Question
Problem with scanf in STM32F4, it is scanning only the first char even I am requesting to scan an int or float. Details in description
here is the code I am using to scan
int ScanConfig(__const char * format, va_list args) {
unsigned i=0;
char ch = 0;
char buffer[256];
int ret = 0;
while((i<sizeof(buffer))&&(ch!='\n')&&(ch!='\r')){
HAL_StatusTypeDef status = HAL_TIMEOUT;
while (status == HAL_TIMEOUT) {
status = HAL_UART_Receive(&UartHandle1, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
if (status == HAL_TIMEOUT) {
/*HAL_UART_DeInit(&rxHandle);
HAL_UART_Init(&rxHandle);*/
}
else
break;
}
buffer[i]=ch;
i++;
ret = vsscanf(buffer, format, args);
if (ret > 0)
break;
}
buffer[i]=0;
return ret;
}
int Scan(__const char * format, ...) {
va_list args;
va_start(args, format);
int size = ScanConfig(format, args);
va_end(args);
return size;
}I am calling the function like this:
Scan("%f",&InVar);The problem that if I try to enter 4.5 for example, I can't and it saves only 4.
