How uart1_read() works?

Thread Starter

varden

Joined Jul 11, 2016
38
I don't understand the logic of this command. When we say
Code:
if(UART1_Data_Ready())
uart_rd=UART1_Read();
does it store all coming data in uart_rd[0]? Is there any way to store daha not in just one sector but in all array extended?
I mean not
Code:
uart_rd[0]= 'data'
but
Code:
uart_rd[0]='d';
uart_rd[1]='a';
uart_rd[2]='t';
uart_rd[3]='a';
 

ErnieM

Joined Apr 24, 2011
8,377
If uart_rd is truly an array then your statement

uart_rd =UART_Rd();

Should throw a compile error. Thay symbol is a pointer and not a variable, so you are attempting to change a pointer, and a pointer to an array it is also a constant pointer that cannot be changed.

I would guess (not having your library docs) that the read function returns a single character as that is typical, you receive one character at a time. Your job as the programmer is to assemble the characters into someone more meaningful by your understanding of the data being sent, what the actual content is to be expected.

Sometimes this is as simple as all messages end with a trailing zero character, so you can read characters up until you get that zero and copy each into the array using an index variable.
 

Thread Starter

varden

Joined Jul 11, 2016
38
I use mikro C and pic 18F4550. Actually uart_rd =UART_Rd(); works. I send data with uart. Like words or sentences. And can print them into LCD without any problem. But no matter how I try, I can't get them in array as I told before. Also I am very confused. Please can you give some examples?
 

ErnieM

Joined Apr 24, 2011
8,377
First, what does your incoming data look like? Does it have a constant length or a zero at the end? How can you tell one chunk of data from the next?
 

MaxHeadRoom

Joined Jul 18, 2013
28,698
A Uart clocks what is usually a maximum 8 bit word into its register a bit at a time at the baud rate selected, sometimes having a word register storage with the next byte ready to clock in,
Once the buffer is full it has to be read in order for the next word to be clocked in.
Max.

,
 

Thread Starter

varden

Joined Jul 11, 2016
38
I send data with bluetooth module to uart. With bluetooth terminal program, I write anything and send it.
 

ErnieM

Joined Apr 24, 2011
8,377
I send data with bluetooth module to uart. With bluetooth terminal program, I write anything and send it.
Literally "anything" is a very tough data set to parse out items that make sense.

How about you try for something like "I limit strings to X characters because that is the width of my LCD."

Add in something like "and I always send a trailing zero" and you have the working of a spec you can write code against.
 

Thread Starter

varden

Joined Jul 11, 2016
38
I forget to mention actually I limited my string at 16 and messages never run over 16 character :D But I mean it can be 5 or 10 character.
I didn't try to send zero character at the end. I thought it adds it by itself automatically. Thanks I will try it.
 

ErnieM

Joined Apr 24, 2011
8,377
If by "it" you mean your Bluetooth terminal program that would depend on that program, so read the documentation carefully. It may instead be sending a carriage return/line feed combo, or some other symbol.

If there is an ASCII character you never use, such as an asterisk, you can insert that at the end of the string as you type it, then you look for that to determine the ending.
 
Top