Page 1 of 2

UART1_Read_text problem

Posted: 17 May 2013 00:18
by tibor385
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!

Re: UART1_Read_text problem

Posted: 17 May 2013 12:41
by marina.petrovic
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

Re: UART1_Read_text problem

Posted: 17 May 2013 14:47
by tibor385
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

Re: UART1_Read_text problem

Posted: 20 May 2013 01:44
by tibor385
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.

Re: UART1_Read_text problem

Posted: 20 May 2013 15:49
by marina.petrovic
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

Re: UART1_Read_text problem

Posted: 20 May 2013 21:07
by tibor385
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.

Re: UART1_Read_text problem

Posted: 21 May 2013 10:28
by marina.petrovic
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

Re: UART1_Read_text problem

Posted: 21 May 2013 14:36
by tibor385
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!

Re: UART1_Read_text problem

Posted: 21 May 2013 16:56
by tibor385
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?

Re: UART1_Read_text problem

Posted: 22 May 2013 10:43
by marina.petrovic
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

Re: UART1_Read_text problem

Posted: 22 May 2013 13:13
by tibor385
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!

Re: UART1_Read_text problem

Posted: 24 Jul 2013 15:29
by granel
I have this problem too (((
May be reinstal compiler?

Re: UART1_Read_text problem

Posted: 24 Jul 2013 16:32
by granel
reinstal --> nothing

Re: UART1_Read_text problem

Posted: 24 Jul 2013 16:40
by granel
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?

Re: UART1_Read_text problem

Posted: 25 Jul 2013 14:16
by marina.petrovic
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