error: invalid conversion from 'char*' to 'uint32_t

error: invalid conversion from 'char*' to 'uint32_t

我正在尝试手动设置 RTC 时钟。 自动执行时,这是工作代码:

clock.setDateTime((__DATE__, __TIME__));

但现在我想手动设置它,这就是我正在尝试的:

char dateTime[20];
strcat(dateTime, "2017,03,22,16,20,04");
//clock.setDateTime((__DATE__, __TIME__));
clock.setDateTime(dateTime);

我收到以下错误(在最后一行):

error: invalid conversion from 'char*' to 'uint32_t {aka long unsigned int}' [-fpermissive]

如何解决?

编辑: setDateTime 是这样定义的:

void setDateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);

setDateTime() 接受 ints 作为参数,但你给它 char 数组。

调用应该是:

clock.setDataTime(2017, 3, 22, 16, 20, 4);

setDateTime() 将日期作为一连串整数:

setDateTime(year, month, day, hours, minutes, seconds);

奖金:根据man strcat

char *strcat(char *dest, const char *src);

Description

The strcat() function appends the src string to the dest string, ...

既然你这样使用它:

char dateTime[20];
strcat(dateTime, "2017,03,22,16,20,04");

您将 "2017,03,22,16,20,04" 附加到单元化内存,这是 未定义的行为