uM2(+): data logging - cheap fast & easy


Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11980
Posted: 03:20am 27 Mar 2016      

  Quote  with this addition, a flash chip could be used to hold data that an mmbasic program could itself make use of.


Rob you already have everything needed to do something like this in the current code:

the function "writepage" writes a block of data to a specific page on the chip

writepage(page_number, data, chip_select_pin)

because of the way variable passing to CFunctions works "data" can be anything that adds up to 256 bytes

dim string mystring$ length 255 '1 byte length + 255 bytes of data
dim float myfloats!(63) ' 64 x 4-bytes
DIM integer myintegers%(31) '32 x 8-bytes

Likewise "readpage" can do the same thing

readpage(page_number, mystring$, chip_select_pin)
readpage(page_number, myfloat!(), chip_select_pin)
readpage(page_number, myintegers%(), chip_select_pin)

I specifically wanted to make the logging commands context free i.e. the Basic program shouldn't have to remember anything in order to use them. However, using the primitives as above you can use the flash chip for anything. If you want to use logging in addition then it is probably best to do direct access to high pages in the flash memory and then logging will continue to work from the beginning of flash. It would then be up to the Basic program to know what was in each page used in this way. Effectively readpage and writepage allow direct access to any 256-byte record. The log data can't be treated in this way as it is effectively a sequential stream so to access the 100th string you have to read the first 99 first.

readpage and writepage would just need wrapping with SPI OPEN and SPI CLOSE commands and if used by themselves the user would need to ensure chip_select_pin was set as an ouput (this is done at the moment in C by the "pagecount" comand)