Test Program for AT241024. Byte R/W, Page R/W

Dependencies:   AT24C1024 mbed-rtos mbed

main.cpp

Committer:
ryood
Date:
2016-11-25
Revision:
2:ba28083ac613
Parent:
1:c671dcf90b11
Child:
3:2265ade869a4

File content as of revision 2:ba28083ac613:

#include "mbed.h"
#include "AT24C1024.h"

I2C         i2c(D14, D15);      // SDA, SCL
AT24C1024   at24c1024(i2c);     // Atmel 1Mbit EE-PROM

DigitalOut led1(LED1);

int main()
{
    printf("\r\n*** AT24C1024 Test ***\r\n");

    // Byte Read/Write
    // 
    uint8_t dt = 0x55;
    printf("Byte Write: %02x\r\n", dt);
    at24c1024.write(0, dt);     // write addr=0 data=dt
    wait_ms(5);
    dt = at24c1024.read(0);     // read addr=0
    printf("Byte Read: %02x\r\n", dt);

    // Page Read/Write
    // 
    uint8_t eep_buf[258], r_eep_buf[258];
    for (int i = 0; i < 256; i++) {
        eep_buf[i] = i;
        r_eep_buf[i] = 0x00;
    }
    printf("Page Write: 0..255\r\n");
    AT24C_STATUS status = at24c1024.write_page(0x1ff00, eep_buf, sizeof(eep_buf));
    wait_ms(5);
    printf("Status: %d\r\n", status);
    printf("Page Read:\r\n");
    status = at24c1024.read_page(0x1ff00, r_eep_buf, sizeof(r_eep_buf));
    printf("Status: %d\r\n", status);
    for (int i = 0; i < sizeof(r_eep_buf); i++) {
        printf("%d ", r_eep_buf[i]);
    }
    printf("\r\n");

    while(1) {
        led1 = !led1;
        wait(0.2);
    }
}