请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:LAUNCHCC3220MODASF 您好!
我们使用外部 RTC ds3231来获取日期和时间。 我们正在使用默认 I2C 库 ti/drivers/i2c.c、但在将时序写入 DS3231时、我遇到了 I2C 传输失败。
如果我将 DS3231连接到 esp32、则可以正常工作。
再生程序
*移除跳线 J14和 J15 ( ds3231模块具有内置 I2C 上拉)
*将 sda 和 scl 线从 ds3231连接到 launchpad 的 sda 和 scl 线
* ds3231由 cc32200 launchpad 的3.3V 电源供电
*运行下面的代码
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void RTC_test( struct tm *timeInfo) {
I2C_init();
// Initialize I2C
I2C_Handle i2cHandle;
I2C_Params i2cParams;
i2cParams.bitRate = I2C_400kHz ;
I2C_Params_init(&i2cParams);
i2cHandle = I2C_open(CONFIG_I2C_0, &i2cParams);
if (i2cHandle == NULL) {
// Handle error
Display_printf(display, 0, 0,"Error initializing I2C\n");
return;
}
// Prepare data to write
uint8_t data[8]; // The first byte is the register address
data[0] = DS3231_REG_ADDRESS ; // Start writing from address 0
data[1] = dec2bcd(timeInfo->tm_sec);
data[2] = dec2bcd(timeInfo->tm_min);
data[3] = dec2bcd(timeInfo->tm_hour);
data[4] = dec2bcd(timeInfo->tm_wday + 1);
请帮助我解决此问题