Become a leader in the IoT community!
Join our community of embedded and IoT practitioners to contribute experience, learn new skills and collaborate with other developers with complementary skillsets.
Join our community of embedded and IoT practitioners to contribute experience, learn new skills and collaborate with other developers with complementary skillsets.
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");
}
If the implementation is successful, the output should log a message indicating that the RTC data has been read successfully.
DS1307?
You may need to enable the RTC clock, look at register 0x00 bit 7 should be a CH value.
yeah thanks it worked @superbike_z
amazing!
CONTRIBUTE TO THIS THREAD