Spin equivalent of PBASIC Read and Write commands
Genetix
Posts: 1,754
How would I do the equivalent of the PBASIC Read and Write commands which read and write from the EEPROM in Spin?
Comments
Note: My I2C object requires a pull-up on the SCL (clock) line.
The EEPROM object has several methods for writing to and reading back from the EEPROM. One of the neat tricks with the Propeller is that you can save a variable to the EEPROM such that it will automatically be reloaded with the last written value on the next power-up cycle. Assuming you're wanting to do with with a long, the syntax looks like this:
The first argument is the address to write to. If one uses the address of the variable being written, it will auto load after the next reset.
These objects also have basic read/write wrapper commands to handle basic byte operations. Hope these can help someone.
And what JonnyMac said is very useful. I implement that all the time in my software, with methods like these:
If you were looking for direct analogs for READ and WRITE, they don't exist because there was not enough room in the interpreter. For the same reason you don't find HIGH, LOW, INPUT, PAUSE, SHIFTIN, SHIFTOUT, etc. That said, the Propeller is far more powerful than the BASIC Stamp, and we can easily include advanced features with a bit of code. The best part about that is we get to decide exactly how those features work. I created my EEPROM object because I was developing a commercial product that records and plays back from the EEPROM. That object works exactly the way I need it to work.
That's embedded systems for you. It's lower level programming than most are used to. The nice thing is that people have (for the most part) already written the bit-banging side of things, so you can just simply use the write and read functions. But all embedded systems, PBASIC included, come down to bit-banging the information out. Each IC has a specific protocol that the controller has to conform to, so the software is customized to fit that protocol.