-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Driver for M24C01 EEPROM #20202
Comments
I wonder if the existing at24cxx driver would just work here. I was told that most EEPROMs are basically drop-in replacements for those. @fabian18 might just need only a quick look into the datasheet to see if those are compatible. |
I'm not fabian18, but a quick comparison of both datasheets did not yield significant potential issues. The only major difference is that the M24C01 does not support Fast Mode+ with 1MHz clock. This is the datasheet I compared it against: https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-8871F-SEEPROM-AT24C01D-02D-Datasheet.pdf We did not have any M24C01 in stock, so I ordered some to test it out. The results might take some time though. |
Okay, I actually did find M24C01 EEPROMs. I put them in my backpack weeks ago because I wanted to work on this issue 🤣 @maribu as you already assumed, the M24C01 works as it should as a drop-in replacement for the AT24C01. There is a difference in page size. The AT24C01 has a page size of 8 bytes and the M24C01 has a page size of 16 bytes. Partial page writes are allowed though, so from the user perspective, nothing changes. On this note, the AT24CXXX library is already very universal and in the https://github.com/RIOT-OS/RIOT/blob/master/drivers/at24cxxx/include/at24cxxx_defines.h file, a lot of defines for different I2C EEPROMs already exist. @leocordier As stated above, for the time being you can just use the settings of the AT24C01A and everything should work fine. I'll attach my test code. |
The code was tested with my NRF52840 Development Kit and an ST M24C01WP I2C EEPROM in DIP-8. Default Address, /WC line not connected. Just VCC, GND, SDA, SCL. main.c #include <stdio.h>
#include "at24cxxx.h"
int main(void)
{
at24cxxx_t eeprom_dev;
const at24cxxx_params_t eeprom_params = {
.i2c = 0,
.pin_wp = 2,
.eeprom_size = 128,
.dev_addr = 0x50,
.page_size = 16,
.max_polls = 8
};
int res = at24cxxx_init(&eeprom_dev, &eeprom_params);
if(res != AT24CXXX_OK) {
puts("Error while initializing the I2C EEPROM.");
} else {
puts("I2C EEPROM initialized successfully.");
}
char data[eeprom_dev.params.eeprom_size];
at24cxxx_read(&eeprom_dev, 0, &data, eeprom_dev.params.eeprom_size);
for(uint8_t i = 0; i < eeprom_dev.params.eeprom_size; i++) {
printf("%02X ", data[i]);
}
printf("\n");
fflush(stdout);
while(1);
return 0;
} Makefile APPLICATION = EEPROMTest
PROJECT_BASE ?= $(CURDIR)/../..
RIOTBASE ?= $(PROJECT_BASE)/RIOT
# Optionally, provide paths to where external boards and/or modules
# reside, so that they can be included in the app
EXTERNAL_MODULE_DIRS += $(PROJECT_BASE)/modules
EXTERNAL_BOARD_DIRS += $(PROJECT_BASE)/boards
BOARD ?= nrf52840dk
# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
DEVELHELP ?= 1
# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1
# Modules to include:
USEMODULE += at24cxxx
include $(RIOTBASE)/Makefile.include Edit: Updated the code (double occurance of at24cxxx_t dev;). |
@crasbe: Thanks for testing this ❤️ What we could do now is adding the parameters from the datasheet, similar to: RIOT/drivers/at24cxxx/include/at24cxxx_defines.h Lines 347 to 368 in 3c3c5c2
and select those by default if an RIOT/drivers/at24cxxx/include/at24cxxx_defines.h Lines 426 to 429 in 3c3c5c2
let the Lines 15 to 17 in 3c3c5c2
and finally, add With all that in place, one could just use Would you mind to open a PR to do that, so that you also get the credit in our git history, since you did the testing and digging through the data sheet? Otherwise I could also do that. |
I'll open a PR. That's the most sensible option anyways since I have the hardware to test it here on my desk :) There is actually code to support the MTD subsystem, but I'm not sure if my small 128 byte EEPROM (it's actually 1KBit instead of 1MBit as stated above) is enough for a LittleFS filesystem 🤣 |
@maribu I think the drivers/at24cxxx/Makefile.include would be a better place to define the pseudomodule for the M24C01 (or rather M24C%), considering the at24c% pseudomodules are not defined there either. Then we avoid "spamming" the global pseudomodules Makefile. Something else I noticed: However this issue is probably not the right place to discuss this, even though I'm not sure where a better place would be... |
This is my updated example/test code (now running on a nRF52832DK instead of the nRF52840DK, because I needed the latter for something else in the meantime.) The makefile and code demonstrate that the m24c01 pseudomodule is working. It utilizes the AT24CXXX_PARAMS macro, which is based on the defines derived from the pseudomodule definition. #include <stdio.h>
#include "at24cxxx.h"
#include "at24cxxx_params.h"
int main(void)
{
at24cxxx_t eeprom_dev;
at24cxxx_params_t eepronm_params = AT24CXXX_PARAMS;
int res = at24cxxx_init(&eeprom_dev, &eepronm_params);
if(res != AT24CXXX_OK) {
puts("Error while initializing the I2C EEPROM.");
} else {
puts("I2C EEPROM initialized successfully.");
}
char data[eeprom_dev.params.eeprom_size];
at24cxxx_read(&eeprom_dev, 0, &data, eeprom_dev.params.eeprom_size);
for(uint8_t i = 0; i < eeprom_dev.params.eeprom_size; i++) {
printf("%02X ", data[i]);
fflush(stdout);
}
printf("\n");
fflush(stdout);
while(1);
return 0;
} APPLICATION = EEPROMTest2
PROJECT_BASE ?= $(CURDIR)/../..
RIOTBASE ?= $(PROJECT_BASE)/RIOT
# Optionally, provide paths to where external boards and/or modules
# reside, so that they can be included in the app
EXTERNAL_MODULE_DIRS += $(PROJECT_BASE)/modules
EXTERNAL_BOARD_DIRS += $(PROJECT_BASE)/boards
BOARD ?= nrf52dk
# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
DEVELHELP ?= 1
# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1
# Modules to include:
USEMODULE += m24c01
include $(RIOTBASE)/Makefile.include This is the expected output on the serial terminal from this test program (depending on the content of the EEPROM of course...):
|
@maribu You can close this issue now :) |
Description
I would like to use the external EEPROM i have on my board, with basics functions to write and read data from it.
The component is a 1Mbit EEPROM from ST Microelectronics. It use the i2c protocol for the data transfer.
Useful links
Official component page: https://www.st.com/en/memories/m24c01-r.html
Datasheet : https://www.st.com/resource/en/datasheet/m24c01-r.pdf
The text was updated successfully, but these errors were encountered: