![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Basic fram test for spi connectivity
Dependencies: mbed
main.cpp
- Committer:
- smigielski
- Date:
- 2015-01-30
- Revision:
- 2:d11473ce92d6
- Parent:
- 1:711a282f7332
- Child:
- 3:f71a526212cc
File content as of revision 2:d11473ce92d6:
#include "mbed.h" SPI spi(P0_02, P0_03, P0_04); // mosi, miso, sclk DigitalOut cs(P0_30); DigitalOut hold(P0_01); // ACC Registers #define FM25CL_WREN 0x06 #define FM25CL_WRDI 0x04 #define FM25CL_RDSR 0x05 #define FM25CL_WRSR 0x01 #define FM25CL_READ 0x03 #define FM25CL_WRITE 0x02 #define TEST_LENGTH 4 void readRegister(){ cs = 0; spi.write(FM25CL_RDSR); //should be 0x00 uint8_t val_register = spi.write(0x00); cs = 1; } void enableWrite(){ cs = 0; spi.write(FM25CL_WREN); cs = 1; } void writeMemory(){ cs = 0; spi.write(FM25CL_WRITE); spi.write(0x00); spi.write(0x00); for (uint8_t i=0;i<TEST_LENGTH;i++){ spi.write(i); } cs = 1; } void readMemory(){ cs = 0; spi.write(FM25CL_READ); spi.write(0x00); spi.write(0x00); //should be next increments up to test_length for (uint8_t i=0;i<TEST_LENGTH;i++){ uint8_t data = spi.write(0x00); } cs = 1; } //Test that spi is working with fram FM25CL memory int main() { hold=1; cs=1; while(1) { readRegister(); enableWrite(); readRegister(); writeMemory(); readRegister(); readMemory(); wait(0.5); } }