Here is some example code for reading and writing from an EEPROM connected via SPI to a ZBasic device. All you need for your own code is the module named spi.bas which has all of the interface code. The other two modules (testspi.bas and debug.bas) only exist as example code.
You connect the EEPROM chip to the SCK, MOSI, and MISO pins. For the EEPROM SPI select you have several alternatives depending on the type of ZBasic device:
1. If the device uses native mode (has a "n", "s", or "x" in the name (e.g. ZX-24su) then you can use the CS pin or any other pin for chip select.
2. If the device has a ZBasic virtual machine and uses flash for program storage (ZX-128e, ZX-1281e, ZX-1280e, ZX-24r, ZX-24ru) then you can use the CS pin or any other pin for chip select.
3. If the device has a ZBasic virtual machine and uses EEPROM for program memory (e.g. ZX-24a, ZX-24p, etc.) then you need to find a different pin for chip select.
Note that the example code uses the CS pin for the EEPROM chip select so you may need to change it if you use another pin for chip select.
You can buy 64K SPI EEPROMs from my website: http://oakmicros.com/content/64K-EEPROM.html
Edited 12/31/10 to update example code to show how to write/read additional datatypes and added functions for reading and writing Single values.
SPI EEPROM Example
SPI EEPROM Example
- Attachments
-
- spi_example.zip
- SPI Example code (updated)
- (6.18 KiB) Downloaded 2054 times
Mike Perks