UART1_Read_text problem

General discussion on mikroC PRO for AVR.
Author
Message
granel
Posts: 142
Joined: 13 Feb 2007 11:01

Re: UART1_Read_text problem

#16 Post by granel » 25 Jul 2013 17:19

hello, Marina
using ATmega16 - 14,745600 MHz
Sending to ATmega hex code, for example -- 20 21 22 23 24 25 26 27 28 29 30 0D 0A

Using C code -- UART_Read_Text(uart_rd_txt, "0", 13);
UART_Write_Text(uart_rd_txt);
Receive -- with errors --> 20 21 22 23 24 25 26 27 28 29
0D 0A 20 21 22 23 24 25 26 27 28 29
0D 0A 20 21 22 23 24 25 26 27 28 29
0D 0A 20 21 22 23 24 25 26 27 28 29
0D 0A 20 21 22 23 24 25 26 27 28 29
..................


Using C code -- UART_Read_Text(uart_rd_txt, 0x30, 13);
UART1_Write_Text(uart_rd_txt);
Receive -- bad code --> 49 6E 96 74 0D 0A
49 6E 96 74 0D 0A
49 6E 96 74 0D 0A
49 6E 96 74 0D 0A
............

Using C code -- UART_Read_Text(uart_rd_txt, 48, 13);
UART_Write_Text(uart_rd_txt);
Receive --bad code --> 49 6E 96 74 0D 0A
49 6E 96 74 0D 0A
49 6E 96 74 0D 0A
........
/*at code start have:
UART_Write_Text("Init");
UART_Write(13); //0x0D
UART_Write(10); //0x0A
*/

//48 -- 0x30 -- "0"
this code like black box :(((((
UART_Read_Text(x, y, z);
I tried it all day :(((((

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: UART1_Read_text problem

#17 Post by marina.petrovic » 26 Jul 2013 13:21

Hi,

When you take a look at help file (UART Library) - UART_Read_Text() function you will see that delimiter need to be
sequence of characters that identifies the end of a received string.

In the firs example when you use delimiter = "0", you have errors in code because you send "0" in some moment,
but USART Terminal "see" that character as delimiter.

I tried to send: 21 22 23 24 25 26 27 28 29 30 0D 0A

And use letter M as delimiter:
UART1_Read_Text(uart_rd_txt, "M", 40);
UART1_Write_Text(uart_rd_txt);

Result is correct: 21 22 23 24 25 26 27 28 29 30 0D 0A

Best regards,
Marina

granel
Posts: 142
Joined: 13 Feb 2007 11:01

Re: UART1_Read_text problem

#18 Post by granel » 26 Jul 2013 14:01

Thank you , will try.

granel
Posts: 142
Joined: 13 Feb 2007 11:01

Re: UART1_Read_text problem

#19 Post by granel » 26 Jul 2013 14:05

can I use like delimiter --> "M" or 0x4D or 77 (dec.) ?

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: UART1_Read_text problem

#20 Post by marina.petrovic » 26 Jul 2013 15:39

Hi,

I said "M" for no particular reason, just thought that you can try to use some letter or a word ("OK") that you don't send.

Delimiter must be sequence of characters (with zero terminating character) and you can use any sequence that you want.

Best regards,
Marina

Post Reply

Return to “mikroC PRO for AVR General”