![]() |
Forum Index : Microcontroller and PC projects : UNIO problem - 11AA160
![]() ![]() |
|||||
Author | Message | ||||
disco4now![]() Guru ![]() Joined: 18/12/2014 Location: AustraliaPosts: 1003 |
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: AustraliaPosts: 3292 |
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 Geoff Graham - http://geoffg.net |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
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? Smoke makes things work. When the smoke gets out, it stops! |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3292 |
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. 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 ZealandPosts: 9610 |
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.... ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
GoodToGo!![]() Senior Member ![]() Joined: 23/04/2017 Location: AustraliaPosts: 188 |
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 ZealandPosts: 9610 |
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 StatesPosts: 769 |
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 KingdomPosts: 4044 |
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 ZealandPosts: 9610 |
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: AustraliaPosts: 3292 |
Yes Grogs, you have it correct. Geoff Graham - http://geoffg.net |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
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) Smoke makes things work. When the smoke gets out, it stops! |
||||
disco4now![]() Guru ![]() Joined: 18/12/2014 Location: AustraliaPosts: 1003 |
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: AustraliaPosts: 6283 |
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 ZealandPosts: 9610 |
@ disco4now - Bloody Hell!!! Well spotted! That was it exactly. ![]() ![]() ![]() @ Jim - Here you go: Smoke makes things work. When the smoke gets out, it stops! |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |