For following code, I am not able to read and print the value from EEPROM.
Code :
#include "driver/i2c.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define I2C_PORT_NUM I2C_NUM_0
#define EEPROM_ADDR 0x50
void i2c_task(void *arg) {
uint8_t Write_data[3] = {0xAA, 0x11, 0x22}; // Data to be written to EEPROM
uint8_t Read_data[3]; // Data read from EEPROM
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (EEPROM_ADDR << 1) | I2C_MASTER_WRITE, true);
i2c_master_write(cmd, Write_data, 3, true);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(I2C_PORT_NUM, cmd, pdMS_TO_TICKS(1000));
i2c_cmd_link_delete(cmd);
printf("Write operation return value: %d\n", ret);
printf("Write data: %02X %02X %02X\n", Write_data[0], Write_data[1], Write_data[2]);
vTaskDelay(pdMS_TO_TICKS(2000)); // Delay for 1 second
cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (EEPROM_ADDR << 1) | I2C_MASTER_READ, true);
i2c_master_read(cmd, Read_data, 3, I2C_MASTER_LAST_NACK);
i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(I2C_PORT_NUM, cmd, pdMS_TO_TICKS(1000));
i2c_cmd_link_delete(cmd);
printf("Read operation return value: %d\n", ret);
// Print the data read from EEPROM
printf("Read data: %02X %02X %02X\n", Read_data[0], Read_data[1], Read_data[2]);
vTaskDelete(NULL);
}
void app_main(void) {
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = 21,
.scl_io_num = 22,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master = {
.clk_speed = 400000
}
};
i2c_param_config(I2C_PORT_NUM, &conf);
i2c_driver_install(I2C_PORT_NUM, I2C_MODE_MASTER, 0, 0, 0);
xTaskCreate(i2c_task, "i2c_task", 2048, NULL, 10, NULL);
}
Output:
Write operation return value: 0
Write data: AA 11 22
Read operation return value: 0
Read data: FF FF FF
Please help me to find the misktake
EEPROM interfacing issue with ESP32 WROOM Board
-
- Posts: 1
- Joined: Sat May 06, 2023 8:43 am
-
- Posts: 1709
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: EEPROM interfacing issue with ESP32 WROOM Board
What kind of EEPROM? Brand/Manufacturer, size, part#,...?
Pretty certain you need to also send the memory address you wish to access to the device before you write or read any data.
Then you may have to wait some time for the device to complete the write operation before accessing it again.
And make sure the part is not in write-protected mode.
Pretty certain you need to also send the memory address you wish to access to the device before you write or read any data.
Then you may have to wait some time for the device to complete the write operation before accessing it again.
And make sure the part is not in write-protected mode.
Who is online
Users browsing this forum: Baidu [Spider] and 94 guests