Dtynin
Dtynin
DIIDevHeads IoT Integration Server
Created by Dtynin on 7/24/2024 in #pcb-and-analog
Failed to Read RTC Data with ATmega2560 and Zephyr OS: Integration Issue
Hey guys, so I've been trying to integrate an RTC module with an ATmega2560 and Zephyr OS for time-stamped data logging, and resolve the issue of failing to read from the RTC? I have tried connecting the RTC module via I2C and implementing RTC read and write operations, despite that, I've been encountering the error "Failed to read from RTC." Here's the code:
#include <zephyr.h>
#include <device.h>
#include <drivers/i2c.h>
#include <logging/log.h>

LOG_MODULE_REGISTER(main);

#define I2C_DEV_NAME DT_LABEL(DT_NODELABEL(i2c1))
#define RTC_ADDR 0x68

const struct device *i2c_dev;

void main(void)
{
uint8_t rtc_data[7];

i2c_dev = device_get_binding(I2C_DEV_NAME);
if (!i2c_dev) {
LOG_ERR("I2C: Device driver not found");
return;
}

if (i2c_read(i2c_dev, rtc_data, sizeof(rtc_data), RTC_ADDR) != 0) {
LOG_ERR("Failed to read from RTC");
return;
}

LOG_INF("RTC data read successfully");
}
#include <zephyr.h>
#include <device.h>
#include <drivers/i2c.h>
#include <logging/log.h>

LOG_MODULE_REGISTER(main);

#define I2C_DEV_NAME DT_LABEL(DT_NODELABEL(i2c1))
#define RTC_ADDR 0x68

const struct device *i2c_dev;

void main(void)
{
uint8_t rtc_data[7];

i2c_dev = device_get_binding(I2C_DEV_NAME);
if (!i2c_dev) {
LOG_ERR("I2C: Device driver not found");
return;
}

if (i2c_read(i2c_dev, rtc_data, sizeof(rtc_data), RTC_ADDR) != 0) {
LOG_ERR("Failed to read from RTC");
return;
}

LOG_INF("RTC data read successfully");
}
If the implementation is successful, the output should log a message indicating that the RTC data has been read successfully.
6 replies