Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 22:17 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 2 of 2    
Author Message
disco4now

Guru

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

Hi Grogs,
Looks like I jumped the gun with the CLEAR thing.

Your code works and I can't get the 'Incompatible type'. error at all.

I had to add DIM INTEGER Status to get rid or the other error. I initially put it before the CLEAR statement which is where I went off track.

So your code works for me and on pin 14 as well, so I don't know?

Regards
Gerry
Latest F4 Latest H7 FotS
 
Geoffg

Guru

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

Grogs, I setup a test system and ran the code in your first post and it works fine for me also.

I tried it with CPU speeds from 20 to 48MHz and various data/addresses and it worked every time... no "Incompatible type" error. I also tried it with DIM S AS INTEGER and that worked fine also. This is with the latest version of MMBasic.

There must be something else in your program causing the problem but I cannot see what. The code that I used is below, maybe the solution would be to start with this and then add segments of your main program until it falls over.

By the way, you used Dim D$,E$ As String in your code. This will work but it is rather inconsistent. The As String will only apply to E$ but as D$ has a $ suffix it is a string anyway. A cleaner way of writing it would be Dim String D$,E$ or even Dim String D,E.


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

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
Edited by Geoffg 2017-11-05
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

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

Interesting. OK, I will have a play. I will re-flash the PIC32 with MMBASIC and start clean and see if the problem goes away. Perhaps I corrupted something somehow.

EDIT: I can recall that on more then one occasion, I had to pull the power on the MM2, as calling the UNIO C-function crashed the chip big-time, and you never got the console back ever again unless you forced a reboot of the chip. Could that have resulted in corruption of MMBASIC do you think?

Thanks for confirming that my code works for you.

What about the extra byte used by MMBASIC?
Am I correct in that if you write 10 bytes, you are in fact only writing ten and not eleven bytes as I was wondering?

IE: That extra byte is only used by MMBASIC, and is not written to the memory at all, correct?Edited by Grogster 2017-11-06
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

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

  Grogster said   I had to pull the power on the MM2, as calling the UNIO C-function crashed the chip big-time, and you never got the console back ever again unless you forced a reboot of the chip. Could that have resulted in corruption of MMBASIC do you think?

I have heard reports of the firmware being corrupted but I don't understand how it could occur. To write to flash the program has to provide a special unlock code to the CPU. This is specifically designed to stop any corruption of the flash and I cannot see how the unlock code could be accidentally generated (ie, by a runaway program)..

Regardless, it will not hurt to reflash the firmware.

  Grogster said  What about the extra byte used by MMBASIC?
Am I correct in that if you write 10 bytes, you are in fact only writing ten and not eleven bytes as I was wondering? IE: That extra byte is only used by MMBASIC, and is not written to the memory at all, correct?

No, not right. MMBasic needs all the bytes to be written including the size byte, this is so that when it reads back the string it knows how long it is.

Before we delve into this you need to know how a string is stored by MMBasic. Take this example:
D$ = "abcd"

While the string is four characters long it is actually stored in memory as five bytes. The first byte is the length (ie, 4), the next byte is a, the third byte is b, and so on.

When writing a string to an EEPROM you would normally allow a fixed amount of the EEPROM for each string, this is so that you can easily find a string when reading from the EEPROM. For example, allowing 16 bytes per string, the first string would be at &H0000, the second at &H0010, the third at &H0020, etc. So, the command to write the variable D$ in the third slot would be:
S = UNIO(14, 02, &H0020, 16, D$)

and the code to read the string in the third slot would be:
S = UNIO(14, 01, &H0020, 16, E$)

Note that we do not care how long the string in D$ is, it could be one byte or five. The reason we do not care is because the first byte of the string is the length byte and that will be written to the EEPROM and read back in a read command. The only significance of the length byte is that it occupies one of the 16 bytes that we are writing to the EEPROM so that the maximum length string that you can write is 15 bytes. In fact, the code should look like this:
IF LEN(D$) > 15 THEN ERROR "String too long to write"
S = UNIO(14, 02, &H0020, 16, D$)

Normally the details of how a string is stored by MMBasic is hidden from you the programmer but in this instance you need to consider it because you are writing to physical memory locations.

I hope that this helps.

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

Admin Group

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

Ahhhh, thanks a ton, that really helps my understanding of things, and explains to some extent why I was not getting the results I wanted.

disco4now was indeed correct, in that I was overlapping data in the memory.

One last question: When writing STRINGS to UNIO, do they have to be <=16 bytes or is that just your example? Reading your example above, suggests to me that if I had a string of 25 bytes, I need to split it into 16-byte sub-strings, then write those.

Do I have that right or wrong?

EDIT: No, that was just your example. I have re-read your post a couple of times, and you were using 16-byte examples. You can ignore my question above. ...but I leave it in the post for others to giggle at as I try to understand this correctly.... Edited by Grogster 2017-11-06
Smoke makes things work. When the smoke gets out, it stops!
 
GoodToGo!

Senior Member

Joined: 23/04/2017
Location: Australia
Posts: 188
Posted: 09:03pm 04 Nov 2017
Copy link to clipboard 
Print this post

Giggle!

Actually the string info Geoff wrote about is quite interesting, I never knew it stored it like that either....

GTG!
...... Don't worry mate, it'll be GoodToGo!
 
Grogster

Admin Group

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

Giggle to you too!

@ Geoff: Assume our example string of D$="ABCD". With a write command of S=UNIO(14,02,100,4+1,D$), this means that the write will start at memory address 100, and that address 100 will hold the LENGTH of the string(4), and addresses 101,102,103 and 104 will hold "A", "B", "C" and "D" respectively - correct?
Smoke makes things work. When the smoke gets out, it stops!
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 02:22am 05 Nov 2017
Copy link to clipboard 
Print this post

Grahame,

I would be worried about the underlying C function needing a binary or hexadecimal address in the third position. Your 100 looks like it might be decimal.

Geoff will clarify I'm sure.

Paul in NY
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 05:29am 05 Nov 2017
Copy link to clipboard 
Print this post

Grogster - yes, you have it. You could even check by such as writing 5 to address 99 then read back 5+1 from 99 and the first byte of the string would be the previous length byte (i.e. 4) with the next being A,B,C,D.

Paul_L - hex or decimal, doesn't matter which. (100 = &h64)

John
 
Grogster

Admin Group

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

Cool, thanks for that. Yes, I was most DEFINITELY overlapping my data, as I thought that the 'Tracking-byte' was only used by MMBASIC and NOT the memory, so that would explain some things.

That would also possibly explain why the MM2 would crash sometimes when I went to read some data - the length byte for the string it was about to read was probably overwritten, and so the string length was totally wrong - that might not have bothered the memory chip though, it would just fill up the string with &h00 bytes I guess.(UNIO format to &h00)

I am working on changing my code now, to make allowances for this length byte at the start, and also combining the reads into ONE read command - one large string which I will then pick apart using MID$ etc.
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

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

Yes Grogs, you have it correct.
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

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

OK, I re-flashed the 170 chip to be sure, and changed the code and got ONE successful read.

Thinking I was on a winner, I then changed 'status' to 'S' and added 'S' to the the list of declared integers, and re-ran the code - it crashed when it ran into the very first UNIO access request:





At this point, you NEVER get the console back - I waited about 10 minutes to be sure this time. You HAVE to cycle power to get the console back.

OK, that done and console back, re-run the exact same code, and you get the expected result. Run the code a 2nd time, and the MM2 crashes - you have to cycle power.

So, the first read is OK, but the 2nd one causes a crash. I can repeat this exactly every time. Any idea why that should be?





EDIT: I have changed the code so that all it does, is setup the variables etc, read the memory, and STOP. Still crashes at the same point on the 2nd attempt to read.

My current test code:(not including UNIO C-Function, but it is there naturally)

  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,S
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..."
'Example index reference: [111 SOUTHWIN_> with mode-byte added to the end.(13 bytes, 14 with mode-byte)
S=UNIO(SMC,01,10,4,TIMEOUT$) 'Read auto-repeat timeout from SMC - Three bytes
S=UNIO(SMC,01,15,14,FNI$) 'Read File Name Index from SMC - 13 bytes
S=UNIO(SMC,01,35,21,FLAGS$) 'Read control flags from SMC - twenty 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! <<<"
END


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

Guru

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

Hi Grogs,
On the second go are you still at CPU 5. I think you need to set it at the start, its defaulted on first run, but will still be CPU 5 on second go.

Gerry
Latest F4 Latest H7 FotS
 
TassyJim

Guru

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

You have "If status=0 Then " but are using 'S' so status will ALWAYS equal zero and should throw a wobbly because it isn't declared.

You refer to the HC12_OFF sub but it isn't in the supplied code.

Jim

VK7JH
MMedit
 
Grogster

Admin Group

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

@ disco4now - Bloody Hell!!! Well spotted! That was it exactly. My brain is having a hard time with these UNIO things, but I WILL get it right - eventually!

@ Jim - Here you go:

  Quote  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


Smoke makes things work. When the smoke gets out, it stops!
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025