Fujitsu MB85RSxx serial FRAM test program

Dependencies:   mbed MB85RSxx_SPI

Connectivity

MB82RSxx pinmbed LPC1114FN28 pinmbed LPC1768 pinArudino form factor
1 (_CS)9 (dp9)8 (p8)D10
2 (SO)1 (dp1)6 (p6)D12
3 (_WP)21 (VDD)40 (VOUT)3V3
4 (VSS)22 (GND)1 (GND)GND
5 (SI)2 (dp2)5 (p5)D11
6 (SCK)6 (dp6)7 (p7)D13
7 (_HOLD)21 (VDD)40 (VOUT)3V3
8 (VDD)21 (VDD)40 (VOUT)3V3
Committer:
MACRUM
Date:
Mon Apr 24 14:03:53 2017 +0000
Revision:
1:bdf8b378dbc9
Parent:
0:20b32d13a758
Child:
3:3e6b31527e0e
Update library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 0:20b32d13a758 1 #include "mbed.h"
MACRUM 1:bdf8b378dbc9 2 #include "MB85RSxx_SPI.h"
MACRUM 0:20b32d13a758 3
MACRUM 0:20b32d13a758 4 DigitalOut myled(LED1);
MACRUM 0:20b32d13a758 5 Serial pc(USBTX, USBRX);
MACRUM 0:20b32d13a758 6
MACRUM 0:20b32d13a758 7 #if defined(TARGET_LPC1768)
MACRUM 1:bdf8b378dbc9 8 MB85RSxx_SPI _spi(p5, p6, p7, p8); // mosi, miso, sclk, cs
MACRUM 0:20b32d13a758 9 #elif defined(TARGET_LPC1114)
MACRUM 1:bdf8b378dbc9 10 MB85RSxx_SPI _spi(dp2, dp1, dp6, dp9); // mosi, miso, sclk, cs
MACRUM 0:20b32d13a758 11 #else // Arduino R3 Shield form factor
MACRUM 1:bdf8b378dbc9 12 MB85RSxx_SPI fram(D11, D12, D13, D10); // mosi, miso, sclk, cs
MACRUM 0:20b32d13a758 13 #endif
MACRUM 0:20b32d13a758 14
MACRUM 1:bdf8b378dbc9 15 int main()
MACRUM 0:20b32d13a758 16 {
MACRUM 0:20b32d13a758 17 uint8_t buf[16];
MACRUM 0:20b32d13a758 18 uint32_t address;
MACRUM 0:20b32d13a758 19
MACRUM 0:20b32d13a758 20 pc.baud(115200);
MACRUM 0:20b32d13a758 21 pc.printf("\nFujitsu MB85RSxxx FRAM test program\n\n");
MACRUM 1:bdf8b378dbc9 22
MACRUM 1:bdf8b378dbc9 23 // Read device ID and detect memory density for addressing
MACRUM 1:bdf8b378dbc9 24 fram.read_device_id(buf);
MACRUM 1:bdf8b378dbc9 25 pc.printf("read device ID = 0x%x 0x%x 0x%x 0x%x\n", buf[0], buf[1], buf[2], buf[3]);
MACRUM 0:20b32d13a758 26
MACRUM 1:bdf8b378dbc9 27 fram.write_enable();
MACRUM 1:bdf8b378dbc9 28 pc.printf("read status (WREN) = 0x%x\n", fram.read_status());
MACRUM 1:bdf8b378dbc9 29
MACRUM 1:bdf8b378dbc9 30 fram.write_disable();
MACRUM 1:bdf8b378dbc9 31 pc.printf("read status (WRDI) = 0x%x\n", fram.read_status());
MACRUM 1:bdf8b378dbc9 32
MACRUM 0:20b32d13a758 33 // Write 0 data
MACRUM 1:bdf8b378dbc9 34 fram.write_enable();
MACRUM 1:bdf8b378dbc9 35 fram.fill(0, 0, 256);
MACRUM 0:20b32d13a758 36
MACRUM 0:20b32d13a758 37 // Prepare write data
MACRUM 0:20b32d13a758 38 for (int i = 0; i < 16; i++) {
MACRUM 0:20b32d13a758 39 buf[i] = i;
MACRUM 0:20b32d13a758 40 }
MACRUM 1:bdf8b378dbc9 41
MACRUM 0:20b32d13a758 42 // Write data with write enable
MACRUM 1:bdf8b378dbc9 43 fram.write_enable();
MACRUM 1:bdf8b378dbc9 44 fram.write(0x00, buf, 16);
MACRUM 1:bdf8b378dbc9 45
MACRUM 0:20b32d13a758 46 // Attempt to write data (not written)
MACRUM 1:bdf8b378dbc9 47 fram.write(0x10, buf, 16);
MACRUM 1:bdf8b378dbc9 48
MACRUM 0:20b32d13a758 49 // Write data with write enable
MACRUM 1:bdf8b378dbc9 50 fram.write_enable();
MACRUM 1:bdf8b378dbc9 51 fram.write(0x20, buf, 16);
MACRUM 1:bdf8b378dbc9 52
MACRUM 0:20b32d13a758 53 // Read data
MACRUM 0:20b32d13a758 54 for (address = 0; address < 0x80; address += 16) {
MACRUM 1:bdf8b378dbc9 55 fram.read(address, buf, 16);
MACRUM 0:20b32d13a758 56 pc.printf("%08X : ", address);
MACRUM 0:20b32d13a758 57 for (int i = 0; i < 16; i++) {
MACRUM 1:bdf8b378dbc9 58 pc.printf("%02X ", buf[i]);
MACRUM 0:20b32d13a758 59 }
MACRUM 0:20b32d13a758 60 pc.printf("\n");
MACRUM 0:20b32d13a758 61 }
MACRUM 0:20b32d13a758 62
MACRUM 0:20b32d13a758 63 // Write number from 0 to 255
MACRUM 0:20b32d13a758 64 pc.printf("\n");
MACRUM 0:20b32d13a758 65 for (address = 0; address < 0x100; address++) {
MACRUM 1:bdf8b378dbc9 66 fram.write_enable();
MACRUM 1:bdf8b378dbc9 67 fram.write(address, (uint8_t)address);
MACRUM 0:20b32d13a758 68 }
MACRUM 0:20b32d13a758 69 // Read data
MACRUM 0:20b32d13a758 70 for (address = 0; address < 0x100; address += 16) {
MACRUM 1:bdf8b378dbc9 71 fram.read(address, buf, 16);
MACRUM 0:20b32d13a758 72 pc.printf("%08X : ", address);
MACRUM 0:20b32d13a758 73 for (int i = 0; i < 16; i++) {
MACRUM 1:bdf8b378dbc9 74 pc.printf("%02X ", buf[i]);
MACRUM 0:20b32d13a758 75 }
MACRUM 0:20b32d13a758 76 pc.printf("\n");
MACRUM 0:20b32d13a758 77 }
MACRUM 0:20b32d13a758 78
MACRUM 0:20b32d13a758 79 while(1) {
MACRUM 0:20b32d13a758 80 myled = 1;
MACRUM 0:20b32d13a758 81 wait(0.2);
MACRUM 0:20b32d13a758 82 myled = 0;
MACRUM 0:20b32d13a758 83 wait(0.2);
MACRUM 0:20b32d13a758 84 }
MACRUM 0:20b32d13a758 85 }
MACRUM 1:bdf8b378dbc9 86