Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PROYECTO EEPROM
UNIVERSIDAD POLITECNICA SALESIANA
SEDE GUAYAQUIL
FACULTAD DE INGENIERIA
MAESTRIA EN ELECTRONICA Y AUTOMATIZACION
MATERIA: SISTEMAS MICROPROCESADOS
PROYECTO EEPROM
DESCRIPCION DEL PROYECTO:
El siguiente proyecto se encarga de realizar una programación para la configuración de una memoria, de esta manera pudimos escribir en la eeprom lo que deseamos mediante el comando print, es muy importante tener en cuenta el uso correcto de los códigos en el programa mbed y también utilizar la herramienta Hercules, eeprom son las siglas de Electrically Erasable Programmable Read-Only Memory (ROM programable y borrable eléctricamente). Es un tipo de memoria ROM que puede ser programada, borrada y reprogramada eléctricamente, a diferencia de la EPROM que ha de borrarse mediante un aparato que emite rayos ultravioleta. Las direcciones que se tomaron de la memoria eeprom fueron las A0, A1, A2. Para poder visualizar cuando se escribe en el eeprom utilizamos la herramienta Hercules, utilizamos el puerto COM3 para el puerto serial y el puerto COM4 para el usb.
El STM32F4 DISCOVERY permite el desarrollo de aplicaciones con el microcontrolador ARM Cortex-M4F de alto rendimiento. Características principales IDE de desarrollo de aplicaciones para toda la familia de microcontroladores ARM CORTEX M-4 Basado en componentes y librerías de código abierto Programación de alto nivel en C/C++ Editor, compilador y depurador
EEPROM 24C16N Características: Memoria serial tipo EEPROM de 16 kbit (2048 x 8) Bus I²C. ... Entrada de control de escritura. Escritura por byte y por página (Hasta 16 bytes) Modo de lectura aleatoria y secuencial. Incremento automático de la dirección. Soporta más de 1 millón de ciclos de escritura. Retención de los datos mayor a 40 años.
CODIGO REALIZADO EN MBED DEL PROYECTO EEPROM E IMAGINES DEL PROYECTO IMPLEMENTADO
- include "mbed.h"
- include <string>
- include "eeprom.h"
- define EEPROM_ADDR 0x0 I2c EEPROM address is 0x00
- define SDA PB_9 I2C SDA pin
- define SCL PB_10 I2C SCL pin
- define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
- define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
DigitalOut led2(LED2);
typedef struct _MyData { int16_t sdata; int32_t idata; float fdata; } MyData;
static void myerror(std::string msg) { printf("Error %s\n",msg.c_str()); exit(1); }
void eeprom_test(void) { EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C64); 24C64 eeprom with sda = p9 and scl = p10 uint8_t data[256],data_r[256]; int8_t ival; uint16_t s; int16_t sdata,sdata_r; int32_t ldata[1024]; int32_t eeprom_size,max_size; uint32_t addr; int32_t idata,idata_r; uint32_t i,j,k,l,t,id; float fdata,fdata_r; MyData md,md_r;
eeprom_size = ep.getSize(); max_size = MIN(eeprom_size,256);
printf("Test EEPROM I2C model %s of %d bytes\n\n",ep.getName(),eeprom_size);
Test sequential read byte (max_size first bytes) for(i = 0;i < max_size;i++) { ep.read(i,ival); data_r[i] = ival; if(ep.getError() != 0) myerror(ep.getErrorMessage()); }
printf("Test sequential read %d first bytes :\n",max_size); for(i = 0;i < max_size/16;i++) { for(j = 0;j < 16;j++) { addr = i * 16 + j; printf("%3d ",(uint8_t)data_r[addr]); } printf("\n"); }
Test sequential read byte (max_size last bytes) for(i = 0;i < max_size;i++) { addr = eeprom_size - max_size + i; ep.read(addr,ival); data_r[i] = ival; if(ep.getError() != 0) myerror(ep.getErrorMessage()); }
printf("\nTest sequential read %d last bytes :\n",max_size); for(i = 0;i < max_size/16;i++) { for(j = 0;j < 16;j++) { addr = i * 16 + j; printf("%3d ",(uint8_t)data_r[addr]); } printf("\n"); }
Test write byte (max_size first bytes) for(i = 0;i < max_size;i++) data[i] = i;
for(i = 0;i < max_size;i++) { ep.write(i,(int8_t)data[i]); if(ep.getError() != 0) myerror(ep.getErrorMessage()); }
Test read byte (max_size first bytes) for(i = 0;i < max_size;i++) { ep.read(i,(int8_t&)ival); data_r[i] = (uint8_t)ival; if(ep.getError() != 0) myerror(ep.getErrorMessage()); }
printf("\nTest write and read %d first bytes :\n",max_size); for(i = 0;i < max_size/16;i++) { for(j = 0;j < 16;j++) { addr = i * 16 + j; printf("%3d ",(uint8_t)data_r[addr]); } printf("\n"); }
Test current address read byte (max_size first bytes) ep.read((uint32_t)0,(int8_t&)ival); current address is 0 data_r[0] = (uint8_t)ival; if(ep.getError() != 0) myerror(ep.getErrorMessage());
for(i = 1;i < max_size;i++) { ep.read((int8_t&)ival); data_r[i] = (uint8_t)ival; if(ep.getError() != 0) myerror(ep.getErrorMessage()); }
printf("\nTest current address read %d first bytes :\n",max_size); for(i = 0;i < max_size/16;i++) { for(j = 0;j < 16;j++) { addr = i * 16 + j; printf("%3d ",(uint8_t)data_r[addr]); } printf("\n"); }
Test sequential read byte (first max_size bytes) ep.read((uint32_t)0,(int8_t *)data_r,(uint32_t) max_size); if(ep.getError() != 0) myerror(ep.getErrorMessage());
printf("\nTest sequential read %d first bytes :\n",max_size); for(i = 0;i < max_size/16;i++) { for(j = 0;j < 16;j++) { addr = i * 16 + j; printf("%3d ",(uint8_t)data_r[addr]); } printf("\n"); }
Test write short, long, float sdata = -15202; addr = eeprom_size - 16; ep.write(addr,(int16_t)sdata); short write at address eeprom_size - 16 if(ep.getError() != 0) myerror(ep.getErrorMessage());
idata = 45123; addr = eeprom_size - 12; ep.write(addr,(int32_t)idata); long write at address eeprom_size - 12 if(ep.getError() != 0) myerror(ep.getErrorMessage());
fdata = -12.26; addr = eeprom_size - 8; ep.write(addr,(float)fdata); float write at address eeprom_size - 8 if(ep.getError() != 0) myerror(ep.getErrorMessage());
Test read short, long, float printf("\nTest write and read short (%d), long (%d), float (%f) :\n", sdata,idata,fdata);
ep.read((uint32_t)(eeprom_size - 16),(int16_t&)sdata_r); if(ep.getError() != 0) myerror(ep.getErrorMessage()); printf("sdata %d\n",sdata_r);
ep.read((uint32_t)(eeprom_size - 12),(int32_t&)idata_r); if(ep.getError() != 0) myerror(ep.getErrorMessage()); printf("idata %d\n",idata_r);
ep.read((uint32_t)(eeprom_size - 8),fdata_r); if(ep.getError() != 0) myerror(ep.getErrorMessage()); printf("fdata %f\n",fdata_r);
Test read and write a structure md.sdata = -15203; md.idata = 45124; md.fdata = -12.27;
ep.write((uint32_t)(eeprom_size - 32),(void *)&md,sizeof(md)); write a structure eeprom_size - 32 if(ep.getError() != 0) myerror(ep.getErrorMessage());
printf("\nTest write and read a structure (%d %d %f) :\n",md.sdata,md.idata,md.fdata);
ep.read((uint32_t)(eeprom_size - 32),(void *)&md_r,sizeof(md_r)); if(ep.getError() != 0) myerror(ep.getErrorMessage());
printf("md.sdata %d\n",md_r.sdata); printf("md.idata %d\n",md_r.idata); printf("md.fdata %f\n",md_r.fdata);
Test read and write of an array of the first max_size bytes for(i = 0;i < max_size;i++) data[i] = max_size - i - 1;
ep.write((uint32_t)(0),data,(uint32_t)max_size); if(ep.getError() != 0) myerror(ep.getErrorMessage());
ep.read((uint32_t)(0),data_r,(uint32_t)max_size); if(ep.getError() != 0) myerror(ep.getErrorMessage());
printf("\nTest write and read an array of the first %d bytes :\n",max_size); for(i = 0;i < max_size/16;i++) { for(j = 0;j < 16;j++) { addr = i * 16 + j; printf("%3d ",(uint8_t)data_r[addr]); } printf("\n"); } printf("\n");
Test write and read an array of int32 s = eeprom_size / 4; size of eeprom in int32 int ldata_size = sizeof(ldata) / 4; size of data array in int32 l = s / ldata_size; loop index
size of read / write in bytes t = eeprom_size; if(t > ldata_size * 4) t = ldata_size * 4;
printf("Test write and read an array of %d int32 (write entire memory) :\n",t/4);
Write entire eeprom if(l) { for(k = 0;k < l;k++) { for(i = 0;i < ldata_size;i++) ldata[i] = ldata_size * k + i;
addr = k * ldata_size * 4; ep.write(addr,(void *)ldata,t); if(ep.getError() != 0) myerror(ep.getErrorMessage()); }
printf("Write OK\n");
Read entire eeprom id = 0; for(k = 0;k < l;k++) { addr = k * ldata_size * 4; ep.read(addr,(void *)ldata,t); if(ep.getError() != 0) myerror(ep.getErrorMessage());
format outputs with 8 words rows for(i = 0;i < ldata_size / 8;i++) { id++; printf("%4d ",id); for(j = 0;j < 8;j++) { addr = i * 8 + j; printf("%5d ",ldata[addr]); } printf("\n"); } } } else { for(i = 0;i < s;i++) ldata[i] = i;
addr = 0; ep.write(addr,(void *)ldata,t); if(ep.getError() != 0) myerror(ep.getErrorMessage());
printf("Write OK\n");
Read entire eeprom id = 0;
addr = 0; ep.read(addr,(void *)ldata,t); if(ep.getError() != 0) myerror(ep.getErrorMessage());
format outputs with 8 words rows for(i = 0;i < s / 8;i++) { id++; printf("%4d ",id); for(j = 0;j < 8;j++) { addr = i * 8 + j; printf("%5d ",ldata[addr]); } printf("\n"); } }
clear eeprom printf("\nClear eeprom\n");
ep.clear(); if(ep.getError() != 0) myerror(ep.getErrorMessage());
printf("End\n");
}
int main() {
eeprom_test();
return(0); }
Tarjeta STM32 junto al circuito con el EEPROM y el circuito utilizado para el proyecto
Tarjeta STM32 en implementación de proyecto
Se aprecia que el programa realizado en mbed ha sido cargado a la tarjeta STM32
Se puede observar como se imprime en el EEPROM el comando programado previamente en el mbed.
PIN OUT DEL EEPROM 24C64 O 24C16N
PINOUT DE LA TARJETA STM32
CONCLUSIONES
- Al momento de utilizar una EEPROM hay que tener en cuenta la capacidad de memoria de almacenamiento de dicho integrado. En este caso se uso una EEPROM 24C16N que tiene mas capacidad de memoria que una 24C64. La tarjeta STM32 es muy importante para la realización de proyectos de este tipo, es muy didáctico y de gran ayuda para la comunicación entre la EEPROM y la tarjeta.
RECOMENDACIONES
- Al momento de empezar a interactuar con el EEPROM es muy importante saber el correcto uso del mismo como también conocer bien el pinout del integrado tanto como el de la tarjeta STM32.