Got stuck after reading text data using UART1_Read_Text() function

Cross-platform IDE for the rapid development of applications for the embedded world, available on Windows, Linux, and macOS.
Post Reply
Author
Message
kumar123
Posts: 77
Joined: 17 Oct 2023 07:32

Got stuck after reading text data using UART1_Read_Text() function

#1 Post by kumar123 » 07 May 2024 08:10

Hi,
I have this code written by me when I tried to read text data it get stuck, I tried my best to solve this issues still I did not get any solution.
Now I am trying to add interrupt but I don't know how to add interrupt in this code. Although it is working well with single one bytes data.
The MCU I have pc18f67k40. The IDE I am using mikroC pro for pic.
I asked this question many times but mikroE guys did't try to solve this issue.

Code: Select all

void main(){
   char uart_input[10], uart_output[10] = "0";
   TRISC7_bit = 1; // RX1 as input
   TRISC6_bit = 0; // TX1 as output

   UART1_Init(9600);
   Delay_ms(100);

   RC1IE_bit = 1; // Enable UART receive interrupt
   PEIE_bit = 1;  // Enable peripheral interrupts
   GIE_bit =  1;  // Enable global interrupts

   while(1){
        if(UART1_Data_Ready() == 1){
            UART1_Read_Text(uart_input, ";", 9);
            UART1_Write_Text(uart_input);
            strcpy(uart_output, uart_input);
        }
        else{
           UART1_Write_Text(uart_output);
        }
      UART1_Write_Text("\r\n");
      Delay_ms(1000);
   }
}
Regards
Kumar

sgssn
Posts: 35
Joined: 13 Sep 2021 16:24

Re: Got stuck after reading text data using UART1_Read_Text() function

#2 Post by sgssn » 07 May 2024 11:43

Hi
i am not shure, what you mean with "Although it is working well with single one bytes data." What is working, and what does not?
You can read single byte data or you can write single byte data, or both?

Gerhard

kumar123
Posts: 77
Joined: 17 Oct 2023 07:32

Re: Got stuck after reading text data using UART1_Read_Text() function

#3 Post by kumar123 » 08 May 2024 05:26

Hi sgssn,
Have you try to run once?
let me explain if I send 1; , 2; , 3; , ..... till 9; it will work perfect. when I tried to send 12; , 34; 10; etc it got stuck.

To understand the code just dry run once after dry run tried to run on the machine you must get that issue.

Regards,
Kumar

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: Got stuck after reading text data using UART1_Read_Text() function

#4 Post by AntiMember » 08 May 2024 06:58

Try it UART1_Read_Text(uart_input, ";", 255);
Or don't use UART1_Read_Text, use

Code: Select all

     if (UART1_Data_Ready()) { // If data is received,
       uart_input[i] = UART1_Read(); // read the received data
       if(uart_input[i] == delimiter)
         { ............}
       i++;
      if(i > attempts) 
         {................}
     }
Or wait for a response from mikroe...

Added... One week later...
Everyone asks... Nobody answers... It's fun. 8)

Post Reply

Return to “IDE”