【发布时间】:2016-07-25 00:08:31
【问题描述】:
我正在尝试使用 epoch 时间在 STM32L051T6 微控制器上设置 RTC 时间。所以下面是我的代码。
void Rtc_SetTime(uint32_t time_)
{
struct tm* brokenTime;
const time_t temp = 3600;
brokenTime = gmtime(&temp);
if (NULL == brokenTime)
{
printf("Error: Failed to convert time.\r\n");
}
}
当我调用上述函数时。它总是转到if 语句并打印错误。我尝试将值 3600、1459841178 作为参数传递。一切都失败了。代码有什么问题?
【问题讨论】:
-
您能否在 else 语句中致电
perror以了解发生了什么? -
你确定
TIME_T是一个有效的time_tvar? -
移除演员表。如果您收到编译器警告/错误,则意味着代码一直都是错误的。您需要修复代码,而不是抑制警告。
-
@purplepsycho perror 打印“无错误(errno = 0)”
-
尝试使用 gmtime_r() 并分析输出本身。不仅仅是错误代码
标签: c date microcontroller epoch