A simple hello world program that writes and reads to and from FeRAM

Dependencies:   mbed FeRAM

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "FeRAM.h"
00003 
00004 FeRAM RAM(p11, p12, p13);
00005 Serial pc(USBTX,USBRX);
00006 
00007 int main() {
00008     unsigned char write_array[10], read_array[10];
00009 
00010     // Write to and read back from memory in single bytes
00011     for (int i = 0; i < 10; i++) {
00012         write_array[i] = i;                     // Set write value
00013         RAM.write_byte( i, write_array[i]);     // Write byte
00014         read_array[i] = 0;                      // Zero read array
00015         read_array[i] = RAM.read_byte(i);       // Read back from memory
00016     }
00017 
00018     pc.printf("\n\r Single byte values are: ");
00019     for (int i = 0; i < 10; i++) {
00020         pc.printf("%d, ",read_array[i]);        // Print read values
00021         read_array[i] = 0;                      // Zero read array
00022     }
00023 
00024     // Write to and read back from memory in multiple bytes
00025     RAM.write_multiple_bytes (100, write_array, 10);
00026     RAM.read_multiple_bytes(100, read_array, 10);
00027 
00028     pc.printf("\n\r Multiple byte values are: ");
00029     for (int i = 0; i < 10; i++) {
00030         pc.printf("%d, ",read_array[i]);        // Print read values
00031     }
00032 }