I want to use UART to read number more than 1 digit

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
DaCh_4286001
Level 3
Level 3
First like received First like given

My basic idea for this code is I will keep getChar from keyboard until I hit ENTER key.

However, it is not working if I type 1 2 3 ENTER. It will stuck in while(UART_GetRxBufferSize() < size_start_num)  until I enter 3 more digits then '123' will appear in Tera Term

Code is attached here

Simon

0 Likes
1 Solution

You have two lines where you get the data from UART. Line 47 and 63

Bob

View solution in original post

0 Likes
6 Replies
BoMa_4329931
Level 3
Level 3
First like received

Look at your last received character. when it is a number you save it in your result array, when it id a newline you are done. Otherwise it is an error. Classical structure for a "switch" statement.

Bob

0 Likes

The problem is I stuck in while(UART_GetRxBufferSize() < size_start_num) if I just type 1 2 3 ENTER

0 Likes

You have two lines where you get the data from UART. Line 47 and 63

Bob

0 Likes

but line 47 is getchar while 63 is readRxdata. These two are similar?

0 Likes

OK I see, both then are reading rxBuffer.

0 Likes
lock attach
Attachments are accessible only for community members.

You could try to get something out of the attached files

Bob

0 Likes