Page 1 of 1

Send Interger data over UART1_Write_Text

Posted: 11 Dec 2023 11:31
by kumar123
Hi,
I am trying to send integer data over uart from 1 to 65535, for every integer taking delay of 1 second. I am getting data from 1 to 260 without given any delay, if i introduce delay of 1 second, I only received 1,2,3 integer as output.


Code: Select all

unsigned Uart1_Intout_ReturnInt(unsigned long int i) {
   char puf[8]; //for max 5 digits and the end-sign

   WordToStr(i, puf); // in "Conversions" library
   UART1_Write_Text(puf);
   Delay_ms(1000);
   UART1_Write(10);
   UART1_Write(13);
   return i;
}



void main() {
    unsigned y, result;
    unsigned long int counter=1;;

    UART1_Init(9600);  //9600
    Delay_ms(10);
    y = 1;
    
    result = Uart1_Intout_ReturnInt(y);   // "  999"
    while(counter <=65535){
      Uart1_Intout_ReturnInt(1 + counter);   // " 1000"
      counter++;
      if(counter == 65536){
            counter = 1;
       }
       
    }

}





Regards,
Kumar

Re: Send Interger data over UART1_Write_Text

Posted: 12 Dec 2023 00:36
by hexreader
You need to turn off watchdog timer in project configuration bits

Re: Send Interger data over UART1_Write_Text

Posted: 01 Feb 2024 10:04
by kumar123
Hi hexreader,

I want output of this below code like- initially it print the whatever have the initial value, it will keep on printing until I entered the new integer, again it will keep on printing(old value ) value until I entered the new value and so on.
This below code works well for single digit Integer(0-9), when I read integer greater than 10, first time it get stuck, second time I read same value it print wrong value.

Code: Select all

void main(){
     char str[256] = "0";
     char st[256];
     TRISC6_bit = 0;   // Tx pin set as output
     TRISC7_bit = 1;   // Rx pin set as input

     UART1_Init(9600); // Initialize the UART with a baud rate of 9600

     Delay_ms(4);     //Wait for UART to stabilize

     while(1){
     
        if(UART1_Data_Ready() == 1){
            UART1_Read_Text(st, ";", 255);
            UART1_Write_Text(st);
             strcpy(str,st);
            UART1_Write_Text("\r\n");
            Delay_ms(1000);

        }
        else{
            UART1_Write_Text(str);
            UART1_Write_Text("\r\n");
            Delay_ms(1000);
        }
     }
 }
This is when I am reading single digit integer and printing the same:
screa1.png
screa1.png (207.33 KiB) Viewed 489 times
This is when first time I am reading integer greater than 10 and try to print, but it get stuck
scr2.png
scr2.png (204.46 KiB) Viewed 489 times
This is when second time enter the same integer get gives wrong value:
sc3.png
sc3.png (204.52 KiB) Viewed 489 times
Hope you understood the problem.

Regards,
Kumar

Re: Send Interger data over UART1_Write_Text

Posted: 04 Feb 2024 18:03
by Thomas.Pahl@t-online.de
You should decide if you want to send the number as text or as number.

If you want to send as text (you use uart_write_text) then you have to convert the integer into a string with IntToStr function.
And on the receiver side should convert it back (with StrToInt function).

If you want to send the integer as number. split it into two bytes with hi(integer) and lo(integer) and send them one after the other (with uart_write) over the interface.
On the receiver side receive the two bytes and put them together.

greetings

Re: Send Interger data over UART1_Write_Text

Posted: 09 Feb 2024 06:37
by kumar123
Hi,
I had tried whatever you suggest, still it was not working .

Is there any suggestions?

Regards,
Kumar

Re: Send Interger data over UART1_Write_Text

Posted: 14 Feb 2024 06:02
by kumar123
Hi,

Does anyone have suggestions for the above query?

Regards,
Kumar