Basic example showing how to use a M24LR64 EEPROM with the STM32469I_DISCOVERY board. This EEPROM can be found on the additional ANT7-M24LR-A daughter board.
Dependencies: BSP_DISCO_F469NI EEPROM_DISCO_F469NI mbed
main.cpp
00001 #include "mbed.h" 00002 #include "EEPROM_DISCO_F469NI.h" 00003 00004 EEPROM_DISCO_F469NI eep; 00005 00006 DigitalOut led_green(LED1); 00007 DigitalOut led_red(LED2); 00008 00009 Serial pc(USBTX, USBRX); 00010 00011 #define BUFFER_SIZE ((uint32_t)32) 00012 #define WRITE_READ_ADDR ((uint32_t)0x0000) 00013 00014 int main() 00015 { 00016 // 12345678901234567890123456789012 00017 uint8_t WriteBuffer[BUFFER_SIZE+1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"; 00018 uint8_t ReadBuffer[BUFFER_SIZE+1]; 00019 uint16_t bytes_rd; 00020 00021 pc.printf("\n\nEEPROM demo started\n"); 00022 led_red = 0; 00023 00024 // Check initialization 00025 if (eep.Init() != EEPROM_OK) { 00026 led_red = 1; 00027 error("Initialization FAILED\n"); 00028 } else { 00029 pc.printf("Initialization PASSED\n"); 00030 } 00031 00032 // Write buffer 00033 if (eep.WriteBuffer(WriteBuffer, WRITE_READ_ADDR, BUFFER_SIZE) != EEPROM_OK) { 00034 led_red = 1; 00035 error("Write buffer FAILED\n"); 00036 } else { 00037 pc.printf("Write buffer PASSED\n"); 00038 } 00039 00040 // Read buffer 00041 bytes_rd = BUFFER_SIZE; 00042 if (eep.ReadBuffer(ReadBuffer, WRITE_READ_ADDR, &bytes_rd) != EEPROM_OK) { 00043 led_red = 1; 00044 error("Read buffer FAILED\n"); 00045 } else { 00046 ReadBuffer[BUFFER_SIZE] = '\0'; 00047 pc.printf("Read buffer PASSED\n"); 00048 pc.printf("Buffer read = [%s]\n", ReadBuffer); 00049 pc.printf("Bytes read = %d\n", bytes_rd); 00050 } 00051 00052 while(1) { 00053 led_green = !led_green; 00054 wait(1); 00055 } 00056 }
Generated on Wed Jul 13 2022 10:42:06 by 1.7.2