![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Basic fram test for spi connectivity
Dependencies: mbed
main.cpp@0:94b74988d717, 2015-01-30 (annotated)
- Committer:
- smigielski
- Date:
- Fri Jan 30 19:57:53 2015 +0000
- Revision:
- 0:94b74988d717
- Child:
- 1:711a282f7332
inital program to test fram
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
smigielski | 0:94b74988d717 | 1 | #include "mbed.h" |
smigielski | 0:94b74988d717 | 2 | |
smigielski | 0:94b74988d717 | 3 | SPI spi(P0_28, P0_24, P0_29); // mosi, miso, sclk |
smigielski | 0:94b74988d717 | 4 | DigitalOut cs(P0_23); |
smigielski | 0:94b74988d717 | 5 | DigitalOut hold(P0_23); |
smigielski | 0:94b74988d717 | 6 | |
smigielski | 0:94b74988d717 | 7 | |
smigielski | 0:94b74988d717 | 8 | // ACC Registers |
smigielski | 0:94b74988d717 | 9 | #define FM25CL_WREN 0x06 |
smigielski | 0:94b74988d717 | 10 | #define FM25CL_WRDI 0x04 |
smigielski | 0:94b74988d717 | 11 | #define FM25CL_RDSR 0x05 |
smigielski | 0:94b74988d717 | 12 | #define FM25CL_WRSR 0x01 |
smigielski | 0:94b74988d717 | 13 | #define FM25CL_READ 0x03 |
smigielski | 0:94b74988d717 | 14 | #define FM25CL_WRITE 0x02 |
smigielski | 0:94b74988d717 | 15 | |
smigielski | 0:94b74988d717 | 16 | #define TEST_LENGTH 4 |
smigielski | 0:94b74988d717 | 17 | |
smigielski | 0:94b74988d717 | 18 | void writeMemory(){ |
smigielski | 0:94b74988d717 | 19 | cs = 0; |
smigielski | 0:94b74988d717 | 20 | spi.write(FM25CL_RDSR); |
smigielski | 0:94b74988d717 | 21 | //should be 0x00 |
smigielski | 0:94b74988d717 | 22 | uint8_t val_register = spi.write(0x00); |
smigielski | 0:94b74988d717 | 23 | spi.write(FM25CL_WREN); |
smigielski | 0:94b74988d717 | 24 | spi.write(FM25CL_RDSR); |
smigielski | 0:94b74988d717 | 25 | //should be 0x04 |
smigielski | 0:94b74988d717 | 26 | uint8_t val_register2 = spi.write(0x00); |
smigielski | 0:94b74988d717 | 27 | spi.write(FM25CL_WRITE); |
smigielski | 0:94b74988d717 | 28 | spi.write(0x00); |
smigielski | 0:94b74988d717 | 29 | spi.write(0x00); |
smigielski | 0:94b74988d717 | 30 | for (uint8_t i=0;i<TEST_LENGTH;i++){ |
smigielski | 0:94b74988d717 | 31 | spi.write(i); |
smigielski | 0:94b74988d717 | 32 | } |
smigielski | 0:94b74988d717 | 33 | cs = 1; |
smigielski | 0:94b74988d717 | 34 | } |
smigielski | 0:94b74988d717 | 35 | void readMemory(){ |
smigielski | 0:94b74988d717 | 36 | cs = 0; |
smigielski | 0:94b74988d717 | 37 | spi.write(FM25CL_RDSR); |
smigielski | 0:94b74988d717 | 38 | //should be 0x00 |
smigielski | 0:94b74988d717 | 39 | uint8_t val_register = spi.write(0x00); |
smigielski | 0:94b74988d717 | 40 | spi.write(FM25CL_READ); |
smigielski | 0:94b74988d717 | 41 | spi.write(0x00); |
smigielski | 0:94b74988d717 | 42 | spi.write(0x00); |
smigielski | 0:94b74988d717 | 43 | //should be next increments up to test_length |
smigielski | 0:94b74988d717 | 44 | for (uint8_t i=0;i<TEST_LENGTH;i++){ |
smigielski | 0:94b74988d717 | 45 | uint8_t data = spi.write(0x00); |
smigielski | 0:94b74988d717 | 46 | } |
smigielski | 0:94b74988d717 | 47 | cs = 1; |
smigielski | 0:94b74988d717 | 48 | } |
smigielski | 0:94b74988d717 | 49 | |
smigielski | 0:94b74988d717 | 50 | //Test that spi is working with fram FM25CL memory |
smigielski | 0:94b74988d717 | 51 | int main() { |
smigielski | 0:94b74988d717 | 52 | hold=1; |
smigielski | 0:94b74988d717 | 53 | cs=1; |
smigielski | 0:94b74988d717 | 54 | while(1) { |
smigielski | 0:94b74988d717 | 55 | writeMemory(); |
smigielski | 0:94b74988d717 | 56 | wait(0.5); |
smigielski | 0:94b74988d717 | 57 | readMemory(); |
smigielski | 0:94b74988d717 | 58 | wait(0.5); |
smigielski | 0:94b74988d717 | 59 | } |
smigielski | 0:94b74988d717 | 60 | } |
smigielski | 0:94b74988d717 | 61 |