![]() |
Forum Index : Microcontroller and PC projects : uM2(+): data logging - cheap fast & easy
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9483 |
Calling getpagecount before attempting a write routine causes a processor exception: ![]() I can't close the SPI2 port, as it is not open, but I can't open it cos it is already open....... ![]() I will ask Geoff about that last one, cos that should not be I don't think. EDIT: Just so you can see what I mean by 'goto start'..... ![]() UPDATE: I am getting reading and writing now SO LONG as I don't try to write to the same page more then once. If I do, the data is corrupted. If I make sure I use a new page each time, it reads back fine. ![]() EDIT: Yes, I have confirmed this. If you write to the same page that has been written to before, the data is corrupted. If I issue D$=SPACE$(255) at the command prompt, and then writepage (51,D$,21), that completes fine, and you can read it back with readpage, but if I then try to write some data to page 51 again, it remains as blank spaces - you cannot overwrite a page that has previously been written in other words. I don't think these logging routines are for me. Matherp obviously wrote them for logging purposes, and I get the distinct feeling I am trying to mutate the Cfunctions etc into something they were never written to be in the first place. I am now reading the device manual. Perhaps I can write some basic code of my own to manage the pages the way I need to be able to. I'll have a go, anyway. ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10067 |
I don't understand why you are making things so difficult - put getpagecount or spi open in the program any of the commented versions below work perfectly testdata() 'sets up the testdata generator
' 'formatlog(chipselectpin) 'format the chip 'spi2 open 10000000,3,8 i=getpagecount(d$,chipselectpin%) ' timer=0 for i=1 to 1000 'log 1,000 strings s$=int2Text(i) s$=s$+space$(255-len(s$)) writepage(i,s$,chipselectpin%) next i print "1,000 records constructed and logged in ",timer\1000," seconds" pause 3000 for i=1 to 1000 'log 1,000 strings readpage(i,s$,chipselectpin%) print s$ next i ' end |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9483 |
I am NOT being difficult - I kinda resent that. I think the issue is that your code was designed for logging purposes, and I need it for random-access purposes. From what I can see, the code you wrote is designed specifically for logging, whereas I need to be able to write to a page, read it, and then write TO THE SAME PAGE AGAIN several times, as I want to use the pages of the memory to story a text-based database. spi open does not work, as the memory is on SPI2, and I can't open the port - I get the error that it is already open etc - see above. I have put getpagecount in there, and that is working OK now, but not for writing to the same page more then once. Smoke makes things work. When the smoke gets out, it stops! |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10067 |
I mean't you are mixing command line and program. Just put everything in the program and it works. When you run a program Geoff's firmware does various things as initialisation that can affect I/O. With everything in the program you can be certain of the status of the I/O. The program doesn't know or care whether you are doing random access or not. If you look at my code you will see that the logging commands are reading and writing from multiple pages of the flash to maintain the index and update pages |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9483 |
Oh, I see. I've done that before heaps of times(calling from command prompt), and it normally is OK to do that. That was normal basic code though, not anything involving Cfunction or Csub routines. Is that a no-no? I will make some more changes...... Smoke makes things work. When the smoke gets out, it stops! |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9483 |
OK, my test code all off the command line, but I still cannot write to the same page more then once. I can read and write though, so that's progress! My code: Option explicit Option default none Dim integer i,x,P Const chipselectpin%=21 'chip select pin Dim s$,B$,D$ ' ' Example program to demonstrate logging to a serial flash chip mounted on a SSD1963 ' Compatible with 64 and 100 pin MM+ processors ' 'testdata() 'sets up the testdata generator ' 'formatlog(chipselectpin) 'format the chip ' START: Input "String: ";D$ If D$="" Then Input "Page to read: ";P x=getpagecount(B$,21) 'Wake up SPI readpage (P,D$,21) Print D$ GoTo START EndIf Do D$=D$+Chr$(42) If Len(D$)=255 Then Exit Do Loop Print D$; Print Str$(Len(D$)) Input "Page: ";P x=getpagecount(B$,21) 'Wake up SPI writepage (P,D$,21) Print "Done." Pause 500 Print "Now attempting to read page " + Str$(P) 'x=getpagecount(B$,21) 'Wake up SPI readpage (P,B$,21) Print B$ Print:Print GoTo START End My results - note how I can write and read page 60 in this example fine the first time around, but if I try to write to page 60 again, it is corrupted: ![]() So, it is working, but I can't make it write anything different to the same page more then once. I can select any page number I like, and the FIRST write to that page reads back fine(as many times as I want), INCLUDING previous tests to other pages, but if I try to write something else to the same page, the readback is corrupted as in the image above. I suspect the writing routine, cos the readback is always the same, even though it is corrupted. I have no idea why that should be. I can readback any page at will by just pressing ENTER when asked for a string, and that also returns corrupted data IF I have tried to write to that page more then once. It makes no difference if "'x=getpagecount(B$,21) 'Wake up SPI" right below "Now attempting to read page" is commented out or not. This keeps all my testing inside a running code, no nothing on the command line anymore. EDIT: Here is another example with page 65 this time: ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10067 |
This is how SPI flash works. It is erased to all &HFF and then writes can change bits to 0. You can only get them back to a 1 by erasing the page. Pages can only be erased in blocks of 4K To re-write an individual page you would have to read in the requisite 4k block, erase the block and then re-write the block with the new page updated. I hadn't understood this is what you were wanting to do. Give me an hour or two and I'll write a block erase CFunction |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9483 |
Oh - that IS different to I2C which is what I thought it essentially was, but just with an SPI interface instead of I2C.... I'm not sure WHY I thought that, but for some reason I thought you could just overwrite a page with new data no problems. If it's going to be a pain for you to have to write more code - I don't want to be a pain....... ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10067 |
Grogster In this demo I've added a new function rewritepage. This takes the same parameters as write page: the page to write, the data to be written, and the CS pin number. It works by reading the sector (16 pages) containing the page in question into buffer memory (4096 bytes) and then erasing the sector. It then re-writes the sector with the original contents except for the page requested which is replaced with the new data. Of course this takes quite a lot of I/O so it does take some time (approx 60msec on a Winbond 25Q32) This took very little time to write but ages to debug because.... WARNING If you are using a flash chip on a TFT display you must ensure the CS pins of the touch controller and the SD card (if inserted) are held high. This is done automatically if touch and SD are configured (OPTION TOUCH etc.). Otherwise it appears electrical noise can cause the touch controller to just very occasionally result in miss-reads from the flash. NB I've added a simple Basic subroutine to initialise the I/O and optionally erase the chip. This should work whether or not the Touch and SD card are in use as long as their CS lines are held high option explicit
option default none dim integer i const chipselectpin%=21 'chip select pin dim s$ ,d$ ,t$ ' ' Example program to demonstrate page mode access to a serial flash chip mounted on a SSD1963 ' Compatible with 64 and 100 pin MM+ processors ' testdata() 'sets up the testdata generator ' initchip(1,chipselectpin%) 'iniitialise the chip with full erase s$=space$(255) ' for i=1 to 100 writepage(i,s$,chipselectpin%) 'write out a page of spaces d$="spoil" 'make sure we can't cheat readpage(i,d$,chipselectpin%) 'read in the page if d$<>s$ then 'prove the page is all spaces print "error in read 1" end endif t$=int2Text(i) t$=t$+space$(255-len(t$)) timer = 0 rewritepage(i,t$,chipselectpin%) 'rewrite the page if i=10 then print timer readpage(i,d$,chipselectpin%) 'read in the updated page if d$<>t$ then 'prove the page is as written print "error in read 2" end endif next i for i=1 to 100 readpage(i,d$,chipselectpin%) 'read in the updated page print d$ next i end ' '**************************************** ' ' sub initchip(eraseit as integer, cspin as integer) local integer i=getpagecount(d$,cspin)*256 if eraseit then if not (erasechip(i,chipselectpin%)) then print "erase failed" end endif print "Erase complete" endif end sub ' CFunction getpagecount 00000000 27BDFFC8 AFB30028 AFBF0034 AFB50030 AFB4002C AFB20024 AFB10020 AFB0001C 8CB10000 3C029D00 8C420088 00111880 00621021 8C420000 24030008 10430007 00809821 3C029D00 8C420010 02202021 24050008 0040F809 00003021 3C02BF81 8C44F220 3C029D00 8C430088 3C020580 7C84D800 3442B053 00821026 24050014 24040030 00A2200B 00831021 8C430000 24020065 1062006F 3C02BF81 8C45F220 3C030580 3C029D00 8C420010 3463B053 7CA5D800 00A32826 24040005 2403000C 0065200A 00003021 0040F809 24050008 3C02BF81 8C45F220 3C030580 3C029D00 8C420010 3463B053 7CA5D800 00A32826 24040005 2403000C 0065200A 00003021 0040F809 24050064 3C02BF81 8C45F220 3C030580 3C029D00 8C420010 3463B053 7CA5D800 00A32826 2404002F 2403000B 0065200A 00003021 0040F809 24050002 3C02BF81 8C45F220 3C030580 3C029D00 8C420010 3463B053 7CA5D800 00A32826 2404002F 2403000B 0065200A 00003021 0040F809 24050064 3C02BF81 8C45F220 3C030580 3C029D00 8C420010 3463B053 7CA5D800 00A32826 24040004 2403000A 0065200A 00003021 0040F809 24050008 3C02BF81 8C45F220 3C030580 3C029D00 8C420010 3463B053 7CA5D800 00A32826 24040004 2403000A 0065200A 00003021 0040F809 24050064 3C02BF81 8C43F220 3C020580 3442B053 7C63D800 1462000C 3C03BF81 8C64FA90 24050001 3C02BF81 7CA41804 AC64FA90 8C43FCA0 24040006 7C831804 AC43FCA0 1000000B 3C029D00 8C64FA90 24050007 3C02BF81 7CA41804 AC64FA90 8C43FC9C 24040006 7C831804 AC43FC9C 3C029D00 8C42001C 02202021 0040F809 24050006 3C02BF80 34038060 24040C00 AC435A00 AC445A40 24040001 AC445A30 3C03BF80 AC405A20 8C625A10 30420080 1040FFFD 3C029D00 8C42001C 3C10BF80 02202021 24050005 8E125A20 0040F809 00000000 2402009F AE025A20 3C03BF80 8C625A10 30420080 1040FFFD 3C02BF80 8C435A20 3C03BF80 AC405A20 8C625A10 30420080 1040FFFD 3C02BF80 8C505A20 3C03BF80 AC405A20 8C625A10 30420080 1040FFFD 3C02BF80 8C555A20 3C03BF80 AC525A20 8C625A10 30420080 1040FFFD 3C129D00 8E42001C 3C03BF80 02202021 24050006 8C745A20 0040F809 00108200 24020010 AFA20010 02158021 8E420030 00108200 02148021 26640001 02003021 0040F809 00103FC3 3C02FF40 3442D9BF 02021021 24030006 2C420002 10400027 A2630000 3C029D00 8C42001C 02202021 0040F809 24050005 24030006 3C02BF80 AC435A20 3C03BF80 8C625A10 30420080 1040FFFD 3C129D00 8E42001C 3C13BF80 02202021 24050006 8E635A20 0040F809 00000000 8E42001C 02202021 0040F809 24050005 24020098 AE625A20 3C03BF80 8C625A10 30420080 1040FFFD 3C029D00 8C42001C 3C03BF80 02202021 24050006 8C635A20 0040F809 00000000 3C0200BF 24422642 24044000 12020012 00002821 3C0200BF 24422602 1202000E 3C0200BF 24422641 1202000B 24042000 3C0200BF 24422601 12020006 2694FFF8 24020001 0282A004 02802021 10000002 00142FC3 00002821 8FBF0034 00801021 00A01821 8FB50030 8FB4002C 8FB30028 8FB20024 8FB10020 8FB0001C 03E00008 27BD0038 End CFunction ' CFunction erasechip 00000000 27BDFFD8 AFB40020 AFB00010 AFBF0024 AFB3001C AFB20018 AFB10014 8CB30000 3C029D00 8C42001C 24030001 3C10BF80 AE035A30 0080A021 24050005 0040F809 02602021 24020006 AE025A20 3C03BF80 8C625A10 30420080 1040FFFD 3C109D00 8E02001C 3C11BF80 02602021 24050006 8E235A20 0040F809 00000000 8E02001C 02602021 0040F809 24050005 240200C7 AE225A20 3C03BF80 8C625A10 30420080 1040FFFD 3C029D00 8C42001C 02602021 24050006 3C03BF80 8C635A20 0040F809 3C119D00 3C10BF80 8E220004 0040F809 3404C350 8E22001C 02602021 0040F809 24050005 24020005 AE025A20 8E025A10 30420080 1040FFFD 00000000 8E025A20 AE125A20 8E025A10 30420080 1040FFFD 00000000 8E125A20 8E22001C 02602021 7C129420 0040F809 24050006 32420001 5440FFE6 8E220004 3C029D00 8C42001C 02602021 0040F809 24050005 24030003 3C02BF80 AC435A20 3C03BF80 8C625A10 30420080 1040FFFD 3C02BF80 8C435A20 3C03BF80 AC405A20 8C625A10 30420080 1040FFFD 3C02BF80 8C435A20 3C03BF80 AC405A20 8C625A10 30420080 1040FFFD 3C02BF80 8C435A20 3C03BF80 AC405A20 8C625A10 30420080 1040FFFD 00000000 8E820004 3C03BF80 8C635A20 5C400006 3C02BF80 14400014 3C029D00 8E820000 10400010 3C02BF80 AC525A20 3C03BF80 8C625A10 30420080 1040FFFD 3C029D00 8C42001C 02602021 24050006 3C03BF80 8C635A20 0040F809 00000000 10000007 00001021 3C029D00 8C42001C 02602021 0040F809 24050006 24020001 8FBF0024 8FB40020 8FB3001C 8FB20018 8FB10014 8FB00010 03E00008 27BD0028 End CFunction ' CSUB writepage 00000000 27BDFFD8 AFB3001C AFB10014 AFB00010 AFBF0024 AFB40020 AFB20018 8CD30000 3C029D00 8C42001C 8C940000 24030001 3C10BF80 AE035A30 00A08821 02602021 0040F809 24050005 24020006 0014A200 AE025A20 3C03BF80 8C625A10 30420080 1040FFFD 3C109D00 8E02001C 3C12BF80 02602021 24050006 8E435A20 0040F809 00000000 8E02001C 02602021 0040F809 24050005 24020002 AE425A20 3C03BF80 8C625A10 30420080 1040FFFD 3C02BF80 7E843C00 8C435A20 3C03BF80 AC445A20 8C625A10 30420080 1040FFFD 3C02BF80 7E943A00 8C435A20 3C03BF80 AC545A20 8C625A10 30420080 1040FFFD 3C02BF80 8C435A20 3C03BF80 AC405A20 8C625A10 30420080 1040FFFD 3C02BF80 8C425A20 00008021 3C03BF80 24040100 02301021 80420000 AC625A20 8C625A10 30420080 1040FFFD 00000000 26100001 8C625A20 1604FFF7 02301021 3C029D00 8C42001C 02602021 0040F809 24050006 3C129D00 3C11BF80 8E420004 0040F809 24040064 8E42001C 02602021 0040F809 24050005 24020005 AE225A20 8E225A10 30420080 1040FFFD 00000000 8E225A20 AE305A20 8E225A10 30420080 1040FFFD 00000000 8E305A20 8E42001C 02602021 0040F809 24050006 32020001 5440FFE7 8E420004 8FBF0024 8FB40020 8FB3001C 8FB20018 8FB10014 8FB00010 03E00008 27BD0028 End CSUB ' CSUB readpage 00000000 27BDFFD8 AFB3001C AFB20018 AFB10014 AFBF0024 AFB40020 AFB00010 8CD20000 3C029D00 8C42001C 8C940000 24030001 3C13BF80 AE635A30 00A08821 02402021 0040F809 24050005 24020003 0014A200 AE625A20 3C03BF80 8C625A10 30420080 1040FFFD 3C02BF80 7E843C00 8C435A20 3C03BF80 AC445A20 8C625A10 30420080 1040FFFD 3C02BF80 7E943A00 8C435A20 3C03BF80 AC545A20 8C625A10 30420080 1040FFFD 3C02BF80 8C435A20 3C03BF80 AC405A20 8C625A10 30420080 1040FFFD 3C02BF80 8C425A20 00002021 3C03BF80 24050100 AC705A20 8C625A10 30420080 1040FFFD 00000000 8C705A20 02241021 24840001 1485FFF7 A0500000 3C029D00 8C42001C 02402021 0040F809 24050006 8FBF0024 8FB40020 8FB3001C 8FB20018 8FB10014 8FB00010 03E00008 27BD0028 End CSUB ' CSUB rewritepage 00000000 27BDFFC0 AFBF003C AFB70034 AFB5002C AFB40028 AFB30024 AFB20020 AFB1001C AFBE0038 3C119D00 AFB60030 AFB00018 8E22003C 00809021 24041000 8CD30000 0040F809 00A0A021 8E430000 0040B821 8E22001C 24040001 3C11BF80 3C1500FF 00031A00 AE245A30 24050005 02602021 36B5F000 30720FFF 0040F809 0075A824 24020003 AE225A20 3C02BF80 8C435A10 30630080 1060FFFD 0015B402 3C02BF80 8C435A20 3C03BF80 AC565A20 8C625A10 30420080 1040FFFD 0015F203 3C02BF80 33DE00FF 8C435A20 3C03BF80 AC5E5A20 8C625A10 30420080 1040FFFD 3C02BF80 32A300FF AFA30010 8FA40010 8C435A20 3C03BF80 AC445A20 8C625A10 30420080 1040FFFD 3C02BF80 8C425A20 02E08821 26E51000 02E02021 3C03BF80 AC705A20 8C625A10 30420080 1040FFFD 00000000 8C705A20 A0900000 24840001 1485FFF7 26420100 0242102A 10400008 26420100 02E21021 02F29021 92830000 A2430000 26520001 1642FFFC 26940001 3C129D00 8E42001C 02602021 0040F809 24050006 8E42001C 02602021 0040F809 24050005 24030006 3C02BF80 AC435A20 8C435A10 30630080 1060FFFD 3C129D00 8E42001C 3C14BF80 02602021 24050006 8E835A20 0040F809 00000000 8E42001C 02602021 0040F809 24050005 24020020 AE825A20 3C02BF80 8C435A10 30630080 1060FFFD 00000000 3C02BF80 8C435A20 3C03BF80 AC565A20 8C625A10 30420080 1040FFFD 3C02BF80 8C435A20 3C03BF80 AC5E5A20 8C625A10 30420080 1040FFFD 8FA40010 3C02BF80 8C435A20 3C03BF80 AC445A20 8C625A10 30420080 1040FFFD 3C029D00 8C42001C 02602021 24050006 3C03BF80 8C635A20 0040F809 3C149D00 3C12BF80 8E820004 0040F809 24040064 8E82001C 02602021 0040F809 24050005 24020005 AE425A20 8E425A10 30420080 1040FFFD 00000000 8E425A20 AE505A20 8E425A10 30420080 1040FFFD 00000000 8E505A20 8E82001C 02602021 0040F809 24050006 32020001 5440FFE7 8E820004 26BE1000 02BE102A 1040005E 02A0B021 3C129D00 3C10BF80 24150006 8E42001C 02602021 0040F809 24050005 AE155A20 8E025A10 30420080 1040FFFD 02602021 8E42001C 02A02821 8E035A20 0040F809 00000000 8E42001C 02602021 0040F809 24050005 24020002 AE025A20 8E025A10 30420080 1040FFFD 7EC23C00 8E035A20 AE025A20 8E025A10 30420080 1040FFFD 7EC23A00 8E035A20 AE025A20 8E025A10 30420080 1040FFFD 32C200FF 8E035A20 AE025A20 8E025A10 30420080 1040FFFD 00000000 8E025A20 26230100 92220000 AE025A20 8E025A10 30420080 1040FFFD 00000000 26310001 8E025A20 5623FFF8 92220000 8E42001C 02602021 0040F809 02A02821 24140100 8E420004 0040F809 24040064 8E42001C 02602021 0040F809 24050005 24020005 AE025A20 8E025A10 30420080 1040FFFD 00000000 8E025A20 AE145A20 8E025A10 30420080 1040FFFD 00000000 8E145A20 8E42001C 02602021 0040F809 02A02821 32820001 5440FFE7 8E420004 26D60100 02DE102A 5440FFA8 8E42001C 3C029D00 8C420044 0040F809 02E02021 8FBF003C 8FBE0038 8FB70034 8FB60030 8FB5002C 8FB40028 8FB30024 8FB20020 8FB1001C 8FB00018 03E00008 27BD0040 End CSUB ' ' '**************************** ' test data generation ' 'small sub testdata DATA "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" DATA "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" 'tens DATA "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" 'big DATA "thousand", "million", "billion" dim small(19) AS STRING length 10, tens(7) AS STRING length 10, big(2) AS STRING length 10 FOR i = 1 TO 19 READ small(i) NEXT FOR i = 0 TO 7 READ tens(i) NEXT FOR i = 0 TO 2 READ big(i) NEXT ' end sub . FUNCTION int2Text(number AS integer) as string local num AS integer, outP AS STRING length 60, unit AS INTEGER local tmpLng1 AS integer IF 0 = number THEN int2Text = "zero" EXIT FUNCTION END IF num = ABS(number) DO tmpLng1 = num MOD 100 SELECT CASE tmpLng1 CASE 1 TO 19 outP = small(tmpLng1) + " " + outP CASE 20 TO 99 SELECT CASE tmpLng1 MOD 10 CASE 0 outP = tens((tmpLng1 \ 10) - 2) + " " + outP CASE ELSE outP = tens((tmpLng1 \ 10) - 2) + "-" + small(tmpLng1 MOD 10) + " " + outP END SELECT END SELECT tmpLng1 = (num MOD 1000) \ 100 IF tmpLng1 THEN outP = small(tmpLng1) + " hundred " + outP END IF num = num \ 1000 IF num < 1 THEN EXIT DO tmpLng1 = num MOD 1000 IF tmpLng1 THEN outP = big(unit) + " " + outP unit = unit + 1 LOOP IF number < 0 THEN outP = "negative " + outP Do WHILE ASC(RIGHT$(outp,1))<=32 outp = LEFT$(outp,len(outp)-1) loop int2Text = outP END FUNCTION '********************************* |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9483 |
Thanks a ton. ![]() I will try this out ASAP. Smoke makes things work. When the smoke gets out, it stops! |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9483 |
Oh, matherp, you are a champ - this is working perfectly. ![]() I don't care about the 60mS sector rewrite time - anything less then 500mS is fine with me, as I am only storing text in each page, so speed is not any real concern(for me), only that I can easily store and readback pages any time I want. ![]() ...and my test code:(I ran your example code first, before I started tinkering) ![]() ...and my memory-module board: ![]() ![]() Now I can get to work on writing the rest of the code to use this module and your Cfunction/CSub code to talk to the memory easily. Smoke makes things work. When the smoke gets out, it stops! |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10067 |
Glad it is working for you ![]() If anyone wants a version for the MX170 (SPI or SPI2) let me know. For those interested here is the C-source of the new function void rewritepage(long long *address, unsigned char d[], long long *cspin){
int m,k,add,pin=*cspin,sec; unsigned char *p; p=GetMemory(4096); sec=*address<<8; //convert page number to byte number add=sec & 0xFFF; //convert page number to byte position within sector sec=sec & 0xFFF000; //convert to 4KB sector address SPIBRG=1; PinSetBit(pin,LATCLR); SPIsend(readdata); SPIsend((sec>>16) & 0xFF); SPIsend((sec>>8) & 0xFF); SPIsend(sec & 0xFF); for(k=0;k<4096;k++){ //read in the sector into local memory SPIread(m); p[k]=m; } for(k=add;k<add+256;k++)p[k]=d[k-add];//set the relevant page to the new data PinSetBit(pin,LATSET); // now erase the sector PinSetBit(pin,LATCLR); SPIsend(writeenable); PinSetBit(pin,LATSET); PinSetBit(pin,LATCLR); SPIsend(sectorerase); SPIsend((sec>>16) & 0xFF); SPIsend((sec>>8) & 0xFF); SPIsend(sec & 0xFF); PinSetBit(pin,LATSET); do { //wait for the erase to complete uSec(100); PinSetBit(pin,LATCLR); SPIsend(readstatus1) SPIread(m); PinSetBit(pin,LATSET); } while(m & 1); k=0; for(add=sec;add<sec+4096;add+=256){ //write out the sector a page at a time PinSetBit(pin,LATCLR); SPIsend(writeenable); PinSetBit(pin,LATSET); PinSetBit(pin,LATCLR); SPIsend(pageprogram); SPIsend((add>>16) & 0xFF); SPIsend((add>>8) & 0xFF); SPIsend(add & 0xFF); for(m=0;m<256;m++) { SPIsend(p[k]); k++; } PinSetBit(pin,LATSET); do { uSec(100); PinSetBit(pin,LATCLR); SPIsend(readstatus1) SPIread(m); PinSetBit(pin,LATSET); } while(m & 1); } FreeMemory(p); } |
||||
centrex![]() Guru ![]() Joined: 13/11/2011 Location: AustraliaPosts: 320 |
Yes please Peter for the 170. Grogster do you have these little boards for sale? Regards Cliff |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10067 |
SPI1 version untested but should work. SPI2 version fully tested CSub rewritepage 'SPI1 version
00000000 27BDFFC0 AFBF003C AFB70034 AFB5002C AFB40028 AFB30024 AFB20020 AFB1001C AFBE0038 3C119D00 AFB60030 AFB00018 8E22003C 00809021 24041000 8CD30000 0040F809 00A0A021 8E430000 0040B821 8E22001C 24040001 3C11BF80 3C1500FF 00031A00 AE245830 24050005 02602021 36B5F000 30720FFF 0040F809 0075A824 24020003 AE225820 3C02BF80 8C435810 30630080 1060FFFD 0015B402 3C02BF80 8C435820 3C03BF80 AC565820 8C625810 30420080 1040FFFD 0015F203 3C02BF80 33DE00FF 8C435820 3C03BF80 AC5E5820 8C625810 30420080 1040FFFD 3C02BF80 32A300FF AFA30010 8FA40010 8C435820 3C03BF80 AC445820 8C625810 30420080 1040FFFD 3C02BF80 8C425820 02E08821 26E51000 02E02021 3C03BF80 AC705820 8C625810 30420080 1040FFFD 00000000 8C705820 A0900000 24840001 1485FFF7 26420100 0242102A 10400008 26420100 02E21021 02F29021 92830000 A2430000 26520001 1642FFFC 26940001 3C129D00 8E42001C 02602021 0040F809 24050006 8E42001C 02602021 0040F809 24050005 24030006 3C02BF80 AC435820 8C435810 30630080 1060FFFD 3C129D00 8E42001C 3C14BF80 02602021 24050006 8E835820 0040F809 00000000 8E42001C 02602021 0040F809 24050005 24020020 AE825820 3C02BF80 8C435810 30630080 1060FFFD 00000000 3C02BF80 8C435820 3C03BF80 AC565820 8C625810 30420080 1040FFFD 3C02BF80 8C435820 3C03BF80 AC5E5820 8C625810 30420080 1040FFFD 8FA40010 3C02BF80 8C435820 3C03BF80 AC445820 8C625810 30420080 1040FFFD 3C029D00 8C42001C 02602021 24050006 3C03BF80 8C635820 0040F809 3C149D00 3C12BF80 8E820004 0040F809 24040064 8E82001C 02602021 0040F809 24050005 24020005 AE425820 8E425810 30420080 1040FFFD 00000000 8E425820 AE505820 8E425810 30420080 1040FFFD 00000000 8E505820 8E82001C 02602021 0040F809 24050006 32020001 5440FFE7 8E820004 26BE1000 02BE102A 1040005E 02A0B021 3C129D00 3C10BF80 24150006 8E42001C 02602021 0040F809 24050005 AE155820 8E025810 30420080 1040FFFD 02602021 8E42001C 02A02821 8E035820 0040F809 00000000 8E42001C 02602021 0040F809 24050005 24020002 AE025820 8E025810 30420080 1040FFFD 7EC23C00 8E035820 AE025820 8E025810 30420080 1040FFFD 7EC23A00 8E035820 AE025820 8E025810 30420080 1040FFFD 32C200FF 8E035820 AE025820 8E025810 30420080 1040FFFD 00000000 8E025820 26230100 92220000 AE025820 8E025810 30420080 1040FFFD 00000000 26310001 8E025820 5623FFF8 92220000 8E42001C 02602021 0040F809 02A02821 24140100 8E420004 0040F809 24040064 8E42001C 02602021 0040F809 24050005 24020005 AE025820 8E025810 30420080 1040FFFD 00000000 8E025820 AE145820 8E025810 30420080 1040FFFD 00000000 8E145820 8E42001C 02602021 0040F809 02A02821 32820001 5440FFE7 8E420004 26D60100 02DE102A 5440FFA8 8E42001C 3C029D00 8C420044 0040F809 02E02021 8FBF003C 8FBE0038 8FB70034 8FB60030 8FB5002C 8FB40028 8FB30024 8FB20020 8FB1001C 8FB00018 03E00008 27BD0040 End CSub CSub rewritepage 'SPI2 version
00000000 27BDFFC0 AFBF003C AFB70034 AFB5002C AFB40028 AFB30024 AFB20020 AFB1001C AFBE0038 3C119D00 AFB60030 AFB00018 8E22003C 00809021 24041000 8CD30000 0040F809 00A0A021 8E430000 0040B821 8E22001C 24040001 3C11BF80 3C1500FF 00031A00 AE245A30 24050005 02602021 36B5F000 30720FFF 0040F809 0075A824 24020003 AE225A20 3C02BF80 8C435A10 30630080 1060FFFD 0015B402 3C02BF80 8C435A20 3C03BF80 AC565A20 8C625A10 30420080 1040FFFD 0015F203 3C02BF80 33DE00FF 8C435A20 3C03BF80 AC5E5A20 8C625A10 30420080 1040FFFD 3C02BF80 32A300FF AFA30010 8FA40010 8C435A20 3C03BF80 AC445A20 8C625A10 30420080 1040FFFD 3C02BF80 8C425A20 02E08821 26E51000 02E02021 3C03BF80 AC705A20 8C625A10 30420080 1040FFFD 00000000 8C705A20 A0900000 24840001 1485FFF7 26420100 0242102A 10400008 26420100 02E21021 02F29021 92830000 A2430000 26520001 1642FFFC 26940001 3C129D00 8E42001C 02602021 0040F809 24050006 8E42001C 02602021 0040F809 24050005 24030006 3C02BF80 AC435A20 8C435A10 30630080 1060FFFD 3C129D00 8E42001C 3C14BF80 02602021 24050006 8E835A20 0040F809 00000000 8E42001C 02602021 0040F809 24050005 24020020 AE825A20 3C02BF80 8C435A10 30630080 1060FFFD 00000000 3C02BF80 8C435A20 3C03BF80 AC565A20 8C625A10 30420080 1040FFFD 3C02BF80 8C435A20 3C03BF80 AC5E5A20 8C625A10 30420080 1040FFFD 8FA40010 3C02BF80 8C435A20 3C03BF80 AC445A20 8C625A10 30420080 1040FFFD 3C029D00 8C42001C 02602021 24050006 3C03BF80 8C635A20 0040F809 3C149D00 3C12BF80 8E820004 0040F809 24040064 8E82001C 02602021 0040F809 24050005 24020005 AE425A20 8E425A10 30420080 1040FFFD 00000000 8E425A20 AE505A20 8E425A10 30420080 1040FFFD 00000000 8E505A20 8E82001C 02602021 0040F809 24050006 32020001 5440FFE7 8E820004 26BE1000 02BE102A 1040005E 02A0B021 3C129D00 3C10BF80 24150006 8E42001C 02602021 0040F809 24050005 AE155A20 8E025A10 30420080 1040FFFD 02602021 8E42001C 02A02821 8E035A20 0040F809 00000000 8E42001C 02602021 0040F809 24050005 24020002 AE025A20 8E025A10 30420080 1040FFFD 7EC23C00 8E035A20 AE025A20 8E025A10 30420080 1040FFFD 7EC23A00 8E035A20 AE025A20 8E025A10 30420080 1040FFFD 32C200FF 8E035A20 AE025A20 8E025A10 30420080 1040FFFD 00000000 8E025A20 26230100 92220000 AE025A20 8E025A10 30420080 1040FFFD 00000000 26310001 8E025A20 5623FFF8 92220000 8E42001C 02602021 0040F809 02A02821 24140100 8E420004 0040F809 24040064 8E42001C 02602021 0040F809 24050005 24020005 AE025A20 8E025A10 30420080 1040FFFD 00000000 8E025A20 AE145A20 8E025A10 30420080 1040FFFD 00000000 8E145A20 8E42001C 02602021 0040F809 02A02821 32820001 5440FFE7 8E420004 26D60100 02DE102A 5440FFA8 8E42001C 3C029D00 8C420044 0040F809 02E02021 8FBF003C 8FBE0038 8FB70034 8FB60030 8FB5002C 8FB40028 8FB30024 8FB20020 8FB1001C 8FB00018 03E00008 27BD0040 End CSub |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9483 |
They are not on the website, but I can sell you some if you want any. Flick me a PM if you want some. If anyone else reading this thinks they should be on my website, let me know and I can add them. US$5 for two including airmail to anywhere on the planet. They are designed to fit a standard 12-pin edge-connector socket such as these ones. Smoke makes things work. When the smoke gets out, it stops! |
||||
centrex![]() Guru ![]() Joined: 13/11/2011 Location: AustraliaPosts: 320 |
@ Grogster the little memory board works aok thanks. matherp the logging program works like a charm on a 28 pin pic170 a thousand items in 19 seconds. But the SPI1 rewritepage cfunction won't using grogsters test code snippet. Can you have a look at the function and perhaps check it out if you have the time. Thanks. Cliff |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9483 |
What happens when you try to call rewritepage? Does the MM come back with an error or just crash? I am using a MM+ 64-pin QFP chip, not the 170 DIL, so that might make all the difference. Thanks for letting me know the board works for you. ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10067 |
Sounds like you don't have a self-consistent set of Cfunctions for MX170 SPI1 Here is my test program for paged rewrite which tests fine on SPI1 44-pin Migrate this complete set of CFunction into Grogster's program and it should work option explicit
option default none dim integer i const chipselectpin%=19 'chip select pin dim s$ ,d$ ,t$ ' ' Example program to demonstrate page mode access to a serial flash chip mounted on a SSD1963 ' Compatible with 28 and 44 pin MM2 processors SPI1 ' testdata() 'sets up the testdata generator ' initchip(1,chipselectpin%) 'iniitialise the chip with full erase s$=space$(255) ' for i=100 to 200 writepage(i,s$,chipselectpin%) 'write out a page of spaces d$="spoil" 'make sure we can't cheat readpage(i,d$,chipselectpin%) 'read in the page if d$<>s$ then 'prove the page is all spaces print "error in read 1" end endif t$=int2Text(i) t$=t$+space$(255-len(t$)) timer = 0 rewritepage(i,t$,chipselectpin%) 'rewrite the page if i=10 then print timer readpage(i,d$,chipselectpin%) 'read in the updated page if d$<>t$ then 'prove the page is as written print "error in read 2" end endif next i for i=100 to 200 readpage(i,d$,chipselectpin%) 'read in the updated page print d$ next i end ' '**************************************** ' ' sub initchip(eraseit as integer, cspin as integer) local integer i=getpagecount(d$,cspin)*256 if eraseit then if not (erasechip(i,chipselectpin%)) then print "erase failed" end endif print "Erase complete" endif end sub ' CFunction getnextfreepage 00000000 27BDFEC8 AFB7012C AFBF0134 AFBE0130 AFB60128 AFB50124 AFB40120 AFB3011C AFB20118 AFB10114 AFB00110 8C830004 8C820000 8CB60000 000327C3 308407FF 00821021 0044B82B 02E3B821 000212C2 0017BD40 02E2B825 24030001 3C02BF80 AC435830 1AE00048 0000A021 3C159D00 3C10BF80 241E0003 27B20110 24130020 8EA2001C 02C02021 0040F809 24050005 00141A00 AE1E5820 8E025810 30420080 1040FFFD 7C623C00 8E045820 AE025820 8E025810 30420080 1040FFFD 7C623A00 8E045820 AE025820 8E025810 30420080 1040FFFD 00000000 306300FF 8E025820 AE035820 8E025810 30420080 1040FFFD 00000000 8E025820 27A30010 AE115820 8E025810 30420080 1040FFFD 00000000 8E115820 7C118C20 A0710000 24630001 1472FFF6 02C02021 8EA2001C 0040F809 24050006 8FA20010 8FA30014 00431025 14400012 00002021 27A20018 24040001 8C430000 8C450004 00651825 1460000B 24420008 24840001 5493FFFA 8C430000 26940001 0297102A 5440FFC2 8EA2001C 10000002 24040100 00002021 27A30010 000410C0 00621021 8C460000 8C450004 30C30001 14600011 00001021 24020001 00055840 240A0040 00024827 00461806 012B4804 30480020 00453807 01231825 00E8180B 30630001 54600005 0014A140 24420001 144AFFF5 00024827 0014A140 02842021 8FBF0134 00042180 00441021 00021FC3 8FBE0130 8FB7012C 8FB60128 8FB50124 8FB40120 8FB3011C 8FB20118 8FB10114 8FB00110 03E00008 27BD0138 End CFunction ' CFunction getpagecount 00000000 27BDFFC8 AFB30028 AFBF0034 AFB50030 AFB4002C AFB20024 AFB10020 AFB0001C 8CB10000 3C029D00 8C420088 00111880 00621021 8C420000 24030008 10430007 00809821 3C029D00 8C420010 02202021 24050008 0040F809 00003021 3C02BF81 8C44F220 3C030661 3463A053 7C84D800 1083000B 24020050 3C02BF81 8C43F220 3C020660 3442A053 7C63D800 00621026 2404000C 24030050 0082180B 00601021 3C039D00 8C630088 00431021 8C430000 24020065 1062008E 3C02BF81 8C45F220 3C030661 3C029D00 7CA5D800 3463A053 8C420010 10A3000B 24040014 3C03BF81 8C64F220 3C030660 3463A053 7C84D800 00832026 24050003 24030014 00A4180B 00602021 24050008 0040F809 00003021 3C02BF81 8C45F220 3C030661 3C029D00 7CA5D800 3463A053 8C420010 10A3000B 24040014 3C03BF81 8C64F220 3C030660 3463A053 7C84D800 00832026 24050003 24030014 00A4180B 00602021 24050064 0040F809 00003021 3C02BF81 8C45F220 3C030661 3C029D00 7CA5D800 3463A053 8C420010 10A3000B 24040029 3C03BF81 8C64F220 3C030660 3463A053 7C84D800 00832026 2405000E 24030029 00A4180B 00602021 24050002 0040F809 00003021 3C02BF81 8C45F220 3C030661 3C029D00 7CA5D800 3463A053 8C420010 10A3000B 24040029 3C03BF81 8C64F220 3C030660 3463A053 7C84D800 00832026 2405000E 24030029 00A4180B 00602021 24050064 0040F809 00003021 3C02BF81 8C45F220 3C030661 3C029D00 7CA5D800 3463A053 8C420010 10A3000B 2404000E 3C03BF81 8C64F220 3C030660 3463A053 7C84D800 00832026 24050019 2403000E 00A4180B 00602021 24050008 0040F809 00003021 3C02BF81 8C45F220 3C030661 3C029D00 7CA5D800 3463A053 8C420010 10A3000B 2404000E 3C03BF81 8C64F220 3C030660 3463A053 7C84D800 00832026 24050019 2403000E 00A4180B 00602021 24050064 0040F809 00003021 3C03BF81 8C64FA84 24050001 3C02BF81 7CA41804 AC64FA84 8C43FB04 24040003 7C831804 AC43FB04 3C029D00 8C42001C 02202021 0040F809 24050006 3C02BF80 34038060 24040C00 AC435800 AC445840 24040001 AC445830 3C03BF80 AC405820 8C625810 30420080 1040FFFD 3C029D00 8C42001C 3C10BF80 02202021 24050005 8E125820 0040F809 00000000 2402009F AE025820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C435820 3C03BF80 AC405820 8C625810 30420080 1040FFFD 3C02BF80 8C505820 3C03BF80 AC405820 8C625810 30420080 1040FFFD 3C02BF80 8C555820 3C03BF80 AC525820 8C625810 30420080 1040FFFD 3C129D00 8E42001C 3C03BF80 02202021 24050006 8C745820 0040F809 00108200 24020010 AFA20010 02158021 8E420030 00108200 02148021 26640001 02003021 0040F809 00103FC3 3C02FF40 3442D9BF 02021021 24030006 2C420002 10400027 A2630000 3C029D00 8C42001C 02202021 0040F809 24050005 24030006 3C02BF80 AC435820 3C03BF80 8C625810 30420080 1040FFFD 3C129D00 8E42001C 3C13BF80 02202021 24050006 8E635820 0040F809 00000000 8E42001C 02202021 0040F809 24050005 24020098 AE625820 3C03BF80 8C625810 30420080 1040FFFD 3C029D00 8C42001C 3C03BF80 02202021 24050006 8C635820 0040F809 00000000 3C0200BF 24422642 24044000 12020012 00002821 3C0200BF 24422602 1202000E 3C0200BF 24422641 1202000B 24042000 3C0200BF 24422601 12020006 2694FFF8 24020001 0282A004 02802021 10000002 00142FC3 00002821 8FBF0034 00801021 00A01821 8FB50030 8FB4002C 8FB30028 8FB20024 8FB10020 8FB0001C 03E00008 27BD0038 End CFunction ' CFunction erasechip 00000000 27BDFFD8 AFB40020 AFB00010 AFBF0024 AFB3001C AFB20018 AFB10014 8CB30000 3C029D00 8C42001C 24030001 3C10BF80 AE035830 0080A021 24050005 0040F809 02602021 24020006 AE025820 3C03BF80 8C625810 30420080 1040FFFD 3C109D00 8E02001C 3C11BF80 02602021 24050006 8E235820 0040F809 00000000 8E02001C 02602021 0040F809 24050005 240200C7 AE225820 3C03BF80 8C625810 30420080 1040FFFD 3C029D00 8C42001C 02602021 24050006 3C03BF80 8C635820 0040F809 3C119D00 3C10BF80 8E220004 0040F809 3404C350 8E22001C 02602021 0040F809 24050005 24020005 AE025820 8E025810 30420080 1040FFFD 00000000 8E025820 AE125820 8E025810 30420080 1040FFFD 00000000 8E125820 8E22001C 02602021 7C129420 0040F809 24050006 32420001 5440FFE6 8E220004 3C029D00 8C42001C 02602021 0040F809 24050005 24030003 3C02BF80 AC435820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C435820 3C03BF80 AC405820 8C625810 30420080 1040FFFD 3C02BF80 8C435820 3C03BF80 AC405820 8C625810 30420080 1040FFFD 3C02BF80 8C435820 3C03BF80 AC405820 8C625810 30420080 1040FFFD 00000000 8E820004 3C03BF80 8C635820 5C400006 3C02BF80 14400014 3C029D00 8E820000 10400010 3C02BF80 AC525820 3C03BF80 8C625810 30420080 1040FFFD 3C029D00 8C42001C 02602021 24050006 3C03BF80 8C635820 0040F809 00000000 10000007 00001021 3C029D00 8C42001C 02602021 0040F809 24050006 24020001 8FBF0024 8FB40020 8FB3001C 8FB20018 8FB10014 8FB00010 03E00008 27BD0028 End CFunction ' CSub writepage 00000000 27BDFFD8 AFB3001C AFB10014 AFB00010 AFBF0024 AFB40020 AFB20018 8CD30000 3C029D00 8C42001C 8C940000 24030001 3C10BF80 AE035830 00A08821 02602021 0040F809 24050005 24020006 0014A200 AE025820 3C03BF80 8C625810 30420080 1040FFFD 3C109D00 8E02001C 3C12BF80 02602021 24050006 8E435820 0040F809 00000000 8E02001C 02602021 0040F809 24050005 24020002 AE425820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 7E843C00 8C435820 3C03BF80 AC445820 8C625810 30420080 1040FFFD 3C02BF80 7E943A00 8C435820 3C03BF80 AC545820 8C625810 30420080 1040FFFD 3C02BF80 8C435820 3C03BF80 AC405820 8C625810 30420080 1040FFFD 3C02BF80 8C425820 00008021 3C03BF80 24040100 02301021 80420000 AC625820 8C625810 30420080 1040FFFD 00000000 26100001 8C625820 1604FFF7 02301021 3C029D00 8C42001C 02602021 0040F809 24050006 3C129D00 3C11BF80 8E420004 0040F809 24040064 8E42001C 02602021 0040F809 24050005 24020005 AE225820 8E225810 30420080 1040FFFD 00000000 8E225820 AE305820 8E225810 30420080 1040FFFD 00000000 8E305820 8E42001C 02602021 0040F809 24050006 32020001 5440FFE7 8E420004 8FBF0024 8FB40020 8FB3001C 8FB20018 8FB10014 8FB00010 03E00008 27BD0028 End CSub ' CSub readpage 00000000 27BDFFD8 AFB3001C AFB20018 AFB10014 AFBF0024 AFB40020 AFB00010 8CD20000 3C029D00 8C42001C 8C940000 24030001 3C13BF80 AE635830 00A08821 02402021 0040F809 24050005 24020003 0014A200 AE625820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 7E843C00 8C435820 3C03BF80 AC445820 8C625810 30420080 1040FFFD 3C02BF80 7E943A00 8C435820 3C03BF80 AC545820 8C625810 30420080 1040FFFD 3C02BF80 8C435820 3C03BF80 AC405820 8C625810 30420080 1040FFFD 3C02BF80 8C425820 00002021 3C03BF80 24050100 AC705820 8C625810 30420080 1040FFFD 00000000 8C705820 02241021 24840001 1485FFF7 A0500000 3C029D00 8C42001C 02402021 0040F809 24050006 8FBF0024 8FB40020 8FB3001C 8FB20018 8FB10014 8FB00010 03E00008 27BD0028 End CSub ' CSub rewritepage 00000000 27BDFFC0 AFBF003C AFB70034 AFB5002C AFB40028 AFB30024 AFB20020 AFB1001C AFBE0038 3C119D00 AFB60030 AFB00018 8E22003C 00809021 24041000 8CD30000 0040F809 00A0A021 8E430000 0040B821 8E22001C 24040001 3C11BF80 3C1500FF 00031A00 AE245830 24050005 02602021 36B5F000 30720FFF 0040F809 0075A824 24020003 AE225820 3C02BF80 8C435810 30630080 1060FFFD 0015B402 3C02BF80 8C435820 3C03BF80 AC565820 8C625810 30420080 1040FFFD 0015F203 3C02BF80 33DE00FF 8C435820 3C03BF80 AC5E5820 8C625810 30420080 1040FFFD 3C02BF80 32A300FF AFA30010 8FA40010 8C435820 3C03BF80 AC445820 8C625810 30420080 1040FFFD 3C02BF80 8C425820 02E08821 26E51000 02E02021 3C03BF80 AC705820 8C625810 30420080 1040FFFD 00000000 8C705820 A0900000 24840001 1485FFF7 26420100 0242102A 10400008 26420100 02E21021 02F29021 92830000 A2430000 26520001 1642FFFC 26940001 3C129D00 8E42001C 02602021 0040F809 24050006 8E42001C 02602021 0040F809 24050005 24030006 3C02BF80 AC435820 8C435810 30630080 1060FFFD 3C129D00 8E42001C 3C14BF80 02602021 24050006 8E835820 0040F809 00000000 8E42001C 02602021 0040F809 24050005 24020020 AE825820 3C02BF80 8C435810 30630080 1060FFFD 00000000 3C02BF80 8C435820 3C03BF80 AC565820 8C625810 30420080 1040FFFD 3C02BF80 8C435820 3C03BF80 AC5E5820 8C625810 30420080 1040FFFD 8FA40010 3C02BF80 8C435820 3C03BF80 AC445820 8C625810 30420080 1040FFFD 3C029D00 8C42001C 02602021 24050006 3C03BF80 8C635820 0040F809 3C149D00 3C12BF80 8E820004 0040F809 24040064 8E82001C 02602021 0040F809 24050005 24020005 AE425820 8E425810 30420080 1040FFFD 00000000 8E425820 AE505820 8E425810 30420080 1040FFFD 00000000 8E505820 8E82001C 02602021 0040F809 24050006 32020001 5440FFE7 8E820004 26BE1000 02BE102A 1040005E 02A0B021 3C129D00 3C10BF80 24150006 8E42001C 02602021 0040F809 24050005 AE155820 8E025810 30420080 1040FFFD 02602021 8E42001C 02A02821 8E035820 0040F809 00000000 8E42001C 02602021 0040F809 24050005 24020002 AE025820 8E025810 30420080 1040FFFD 7EC23C00 8E035820 AE025820 8E025810 30420080 1040FFFD 7EC23A00 8E035820 AE025820 8E025810 30420080 1040FFFD 32C200FF 8E035820 AE025820 8E025810 30420080 1040FFFD 00000000 8E025820 26230100 92220000 AE025820 8E025810 30420080 1040FFFD 00000000 26310001 8E025820 5623FFF8 92220000 8E42001C 02602021 0040F809 02A02821 24140100 8E420004 0040F809 24040064 8E42001C 02602021 0040F809 24050005 24020005 AE025820 8E025810 30420080 1040FFFD 00000000 8E025820 AE145820 8E025810 30420080 1040FFFD 00000000 8E145820 8E42001C 02602021 0040F809 02A02821 32820001 5440FFE7 8E420004 26D60100 02DE102A 5440FFA8 8E42001C 3C029D00 8C420044 0040F809 02E02021 8FBF003C 8FBE0038 8FB70034 8FB60030 8FB5002C 8FB40028 8FB30024 8FB20020 8FB1001C 8FB00018 03E00008 27BD0040 End CSub ' ' '**************************** ' test data generation ' 'small sub testdata DATA "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" DATA "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" 'tens DATA "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" 'big DATA "thousand", "million", "billion" dim small(19) AS STRING length 10, tens(7) AS STRING length 10, big(2) AS STRING length 10 FOR i = 1 TO 19 READ small(i) NEXT FOR i = 0 TO 7 READ tens(i) NEXT FOR i = 0 TO 2 READ big(i) NEXT ' end sub . FUNCTION int2Text(number AS integer) as string local num AS integer, outP AS STRING length 60, unit AS INTEGER local tmpLng1 AS integer IF 0 = number THEN int2Text = "zero" EXIT FUNCTION END IF num = ABS(number) DO tmpLng1 = num MOD 100 SELECT CASE tmpLng1 CASE 1 TO 19 outP = small(tmpLng1) + " " + outP CASE 20 TO 99 SELECT CASE tmpLng1 MOD 10 CASE 0 outP = tens((tmpLng1 \ 10) - 2) + " " + outP CASE ELSE outP = tens((tmpLng1 \ 10) - 2) + "-" + small(tmpLng1 MOD 10) + " " + outP END SELECT END SELECT tmpLng1 = (num MOD 1000) \ 100 IF tmpLng1 THEN outP = small(tmpLng1) + " hundred " + outP END IF num = num \ 1000 IF num < 1 THEN EXIT DO tmpLng1 = num MOD 1000 IF tmpLng1 THEN outP = big(unit) + " " + outP unit = unit + 1 LOOP IF number < 0 THEN outP = "negative " + outP Do WHILE ASC(RIGHT$(outp,1))<=32 outp = LEFT$(outp,len(outp)-1) loop int2Text = outP END FUNCTION '********************************* |
||||
centrex![]() Guru ![]() Joined: 13/11/2011 Location: AustraliaPosts: 320 |
Thanks Peter I will give it a try. All works ! Does this mean we need the original program for data logging and this new piece if we only want to load or modify specific locations. Thanks again. Cliff |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
This thread take a lot of digesting for an inexperienced & rusty brain. I'm sure it can do basic things I could use. Would someone be able to paste together a very simple example that just saves & then reads back a couple of variables and maybe an array; if that's something that can easily be done. Have read thru it a few times, but it's still being a huge learning curve to interpret it and figure out how to apply it to the example above. Thanks Phil |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |