Libstock
It is currently 26 Oct 2014 03:53

All times are UTC + 1 hour




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: UART1_Read_text problem
PostPosted: 17 May 2013 00:18 
Offline

Joined: 17 May 2013 00:05
Posts: 7
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!


Top
 Profile  
 
PostPosted: 17 May 2013 12:41 
Offline
User avatar

Joined: 18 Apr 2013 08:11
Posts: 2318
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


Top
 Profile  
 
PostPosted: 17 May 2013 14:47 
Offline

Joined: 17 May 2013 00:05
Posts: 7
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


Top
 Profile  
 
PostPosted: 20 May 2013 01:44 
Offline

Joined: 17 May 2013 00:05
Posts: 7
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.


Top
 Profile  
 
PostPosted: 20 May 2013 15:49 
Offline
User avatar

Joined: 18 Apr 2013 08:11
Posts: 2318
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:

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


Top
 Profile  
 
PostPosted: 20 May 2013 21:07 
Offline

Joined: 17 May 2013 00:05
Posts: 7
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.


Top
 Profile  
 
PostPosted: 21 May 2013 10:28 
Offline
User avatar

Joined: 18 Apr 2013 08:11
Posts: 2318
Hi,

Please, instead of:

UART1_Read_Text(uart_rd, "o", 5);


Try to use:

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


Top
 Profile  
 
PostPosted: 21 May 2013 14:36 
Offline

Joined: 17 May 2013 00:05
Posts: 7
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!


Top
 Profile  
 
PostPosted: 21 May 2013 16:56 
Offline

Joined: 17 May 2013 00:05
Posts: 7
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?


Top
 Profile  
 
PostPosted: 22 May 2013 10:43 
Offline
User avatar

Joined: 18 Apr 2013 08:11
Posts: 2318
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


Top
 Profile  
 
PostPosted: 22 May 2013 13:13 
Offline

Joined: 17 May 2013 00:05
Posts: 7
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!


Top
 Profile  
 
PostPosted: 24 Jul 2013 15:29 
Offline

Joined: 13 Feb 2007 11:01
Posts: 90
I have this problem too (((
May be reinstal compiler?


Top
 Profile  
 
PostPosted: 24 Jul 2013 16:32 
Offline

Joined: 13 Feb 2007 11:01
Posts: 90
reinstal --> nothing


Top
 Profile  
 
PostPosted: 24 Jul 2013 16:40 
Offline

Joined: 13 Feb 2007 11:01
Posts: 90
Quote:
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?


Top
 Profile  
 
PostPosted: 25 Jul 2013 14:16 
Offline
User avatar

Joined: 18 Apr 2013 08:11
Posts: 2318
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group