Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:07 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : UNIO problem - 11AA160

     Page 1 of 2    
Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 05:01pm 01 Nov 2017
Copy link to clipboard 
Print this post

Hi there.

Test code:

  Quote  Test1:
Clear
CPU 30
Dim D$,E$ As String
Dim A As Integer
Input "DATA:";D$
Input "ADDR:";A
S=UNIO(
14,02,A,Len(D$)+1,D$)
Print S
Print "Done. Attempting readback..."
Pause 1000
S=UNIO(
14,01,A,Len(D$)+1,E$)
Print S
Print E$
Print "Done."
End


Result with S declared:




Result with S NOT declared:




Both ways generate an error, so what gives?
MMBASIC 5.04.05, UNIO C-Function 30/07/2017, 063552

Reading works fine, but I can't write anything.

QUESTION: In PDF for the UNIO driver, the syntax is given as 'status=' blah, blah, blah. Is this 'status' variable name mandatory? IE: Does the command HAVE to use 'status=' in the command, or can you use any dummy variable name - which I thought you could?

EDIT: It appears that it IS mandatory. If I change my 'S' to 'status', everything works fine. Perhaps this needs noting in the PDF, if it is in fact the case... Edited by Grogster 2017-11-03
Smoke makes things work. When the smoke gets out, it stops!
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 05:20pm 01 Nov 2017
Copy link to clipboard 
Print this post

Grogs, where can I find a description of the UNIO C-Function?
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 05:25pm 01 Nov 2017
Copy link to clipboard 
Print this post

@ OA47 - Link to driver. PLEASE NOTE that you must use the code from the post by Geoff in PAGE THREE of that thread. The original post had some bugs, so don't play with that one!

No, it does not matter - same error again when I changed the code and re-run:




Edited by Grogster 2017-11-03
Smoke makes things work. When the smoke gets out, it stops!
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 05:33pm 01 Nov 2017
Copy link to clipboard 
Print this post

Looking at the code I am unsure about the last STRING as from Geoff's description:

DATA The variable holding data to be read/written. This can be a variable or an array . In the case of a write it can also be an expression.

OA47Edited by OA47 2017-11-03
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 05:41pm 01 Nov 2017
Copy link to clipboard 
Print this post

See PDF, page 2:





...unless the PDF is wrong?
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 06:51pm 01 Nov 2017
Copy link to clipboard 
Print this post

did you
DIM STATUS AS INTEGER

?

Jim
VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 07:47pm 01 Nov 2017
Copy link to clipboard 
Print this post

Yes. If I DIM status AS INTEGER, then that is when I get the error about 'Incompatible type'.

IE: If you DIM status, I get an 'Incompatible type' error. If I DON'T DIM status, I get an 'status not declared' error, so one error fights the other, and you can't win no matter what you do.
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:42pm 01 Nov 2017
Copy link to clipboard 
Print this post

Can you go back to the code you had working when we first started playing with these chips.
You had success with my code from the link you posted earlier.
That will confirm the hardware.

Jim
VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 09:07pm 01 Nov 2017
Copy link to clipboard 
Print this post

OK, this is getting interesting. Original code works. New code does not, but the only change was my slowing the CPU to 30MHz and clearing the variable table(as I was getting errors from that), which is still 10MHz above what the PDF states is the minimum, so I figured I would be just fine at 30.....


Test1: 'Original code - THIS WORKS.
Dim D$,E$ As String
Dim A As Integer
Input "DATA:";D$
Input "ADDR:";A
status=UNIO(14,02,A,Len(D$)+1,D$)
Print status
Print "Done. Attempting readback..."
Pause 1000
status=UNIO(14,01,A,Len(D$)+1,E$)
Print status
Print E$
Print "Done."
End



Test1: 'New code - THIS DOES NOT WORK
Clear
CPU 30
Dim D$,E$ As String
Dim A As Integer
Input "DATA:";D$
Input "ADDR:";A
status=UNIO(14,02,A,Len(D$)+1,D$)
Print S
Print "Done. Attempting readback..."
Pause 1000
status=UNIO(14,01,A,Len(D$)+1,E$)
Print S
Print E$
Print "Done."
End


I will now tinker a little more....

EDIT: Makes no difference at all. I can change the speed to 48MHz, or leave it at 30MHz, and the test1 routine now works just fine - before it would not - EXACT SAME CODE.

WTF?!

The problem seemed to be cleared by NEW then XMODEM R a new copy of EXACTLY THE CODE THAT WAS NOT WORKING ABOVE. This is REALLY weird, and makes no sense - at all....

EDIT: Nope. As a test, I issued NEW, then XMODEM R the exact same code, now we are back to the same exact error as above. I really don't get this at all.... *scratching head*Edited by Grogster 2017-11-03
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 09:23pm 01 Nov 2017
Copy link to clipboard 
Print this post

OK, here is a bit more information. The test1 routine will run OK at the command prompt from the point of XMODEM, but as soon as you RUN the code, the code falls over at the first UNIO read command, then if you try to run test1 at the command prompt again, it falls over forever from that point on.





If you study the flow of this command-line test, you can see that from the first XMODEM transfer, it works fine. As soon as you RUN the code, it falls over. From that point, it won't even run test1 at the command prompt, whereas before RUN, it DID.

....I'm lost, sorry......
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 03:03am 02 Nov 2017
Copy link to clipboard 
Print this post

This is strange. Firstly, you should be able to use any valid integer variable for "status" (eg s% = UNIO(14,01,A,Len(D$)+1,E$))

Why you are having problems is a mystery. I presume that you do not have OPTION EXPLICIT or OPTION DEFAULT in you program or in code saved to the library?

I will run some tests over the next couple of days and report back.

Geoff
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 12:27pm 02 Nov 2017
Copy link to clipboard 
Print this post

YES I DO HAVE OPTION EXPLICIT at the top of the code.
I always program code with that as the very first step these days to help in debugging.

I did not try the percentage sign though, just a plain 'S' or whatever.

UNIO C-function is just in the main code NOT in the library. This is simply cos there is plenty of room for the C-function in the code listing, but perhaps this one HAS to be saved in the library do you think?

NOTHING in the library - the library is not used at all in this code.
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 02:21pm 02 Nov 2017
Copy link to clipboard 
Print this post

  Grogster said   YES I DO HAVE OPTION EXPLICIT at the top of the code.

Well, that would explain the "not declared" error. Use DIM INTEGER status to declare the variable.

Does this fix the problem?

Geoff
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 04:59pm 02 Nov 2017
Copy link to clipboard 
Print this post

No, it doesn't. If you re-read my earlier posts, the problem I am having is that if I DO DIM status as integer, I get the 'Incompatible type' error.

If I don't DIM status as integer, I get the 'Status not declared' error.

One error fights the other, and you cannot win.
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 07:31pm 02 Nov 2017
Copy link to clipboard 
Print this post

OK, the real problem seems to be the 'Incompatible type' error. I will go back to plan A and setup a test environment to try it out. Stay tuned.
Geoff Graham - http://geoffg.net
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1003
Posted: 02:38am 03 Nov 2017
Copy link to clipboard 
Print this post

Hi Grogs,
your code works for me. I am on pin 26 of an E28 chip.

Have you tried a different pin. Pin 14 is SPI IN on an E28 so I did not try it.

Regards
Gerry
Latest F4 Latest H7 FotS
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 11:33am 03 Nov 2017
Copy link to clipboard 
Print this post

Can't try different pin - PCB is already made, and uses an SSOP 28-pin MM2, so very difficult to change that now. I wonder if that could be a possible cause though?

Yes, the code works fine - until it doesn't. When it is running OK, everything is fine, but then I get those errors, which would seem to center around the 'Incompatible type' error. I only hope Geoff can replicate the error at his end.

Here is a COMPLETE CODE listing as I have it now. I don't see how anything I am doing outside of the UNIO could be causing this, but just in case I had better post the whole code. This will also allow anyone else who wants to, to experiment and see if they get the same errors. This is NOT final yet, but this is what I have and am working on as of now:

  Quote  

Print "CP7A Version 1A, November 2017."
Print "(C) 2017, RICTECH LTD."
Print ""
Option Explicit
Const LEDA=02,LEDK=03,HLP=06,RST=07,PIEZO=10,SMC=14,HC12=15,VT=18,PPD=23,BATT=24

Dim as Integer BFLAG,SMC_FLAG,RST_FLAG,PP_FLAG,DELAY,PIEZO_FLAG
Dim as STRING D$,FNI$,TIMEOUT$,FLAGS$ LENGTH 25
Dim as STRING MODE_BYTE$ LENGTH 1

Setpin LEDA,DOUT
Setpin LEDK,DOUT
Setpin HLP,DIN 'Has external pull-up
Setpin RST,DIN 'Has external pull-up
Setpin PIEZO,DOUT
Setpin HC12,DOUT
Setpin VT,DIN '2272 decoder module Valid Transmission line
Setpin PPD,DIN 'Has external pull-up
Setpin BATT,AIN 'Battery voltage input

Open "COM1:1200" as #1
HC12_OFF
'Put HC12 module to sleep
Print "READING SMC..."
status=UNIO(SMC,
01,10,15+1,FNI$) 'Read 15 bytes from SMC - Unit index reference
status=UNIO(SMC,01,7,3+1,TIMEOUT$) 'Read auto-repeat timeout from SMC - Three bytes
status=UNIO(SMC,01,26,10+1,FLAGS$) 'Read control flags from SMC - ten bytes(not all are used)
CPU 5 'All ahead dead-slow....
If status=0 Then
Print "SMC READ ERROR!"
Pin(LEDK)=0
Do
Pulse PIEZO,150
Pulse LEDA,150
Pause 500
Loop
Endif
Print " INDEX: ["+FNI$+"]"
Print "REPEAT: ["+TIMEOUT$+" seconds]"
Print " FLAGS: ["+FLAGS$+"]"
MODE_BYTE$=
MID$(FLAGS$,1,1) 'Call-point mode byte
Print " MODE: [";
If MODE_BYTE$="1" Then Print "STANDARD]"
If MODE_BYTE$="2" Then Print "ALARM]"
If MODE_BYTE$="3" Then Print "DOOR]"
PIEZO_FLAG=
VAL(MID$(FLAGS$,2,1)) 'Piezo on/off flag
Print " PIEZO: [";
If PIEZO_FLAG=1 Then
Print "On]"
Else
Print "Off]"
Endif
DELAY=
VAL(TIMEOUT$)*1000 'Calculate delay to be used
Print ">>> GO! <<<"
'---------
'MAIN LOOP
'---------
BEGIN:
Do
If Pin(BATT)<=1.922 And BFLAG=0 Then '-------LOW BATTERY ALERT-------
BFLAG=1 'Ensures this message is only sent once
HC12_ON 'Wake up HC12 module
Print #1,FNI$+"B" 'Index + bad battery byte
Print "Battery weak."
Pause 500
HC12_OFF
Endif
If Pin(HLP)=0 or Pin(VT) Then '-------HELP BUTTON OR PENDANT PRESSED------
Pause 100 'Debounce delay
If Pin(HLP) And Pin(VT)=0 Then
Print "Ignore HELP switch bounce." 'Help button or VT inactive now, so ignore
Exit Do 'Clean-exit from main loop
Endif
RST_FLAG=
0
Do
Pulse PIEZO,1000
Pin(LEDK)=0:Pin(LEDA)=1 'RED
Timer=0
HC12_ON
'Wake up HC12 module
Print #1,FNI$+"H" 'Index + help mode byte
Print "HELP CALL."
Pause 3000 'Time for HC12 to transmit...
HC12_OFF
Do
Pin(LEDA)=0
Pulse LEDK,100
If Pin(RST)=0 Then '-------RESET BUTTON PRESSED------
HC12_ON
Print #1,FNI$+"R" 'Index + reset mode byte
Print "RESET pressed."
Pause 3000
HC12_OFF
RST_FLAG=
1
Exit Do
Endif
Pause 250
Loop until Timer>=DELAY
If RST_FLAG Then Exit Do
Loop
Endif
If Pin(PPD)=0 And PP_FLAG=0 Then '--------POWER FAILURE--------
PP_FLAG=1 'Set flag
HC12_ON 'Wake up HC12 module
Print #1,FNI$+"F" 'Index + power failure byte
Print "Power failure."
Pause 3000
HC12_OFF
Endif
If Pin(PPD) And PP_FLAG Then '-------POWER RESTORED---------
PP_FLAG=0 'Clear flag
HC12_ON 'Wake up HC12 module
Print #1,FNI$+"K" 'Index + power OK byte
Print "Power restored."
Pause 3000
HC12_OFF
Endif
Loop
Goto BEGIN 'Should only ever get here from help/VT input debounce...

END

Sub HC12_OFF
Print "HC12: <SLEEP MODULE>"
Pin(HC12)=0 'Enable setting mode on HC12 module
Pause 50
Print #1,"AT+SLEEP" 'Put HC12 module to sleep
Do:Loop until Loc(#1)
Pause 100
D$=
Input$(Loc(#1),#1) 'Suck HC12 response from buffer
Pin(HC12)=1
Print "HC12: ";D$
END Sub

Sub HC12_ON
Print "HC12: <WAKE MODULE>"
Pin(HC12)=0
Pause 25 'Allow HC12 to respond
Pin(HC12)=1
Pause 250 'Allow HC12 to re-initalize
END Sub

'=======================



END
'--------------SMC DIRECT CONTROL ROUTINES (can be removed - not part of running code)
Format:
status=UNIO(
14,03)
Print status
END

Test1:
Clear
CPU 48
Dim D$,E$ as STRING
Dim A as Integer
Input "DATA:";D$
Input "ADDR:";A
status=UNIO(
14,02,A,Len(D$)+1,D$)
Print status
Print "Done. Attempting readback..."
Pause 1000
status=UNIO(
14,01,A,Len(D$)+1,E$)
Print status
Print E$
Print "Done."
END

hexmap:
Clear
CPU 48
Dim D as Integer
For X=1 To 500
status=UNIO(
14,01,X+1,1,D)
Print Hex$(D)+" ";
Next
END

decmap:
Clear
CPU 48
Dim as Integer D,X,S
For X=1 To 500
status=UNIO(
14,01,X+1,1,D)
If D=0 Then
Print "-";
Else
Print Chr$(D);
Endif
Next
END

'--------------------------------------

'status = UNIO(pin, cmd, addr, nbr, data)
CFunction UNIO( Integer, Integer, Integer, Integer ) Integer
00000232
8CE30000 00C31821 ACE30000 40024800 0043102B 1440FFFD 00000000 8C880000
00A84024 00061040 00621821 ACE30000 40024800 0043102B 1040000D 2402FFFF
8C820000 00451024 1048FFF9 00000000 8C820000 00452824 10A80005 2402FFFF
00661821 ACE30000 03E00008 2D020001 03E00008 00000000
27BDFFC8 AFBF0034 AFBE0030 AFB7002C AFB60028 AFB50024 AFB40020 AFB3001C
AFB20018 AFB10014 AFB00010
00809021 00A08821 00C0F021 00E0B021 8FB50048
8FB00050 12A0003E 24020001 26B5FFFF 00069840 24170001 2414FFFF 16A00005
92C70000 00073840 8FA2004C 10000003 00473825 00073840 34E70001 24040008
00872807 30A50001 24A6FFFA 00063080 02463023 8E030000 40024800 0043102B
1440FFFD 00000000 ACD10000 8E030000 02631821 AE030000 24A50005 00052880
02452821 40024800 0043102B 1440FFFD 00000000 ACB10000 8E020000 02621021
2484FFFF 1494FFE6 AE020000 40034800 0062182B 1460FFFD 00000000 AE510018
02402021 02202821 03C03021 02003821 0411FF9D 00000000 16E00003 00000000
18400007 00001021 12A00004 26D60001 26B5FFFF 1000FFC9 0000B821 24020001
8FBF0034 8FBE0030 8FB7002C 8FB60028 8FB50024 8FB40020 8FB3001C 8FB20018
8FB10014 8FB00010 03E00008 27BD0038
27BDFFC8 AFBF0034 AFBE0030 AFB7002C AFB60028 AFB50024 AFB40020 AFB3001C
AFB20018 AFB10014 AFB00010
00809021 00A09821 00C0A821 00E0F021 8FB40048
00008821 00008021 2416FFFF 24170008 02402021 02602821 02A03021 0411FF6E
02803821 1056002D 00118840 26100001 1617FFF7 02228825 3BC30002 0043F00A
03C02821 27DEFFFA 001EF080 025EF023 8E830000 40024800 0043102B 1440FFFD
00000000 AFD30000 24A50005 00052880 02452821 00151840 8E840000 00642021
AE840000
40024800 0044102B 1440FFFD 00000000 ACB30000 8E820000 00621821
AE830000
40024800 0043102B 1440FFFD 00000000 AE530018 02402021 02602821
02A03021 0411FF44 02803821 0002102A 2403FFFF 10000002 0062880A 2411FFFF
02201021 8FBF0034 8FBE0030 8FB7002C 8FB60028 8FB50024 8FB40020 8FB3001C
8FB20018 8FB10014 8FB00010 03E00008 27BD0038
27BDFFB0 AFBF004C AFB50048 AFB40044 AFB30040 AFB2003C AFB10038 AFB00034
0080A021 00A09821 00C09021 8FB00064 8FB10068 24020055 A3A20020 8FA20060
A3A20021
24020003 A3A20022 00071203 A3A20023 A3A70024 00061080 AFA20028
24020005 AFA20010 24020001 AFA20014 27A20028 AFA20018 27A70020 0411FF2F
00000000 10400015 00001821 12000013 24030001 2610FFFF 2415FFFF 27A20028
AFA20010
02802021 02602821 02403021 0010382A 0411FF7D 00000000 10550007
00001821 12000004 A2220000 26310001 1000FFF2 2610FFFF 24030001 00601021
8FBF004C 8FB50048 8FB40044 8FB30040 8FB2003C 8FB10038 8FB00034 03E00008
27BD0050
27BDFFC0 AFBF003C AFB40038 AFB30034 AFB20030 AFB1002C AFB00028 0080A021
00A09821 00C09021 8FB10050 24020055 A3A20020 A3A70021 24020005 A3A20022
8E230000 40024800 0043102B 1440FFFD 00000000 AE930014 00121040 8E230000
00621021 AE220000 24020003 AFA20010 24020001 AFA20014 AFB10018 02802021
02602821 02403021 27A70020 0411FEEA 00000000 10400013 00001821 241001F4
AFB10010
02802021 02602821 02403021 0411FF3D 24070002 04400007 30420001
10400007 2610FFFF 5600FFF6 AFB10010 10000004 00001821 10000002 00001821
24030001 00601021 8FBF003C 8FB40038 8FB30034 8FB20030 8FB1002C 8FB00028
03E00008 27BD0040
27BDFF98 AFBF0064 AFBE0060 AFB7005C AFB60058 AFB50054 AFB40050 AFB3004C
AFB20048 AFB10044 AFB00040
00808021 00A08821 00C0A821 00E09021 8FB3007C
8FB60080 AFA00028 00061080 AFA20034 000618C0 AFA30030 00061040 AFA20038
24170055 8FA30078 307E00FF A3B70020 A3BE0021 2403FF96 A3A30022 8FA20028
8FA30034 00431021 AFA20028 24020003 AFA20010 AFA00014 27A20028 AFA20018
02002021 02202821 02A03021 0411FEA0 27A70020 10400053 8FA30028 8FA20030
00431821 A3B70020 A3BE0021 2402006C A3A20022 00121203 A3A20023 A3B20024
40024800 0043102B 1440FFFD 00000000 AE110014 8FA20038 00621821 AFA30028
24020005 AFA20010 24020001 AFA20014 27A30028 AFA30018 02002021 02202821
02A03021 0411FE82 27A70020 10400037 24140010 3242000F 0282A023 0274102A
0262A00B AFB40010 AFA00014 27A20028 AFA20018 02002021 02202821 02A03021
0411FE73 02C03821 1040002A 8FA30030 8FA20028 00431021 AFA20028 27A20028
AFA20010
02002021 02202821 02A03021 0411FF59 8FA70078 10400020 02749823
1A600020 02549021 02D4B021 8FA20028 40034800 0062182B 1460FFFD 00000000
AE110018
3C039D00 8C630000 8C640000 24030B29 0083001B 006001F4 00002012
00441021 AFA20028 40044800 0082202B 1480FFFD 00000000 AE110014 1000FF9C
A3B70020
10000008 00001021 10000006 00001021 10000004 00001021 10000002
00001021 24020001 8FBF0064 8FBE0060 8FB7005C 8FB60058 8FB50054 8FB40050
8FB3004C 8FB20048 8FB10044 8FB00040 03E00008 27BD0068
27BDFFB0 AFBF004C AFB50048 AFB40044 AFB30040 AFB2003C AFB10038 AFB00034
00809821 00A0A021 00C08021 00E09021 8FB50060 24020055 A3A20020 32B100FF
A3B10021
2402FF96 A3A20022 00061080 AFA20028 24020003 AFA20010 AFA00014
27A20028 AFA20018 27A70020 0411FE1A 00000000 10400022 00001821 24020055
A3A20020 A3B10021 A3B20022
8FA30028 40024800 0043102B 1440FFFD 00000000
AE740014
00101040 00621821 AFA30028 24020003 AFA20010 AFA00014 27A20028
AFA20018
02602021 02802821 02003021 0411FE01 27A70020 10400009 00001821
27A20028 AFA20010 02602021 02802821 02003021 0411FEEA 02A03821 0002182B
00601021 8FBF004C 8FB50048 8FB40044 8FB30040 8FB2003C 8FB10038 8FB00034
03E00008 27BD0050
27BDFFA8 AFBF0054 AFBE0050 AFB7004C AFB60048 AFB50044 AFB40040 AFB3003C
AFB20038 AFB10034 AFB00030
00809821 00A08821 00C0F021 AFA70064 3C109D00
8E020024 8C840000 0040F809 00002821 AFA20024 8E020028 0040F809 8E640000
24030001 00431804 AFA30028 8E220000 2411000A 0051001A 022001F4 00008810
24420009 2C420013 240300A1 240400A0 0082180B AFA30020 8E020000 8C430000
3C020001 344286A0 0062001B 004001F4 00002012 AFA4002C 8E020014 8E640000
0040F809 00002821 8E020010 8E640000 24050009 0040F809 00003021 8E02001C
8E640000 0040F809 2405000E 8E020004 0040F809 2404000A 2412000A 0000A021
24170004 24150002 24160003 8E020014 8E640000 0040F809 24050001 8E020004
0040F809 240402BC 8E020014 8E640000 0040F809 00002821 40944800 24020001
16220010 8FA20020 8FC70000 AFA20010 8FA30064 8C620000 AFA20014 8FA40068
AFA40018
8FA40024 8FA50028 0411FE41 8FA6002C 10400020 24040001 10000033
00002821 16350010 00000000 8FC70000 AFA20010 8FA30064 8C620000 AFA20014
8FA40068 AFA40018 8FA40024 8FA50028 0411FEB3 8FA6002C 1040001A 2652FFFF
1000001D 24040001 1636000B 8FA20020 AFA20010 8FA40024 8FA50028 8FA6002C
0411FF3D 2407006D 1040000E 2652FFFF 10000013 24040001 1637000A 2652FFFF
8FA30020 AFA30010 8FA40024 8FA50028 8FA6002C 0411FF30 24070067 1440000A
24040001 5640FFBA 8E020014 00002021 10000006 00002821 10000004 00002821
10000002 00002821 00002821 00801021 00A01821 8FBF0054 8FBE0050 8FB7004C
8FB60048 8FB50044 8FB40040 8FB3003C 8FB20038 8FB10034 8FB00030 03E00008
27BD0058
END CFunction


Smoke makes things work. When the smoke gets out, it stops!
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1003
Posted: 01:43pm 03 Nov 2017
Copy link to clipboard 
Print this post

Hi Grogs,
Probably not much to do with your issue, but I notice these three reads appear to trample on each other.
Starting at 7 and reading 3+1 takes it up to 10 (7,8,9,10),so next starting point would be 11 (not 10) for the next 16 bytes you read.The 15+1 read also takes you past the current start point for 10+1 read.


  Quote  
Print "READING SMC..."
status=UNIO(SMC,01,10,15+1,FNI$) 'Read 15 bytes from SMC - Unit index reference
status=UNIO(SMC,01,7,3+1,TIMEOUT$) 'Read auto-repeat timeout from SMC - Three bytes
status=UNIO(SMC,01,26,10+1,FLAGS$) 'Read control flags from SMC - ten bytes(not all are used)
CPU 5 'All ahead dead-slow....



Print "READING SMC..."
status=UNIO(SMC,01,11,15+1,FNI$) 'Read 15 bytes from SMC - Unit index reference
status=UNIO(SMC,01,7,3+1,TIMEOUT$) 'Read auto-repeat timeout from SMC - Three bytes
status=UNIO(SMC,01,28,10+1,FLAGS$) 'Read control flags from SMC - ten bytes(not all are used)
CPU 5 'All ahead dead-slow....



Regards
Gerry
Latest F4 Latest H7 FotS
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1003
Posted: 04:10pm 03 Nov 2017
Copy link to clipboard 
Print this post

Hi Grogs,

I think I have found whats happening here, good news is pin 14 is OK.
I think the previous mentioned overlapping of your data in the eeprom made it look like it won't read. Correcting the offsets like below and it seems to work nicely.



Print "Writing SMC..."
status=UNIO(SMC,02,11,15+1,"123456789") 'Read 15 bytes from SMC - Unit index reference
status=UNIO(SMC,02,7,3+1,"999") 'Read auto-repeat timeout from SMC - Three bytes
status=UNIO(SMC,02,28,10+1,"YYYYYNNNNN") 'Read control flags from SMC - ten bytes(not all are used)
Print "READING SMC..."
status=UNIO(SMC,01,11,15+1,FNI$) 'Read 15 bytes from SMC - Unit index reference
status=UNIO(SMC,01,7,3+1,TIMEOUT$) 'Read auto-repeat timeout from SMC - Three bytes
status=UNIO(SMC,01,28,10+1,FLAGS$) 'Read control flags from SMC - ten bytes(not all are used)



The confusion comes when you try to debug with the test1 routine.

  Quote  sub Test1

'Clear
CPU 48
LOCAL STRING E$
LOCAL INTEGER A
Input "DATA:";D$
Input "ADDR:";A
status=UNIO(
14,02,A,Len(D$)+1,D$)
Print status
Print "Done. Attempting readback..."
Pause 1000
status=UNIO(
14,01,A,Len(D$)+1,E$)
Print status
Print E$
Print "Done."
end sub


The joker here is the CLEAR statement. Not sure what is does that is unexpected (maybe loses the reference to the CFunction) but if you don't use it all is well.

I made test1 into a sub and used local varaible. This means you can just type test1 at the command line for debugging.

  Quote   LOCAL STRING E$
LOCAL INTEGER A


Regards
Gerry


Latest F4 Latest H7 FotS
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 04:49pm 03 Nov 2017
Copy link to clipboard 
Print this post

Interesting. I will try that and let you know.

I did not figure that there was any problem piling up multiple calls to UNIO, as the Cfunction would only do one at a time, and so therefore, would not return until it had a result from the first one, BEFORE it tried to do the next one, but perhaps that is wrong interpretation on my part?

I also did not think there would be any problem with jumping around in the memory, as you specify the start address as part of the command, so who cares if you read ahead then jump back and read before?

Not neat I grant you, but I did not think there would be a problem with doing it that way.

I tried putting test1 into a sub with local variables, but was still getting the error, so put it back.

Your example should not change anything. The PDF for the UNIO says that that extra byte is just used by MMBASIC to keep track of the length of the string, but I fully expected that to mean that this was only for MMBASIC's purposes hopping in and out of the Cfunction, and that this extra byte is NOT written in ANY WAY to the UNIO memory itself at all.

IE: Write 10 bytes status=UNIO(14,02,10,10+1,"1234567890") will write TEN bytes and NOT eleven bytes, as you are only writing 10 bytes, and the extra byte is used by MMBASIC(not the UNIO) to keep track of the length of the string.

Do I have that totally wrong? Geoff?Edited by Grogster 2017-11-05
Smoke makes things work. When the smoke gets out, it stops!
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025