UART1_Read_text problem
UART1_Read_text problem
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!
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!
- marina.petrovic
- Posts: 2986
- Joined: 18 Apr 2013 08:11
Re: UART1_Read_text problem
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
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
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
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.
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.
- marina.petrovic
- Posts: 2986
- Joined: 18 Apr 2013 08:11
Re: UART1_Read_text problem
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:
Best regards,
Marina
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
}
}
}
Marina
Re: UART1_Read_text problem
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.
- marina.petrovic
- Posts: 2986
- Joined: 18 Apr 2013 08:11
Re: UART1_Read_text problem
Hi,
Please, instead of:
Try to use:
Or some higher number for number of Attempts (defines number of received characters in which Delimiter sequence, "o", is expected).
Best regards,
Marina
Please, instead of:
Code: Select all
UART1_Read_Text(uart_rd, "o", 5);
Code: Select all
UART1_Read_Text(uart_rd, "o", 20);
Best regards,
Marina
Re: UART1_Read_text problem
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
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?
- marina.petrovic
- Posts: 2986
- Joined: 18 Apr 2013 08:11
Re: UART1_Read_text problem
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
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
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!
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
I have this problem too (((
May be reinstal compiler?
May be reinstal compiler?
Re: UART1_Read_text problem
I sent --> 0x31 0x32 0x33 0x34 0x45 0x0D 0x0Aif(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 received only 0x31 if route delimiter 0x32 or ox33,
if delimiter other --> 0x34 or 0x45 or 0x0D or 0x0A == nothig received ((
When my mistake?
- marina.petrovic
- Posts: 2986
- Joined: 18 Apr 2013 08:11
Re: UART1_Read_text problem
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
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