UART1_Read_text problem

General discussion on mikroC PRO for AVR.
Author
Message
tibor385
Posts: 7
Joined: 17 May 2013 00:05

UART1_Read_text problem

#1 Post by tibor385 » 17 May 2013 00:18

Hello!
I have a problem with the function UART1_Read_Text(start, "o", 5); in my code. I use this function to receive data from serial port. The problem is I have to send character by character in order that the function work.
For example, I use the USART terminal from MikroC and i MUST enable the option "send as typing" and then type character by character. If i don't enable "send as typing", the microcontroller wont receive anything. Is it possible to receive several bytes at once, so i don't have to send character by character?
Thank you for your response!

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

Re: UART1_Read_text problem

#2 Post by marina.petrovic » 17 May 2013 12:41

Hi,

UART1_Read_Text(), reads characters received via UART until the delimiter sequence is detected (in your case: "o").
When you type something that you wont to send, simple press "Send", and it should work.

Check did you maybe enable "Append new line" (add new line after sending text)?

Best regards,
Marina

tibor385
Posts: 7
Joined: 17 May 2013 00:05

Re: UART1_Read_text problem

#3 Post by tibor385 » 17 May 2013 14:47

I tried with and without append new line. The problem is if I send several characters at once, the microcontroller won't read them.For example, I enable the send as typing, and type: "abco" the microcontroller will read "abc" which is fine. If I don't use "send as typing", I type: "abco" and click "send", the microcontroller won't read any of them. I dont know what the problem is. I use an ATMEGA16

tibor385
Posts: 7
Joined: 17 May 2013 00:05

Re: UART1_Read_text problem

#4 Post by tibor385 » 20 May 2013 01:44

I know how the function should work. i tried with and without "append new line". the problem is that the microcontrller won't recieve several characters if they are sent at the same time.
for example: I type "abco" and click send and the microcontroler wont read anything. But if I enable send as typing option and type "a b c o" {without space and quotes} the microcontroller will read "abc". Now I am developing a VB program,and the problem is again the same. If I want to send data from PC to microcontroller I must send them byte per byte with a delay of 150ms in between. I really don't know what the problem is. I also tried several baudrates,but its always the same problem.

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

Re: UART1_Read_text problem

#5 Post by marina.petrovic » 20 May 2013 15:49

Hi,

I can not reproduce the problem that you have. I tried to use the same function UART1_Read_Text(uart_rd, "o", 5);
and everything works as it should.

Please, can you try this simple code, to see if it works properly:

Code: Select all

char uart_rd[15];

void main() {
  UART1_Init(9600);                   // Initialize UART module at 9600 bps
  Delay_ms(100);                      // Wait for UART module to stabilize
  
  UART1_Write_Text("Init");
  UART1_Write(13);
  UART1_Write(10);
  
  while (1) {                                     // Endless loop
   if (UART1_Data_Ready()) {              // If data is received,
     UART1_Read_Text(uart_rd, "o", 5); // Read text until "o" appears
     UART1_Write_text(uart_rd);          // and send data via UART
    }
  }
}
Best regards,
Marina

tibor385
Posts: 7
Joined: 17 May 2013 00:05

Re: UART1_Read_text problem

#6 Post by tibor385 » 20 May 2013 21:07

I tried,but it's not working well. I disabled "send as typing" option. I tried to send "1234o", but the microcontroler only returns "12". No matter what I send,he returns only the first 2 bytes. It works well if I enable the "send as typing" option. I tried it using my regular serial port and an USB UART adapter, but the results are the same. I really have no idea why it isn't working.

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

Re: UART1_Read_text problem

#7 Post by marina.petrovic » 21 May 2013 10:28

Hi,

Please, instead of:

Code: Select all

UART1_Read_Text(uart_rd, "o", 5);
Try to use:

Code: Select all

UART1_Read_Text(uart_rd, "o", 20);
Or some higher number for number of Attempts (defines number of received characters in which Delimiter sequence, "o", is expected).

Best regards,
Marina

tibor385
Posts: 7
Joined: 17 May 2013 00:05

Re: UART1_Read_text problem

#8 Post by tibor385 » 21 May 2013 14:36

I tried already, but it's the same. I will buy a new microcontroler today. Maybe it is faulty. I will let you know if it works in few hours. Thank you for your replies!

tibor385
Posts: 7
Joined: 17 May 2013 00:05

Re: UART1_Read_text problem

#9 Post by tibor385 » 21 May 2013 16:56

I just bought a new ATMEGA32 (it has the same pinout as ATMEGA16), but the problem is still the same. Have you any suggestion how to fix that?

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

Re: UART1_Read_text problem

#10 Post by marina.petrovic » 22 May 2013 10:43

Hi,

Please, if you can, send me a screen shot of your USART Terminal, where I can see the problem?

I really can not determine the source of the error.
I tried the code on my system (with ATMEGA32) and everything works as expected.

Best regards,
Marina

tibor385
Posts: 7
Joined: 17 May 2013 00:05

Re: UART1_Read_text problem

#11 Post by tibor385 » 22 May 2013 13:13

Hello!
It finally started working. I reinstalled MikroC and put a new oscillator and now its working nice. Thank you for your time and replies!

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

Re: UART1_Read_text problem

#12 Post by granel » 24 Jul 2013 15:29

I have this problem too (((
May be reinstal compiler?

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

Re: UART1_Read_text problem

#13 Post by granel » 24 Jul 2013 16:32

reinstal --> nothing

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

Re: UART1_Read_text problem

#14 Post by granel » 24 Jul 2013 16:40

if(UART_Data_Ready())
{
UART_Read_Text(uart_rd_txt, 0x45, 15);
if(uart_rd_txt[0]==0x31)
{
UART_Write(0x31);
if(uart_rd_txt[1]==0x32)
{ UART_Write(0x32);
if(uart_rd_txt[2]==0x33)
{ UART_Write(0x33);
if(uart_rd_txt[3]==0x34)
{
UART_Write_Text(uart_rd_txt);
}
}
}
}
I sent --> 0x31 0x32 0x33 0x34 0x45 0x0D 0x0A
I received only 0x31 if route delimiter 0x32 or ox33,
if delimiter other --> 0x34 or 0x45 or 0x0D or 0x0A == nothig received :(((
When my mistake?

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

Re: UART1_Read_text problem

#15 Post by marina.petrovic » 25 Jul 2013 14:16

Hi,

Please, can you explain me a little bit more what your code should do so i can try to help you?
Also, can you tell me which microcontroller you use?

Best regards,
Marina

Post Reply

Return to “mikroC PRO for AVR General”