Why do you using polling method? First, you should get a string. Then parse it.
When you using old crap microcontrollers like a PIC or AVR, you can use interrupt to receive data from host. But ARM gives you posibility to use FIFO and DMA.
Why do you using polling method? First, you should get a string. Then parse it.
When you using old crap microcontrollers like a PIC or AVR, you can use interrupt to receive data from host. But ARM gives you posibility to use FIFO and DMA.
int scannumber()
{
uint8_t rxbuff,x[8]={0},i=0;//[8];
mss_uart_instance_t * this_uart = &g_mss_uart1;
int num;
while(i<8)
{
UART_Polled_Rx( &g_mss_uart1, &rxbuff, sizeof(rxbuff) );
if(rxbuff == '\r')
{
[B]x[i]=0; // add here string terminator [/B]
rxbuff= this_uart->hw_reg->RBR; // i don't now the purpose of this ????
rxbuff= this_uart->hw_reg->RBR; // i don't now the purpose of this ????
break;
}
else
x[i++]=rxbuff;
}
num = atoi(x);
return num;
}
string length for unsigned integer 16bits is 6 .. not 8 "65536" 5 chars + zero
Apart from all detail points what might be coded differently, the function is already reading a string x which is converted to integer number. So what's your exact problem?
To return a string from a function, you would usually supply a pointer to char array that receives the string along with a maximal number of characters. Missing length check is a serious flaw of the shown code, you can easily crash the application by typing many characters without carriage return.