Dtynin
Dtynin
How can I resolve I2C transfer failure on AVR128DA48 with BMP280 sensor in Zephyr OS?
Hello guys, I'm working on a real-time pressure monitoring system for industrial automation using the AVR128DA48 microcontroller and Zephyr OS. I'm interfacing a BMP280 pressure sensor via I2C, but I'm encountering an error during communication. The I2C wiring and connections between the BMP280 sensor and AVR128DA48 are verified to be ok, I double-checked the BMP280 sensor's I2C address (0x76), and updated the device tree for correct I2C configuration in Zephyr OS. yet still having this issue I2C transfer failed with error code -EIO making it unable to establish successful I2C communication with the BMP280 sensor. who has an idea of how I can reslove it? this is my code:
#include <zephyr.h>
#include <device.h>
#include <drivers/i2c.h>
#include <drivers/sensor.h>


#define BMP280_ADDR 0x76
#define I2C_DEV "I2C_0"

void main(void)
{
const struct device *i2c_dev = device_get_binding(I2C_DEV);
struct sensor_value pressure;
if (i2c_dev == NULL) {
printk("Failed to bind to I2C device\n");
return;
}

const struct device *bmp280 = device_get_binding(DT_LABEL(DT_INST(0, bosch_bmp280)));
if (bmp280 == NULL) {
printk("Failed to initialize BMP280\n");
return;
}

while (1) {
sensor_sample_fetch(bmp280);
sensor_channel_get(bmp280, SENSOR_CHAN_PRESS, &pressure);
printk("Pressure: %d.%06d kPa\n", pressure.val1, pressure.val2);
k_sleep(K_SECONDS(5));
}
}
#include <zephyr.h>
#include <device.h>
#include <drivers/i2c.h>
#include <drivers/sensor.h>


#define BMP280_ADDR 0x76
#define I2C_DEV "I2C_0"

void main(void)
{
const struct device *i2c_dev = device_get_binding(I2C_DEV);
struct sensor_value pressure;
if (i2c_dev == NULL) {
printk("Failed to bind to I2C device\n");
return;
}

const struct device *bmp280 = device_get_binding(DT_LABEL(DT_INST(0, bosch_bmp280)));
if (bmp280 == NULL) {
printk("Failed to initialize BMP280\n");
return;
}

while (1) {
sensor_sample_fetch(bmp280);
sensor_channel_get(bmp280, SENSOR_CHAN_PRESS, &pressure);
printk("Pressure: %d.%06d kPa\n", pressure.val1, pressure.val2);
k_sleep(K_SECONDS(5));
}
}
I'm expected to print pressure values in the console if successful.
4 replies