Toyomasa Watarai
/
Hello-FM25W256
Hello program for the FM25W256 library
Diff: main.cpp
- Revision:
- 1:be908b1aafe6
- Parent:
- 0:3efb18460968
- Child:
- 2:980e3d46d20e
--- a/main.cpp Fri Mar 04 13:48:22 2016 +0000 +++ b/main.cpp Fri Mar 04 15:50:11 2016 +0000 @@ -1,56 +1,8 @@ #include "mbed.h" +#include "FM25W256.h" Serial pc(USBTX, USBRX); -SPI fram(dp2, dp1, dp6); -DigitalOut _cs(dp18); - -#define CMD_WREN 0x06 -#define CMD_WRDI 0x04 -#define CMD_RDSR 0x05 -#define CMD_WRSR 0x01 -#define CMD_READ 0x03 -#define CMD_WRITE 0x02 - -void write_byte(uint16_t address, uint8_t data) -{ - _cs = 0; - fram.write(CMD_WREN); - _cs = 1; - - _cs = 0; - fram.write(CMD_WRITE); - fram.write(address >> 8); - fram.write(address & 0xFF); - fram.write(data & 0xFF); - _cs = 1; -} - -uint8_t read_byte(uint16_t address) -{ - uint8_t data; - - _cs = 0; - fram.write(CMD_READ); - fram.write(address >> 8); - fram.write(address & 0xFF); - data = fram.write(0); - _cs = 1; - - return data; -} - -void read_bytes(uint16_t address, uint8_t *buf, uint16_t size) -{ - _cs = 0; - fram.write(CMD_READ); - fram.write(address >> 8); - fram.write(address & 0xFF); - while (size--) { - *buf++ = fram.write(0); - } - _cs = 1; -} - +FM25W256 f_ram(dp2, dp1, dp6, dp18); void read_test() { @@ -58,8 +10,7 @@ for(int i=0; i<16; i++) { pc.printf("0x%04X : ", i * 16); for(int j=0; j<16; j++) { - //pc.printf("%02X ", fram.write(0)); - pc.printf("%02X ", read_byte(adrs++)); + pc.printf("%02X ", f_ram.read(adrs++)); } pc.printf("\n"); } @@ -67,17 +18,15 @@ void write_test() { - for(int i=0; i<256; i++) { - write_byte(i, i); + uint8_t buf[16]; + for(int i=0; i<16; i++) { + buf[i] = (15 - i); } + f_ram.write(0, buf, 16); } int main() { - fram.format(8, 0); - fram.frequency(20000000); - _cs = 1; - pc.printf("\nFM25W256 test program - write test? (y/n) "); if (pc.getc() == 'y') { write_test();