I have some problem when I use a stm32 discovery board send data to another one and it can get correct data and print in callback function, but cannot print correctly in other function.
void UART7_IRQHandler()
{
HAL_UART_IRQHandler(&huart7);
HAL_UART_Receive_IT(&huart7, (uint8_t *)UART7RxBuffer, 16);
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart)
{
if(huart->Instance == UART7) {
X = (UART7RxBuffer[1]-48) + (UART7RxBuffer[3]-48)*0.1 + (UART7RxBuffer[4]-48)*0.01 + (UART7RxBuffer[5]-48)*0.001;
}
}
But I receive wrong data like this
void controller(){
printf("%.3f\t\n", X);
}
It should be 0.012, and it correct in HAL_UART_RxCpltCallback(), I receive -38.02, -0.009, 0.512, 0.012, -1.948 and so on in controller. How should I do to prevent this situation?