Troubleshooting I2C Transaction Error with AVR Microcontroller and Zephyr RTOS

@Middleware & OS Gm guy's, I'm trying to interface an EEPROM with my AVR microcontroller using Zephyr RTOS. I've configured the I2C peripheral in the prj.conf file and set up the device tree bindings. However, when I attempt to write data to the EEPROM, I get an I2C transaction error. I have been able to configured the I2C peripheral in prj.conf. Created device bindings in the device tree source file (dts). and salso wrote an application to write data to the EEPROM. this is my code snippet:
#include <zephyr.h>
#include <device.h>
#include <drivers/i2c.h>
#include <logging/log.h>

LOG_MODULE_REGISTER(main);

#define EEPROM_I2C DT_NODELABEL(eeprom)

void main(void) {
const struct device *i2c_dev = DEVICE_DT_GET(EEPROM_I2C);

if (!device_is_ready(i2c_dev)) {
LOG_ERR("I2C device not ready");
return;
}

uint8_t data[2] = {0x00, 0xFF}; // Address and data to write
int ret = i2c_write(i2c_dev, data, sizeof(data), EEPROM_ADDR);

if (ret) {
LOG_ERR("I2C write failed: %d", ret);
return;
}

LOG_INF("Data written to EEPROM");
}
#include <zephyr.h>
#include <device.h>
#include <drivers/i2c.h>
#include <logging/log.h>

LOG_MODULE_REGISTER(main);

#define EEPROM_I2C DT_NODELABEL(eeprom)

void main(void) {
const struct device *i2c_dev = DEVICE_DT_GET(EEPROM_I2C);

if (!device_is_ready(i2c_dev)) {
LOG_ERR("I2C device not ready");
return;
}

uint8_t data[2] = {0x00, 0xFF}; // Address and data to write
int ret = i2c_write(i2c_dev, data, sizeof(data), EEPROM_ADDR);

if (ret) {
LOG_ERR("I2C write failed: %d", ret);
return;
}

LOG_INF("Data written to EEPROM");
}
Despite configuring everything, the I2C write operation fails. What could be causing this error?
2 Replies
RED HAT
RED HAT6mo ago
Hi @Dtynin make sure your EEPROM_ADDR is correctly defined and matches the address of your EEPROM device. This should be the 7-bit I2C address of the EEPROM.
Dtynin
Dtynin6mo ago
thanks @RED HAT I would ensure that.
Want results from more Discord servers?
Add your server