|
if((rx1_b[0] == 'g')&&(rx1_b[1] == 'e')&&(rx1_b[2] == 't')&&(rx1_b[3] == 'D')&&(rx1_b[4] == 'T')&&(rx1_b_index >=6))
{
setRTCflag=0x11;
}
主程序中处理:
switch(setRTCflag)
{
case 0x03:
//setT 12 30 09
//setD 2 2 11 2024
//setA 23 32 00 00
if (HAL_RTC_SetTime(&hrtc, &sTime2, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}
break;
case 0x05:
if (HAL_RTC_SetDate(&hrtc, &sDate2, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}
break;
/** Enable the Alarm A
*/
case 0x09:
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm2, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}
break;
case 0x11:
if(HAL_RTC_GetTime(&hrtc, &sTime2, RTC_FORMAT_BIN) == HAL_OK)
{
char uart_buf[100]={0};
HAL_RTC_GetDate(&hrtc, &sDate2, RTC_FORMAT_BIN);
char str[25]={0};
switch(sDate2.WeekDay)
{
case 1:
sprintf(str,"WeekDay is MONDAY\n");
break;
case 2:
sprintf(str,"WeekDay is TUESDAY\n");
break;
case 3:
sprintf(str,"WeekDay is WEDNESDAY\n");
break;
case 4:
sprintf(str,"WeekDay is THURSDAY\n");
break;
case 5:
sprintf(str,"WeekDay is FRIDAY\n");
break;
case 6:
sprintf(str,"WeekDay is SATURDAY\n");
break;
case 7:
sprintf(str,"WeekDay is SUNDAY\n");
break;
}
sprintf(uart_buf,"Date is 20%2d-%02d-%02d \n Time is %02d : %02d : %02d \n %s\n ",sDate2.Year,sDate2.Month,sDate2.Date,sTime2.Hours,sTime2.Minutes,sTime2.Seconds,str);
HAL_UART_Transmit_IT(&huart1,(const uint8_t*)&uart_buf[0], 100);
//HAL_UART_Transmit_IT(&huart1,(const uint8_t*)&uart_buf[0], 50);
HAL_Delay(10);
HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_SET);
HAL_Delay(100);
HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_RESET);
}
break;
default:break;
}
setRTCflag =0;