Send and Receive large arrays through UART

Discussion in 'Embedded Systems and Microcontrollers' started by namratha_r, May 15, 2015.

  1. namratha_r

    Thread Starter New Member

    Jan 27, 2015
    23
    0
    Hi...

    Am facing problem with UART am using PIC24FJ64GA104 and XC16 complier .
    I wanted to transmit large array and receive the same from UART but am receiving only junk datas please help me.
    This is the function am using for TX/RX and bitmap is the data .
    Code (Text):
    1. unsigned char bitmap[104]= {
    2.                               0x0000,0x0070,0x0000,0x0032,0x0081,0x003E,0x0011,0x000E,
    3.                               0x0011,0x002E,0x0012,0x000D,0x0011,0x000E,0x0011,0x000E,
    4.                               0x0011,0x000D,0x0012,0x000D,0x0011,0x000E,0x0011,0x000E,
    5.                               0x0011,0x000D,0x0012,0x000D,0x0011,0x000E,0x0011,0x000E,
    6.                               0x0011,0x002E,0x0011,0x000E,0x0011,0x000E,0x0011,0x000D,
    7.                               0x0012,0x000D,0x0011,0x000E,0x0011,0x000E,0x0011,0x000D,
    8.                               0x0011,0x000D,0x0011,0x000E,0x0011,0x002E,0x0011,0x000E,
    9.                               0x0011,0x000E,0x0011,0x000E,0x0011,0x000D,0x0011,0x000D,
    10.                               0x0011,0x000E,0x0011,0x000E,0x0011,0x000D,0x0011,0x002E,
    11.                               0x0011,0x000E,0x0011,0x000D,0x0012,0x000D,0x0011,0x000E,
    12.                               0x0011,0x002E,0x0012,0x000D,0x0011,0x000E,0x0011,0x002E,
    13.                               0x0012,0x000D,0x0011,0x000E,0x0011,0x000E,0x0011,0x000D,
    14.                               0x0012,0x002E,0x0011,0x000E,0x0011,0x002E,0x0011,0x0AB9
    15.                             };
    16.  
    17.  
    18.  
    19. void SerialTransmit(unsigned char *buffer)
    20. {
    21.         while(U1STAbits.UTXBF);    // wait while TX buffer full
    22.         for(i=0; i<104; i++)
    23.         {
    24.             U1TXREG = buffer[i];          // send single character to transmit buffer
    25.         }
    26.     while(!U1STAbits.TRMT);        // wait for last transmission to finish
    27. }
    28.  
    29. char SerialReceive(unsigned char *buffer, unsigned int max_size)
    30. {
    31.     unsigned int i;
    32.      while(!U1STAbits.URXDA);   // wait until data available in RX buffer
    33.     for(i=0; i< max_size;i++)
    34.     {      
    35.       buffer[i] = U1RXREG;        
    36.     }
    37.     return (*buffer);
    38. }
    39.  
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,432
    3,360
    You have to test the UART flags on each character transmitted and received.

    Code (Text):
    1.  
    2. void SerialTransmit(unsigned char *buffer)
    3. {
    4.    unsigned int i;
    5.    for(i=0; i<104; i++)
    6.    {
    7.       while(!U1STAbits.TRMT); // wait while TX is busy
    8.       U1TXREG = buffer[i]; // send single character to transmit buffer
    9.    }
    10. }
    11.  
    12.  
    13. void SerialReceive(unsigned char *buffer, unsigned int max_size)
    14. {
    15.   unsigned int i;
    16.   for(i=0; i< max_size;i++)
    17.   {
    18.     while (!U1STAbits.URXDA); // wait until data available in RX buffer
    19.     buffer[i] = U1RXREG;
    20.   }
    21. }
    22.  
     
  3. namratha_r

    Thread Starter New Member

    Jan 27, 2015
    23
    0
    Code (Text):
    1. 0x0000,0x0070,0x0000,0x0032,0x0081,0x003E,0x0011,0x000E,
    2.                               0x0011,0x002E,0x0012,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    now its transmitting like this
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,432
    3,360
    So what?
     
  5. namratha_r

    Thread Starter New Member

    Jan 27, 2015
    23
    0
    i mean its not transmitting whole data... its just transmitting only few elements in the array
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,432
    3,360
    To what device or instrument are you transmitting the data?
    How are you displaying the data? How do you know the data received is correct/incorrect?

    0x000D is the ASCII for CR.
     
    MaxHeadRoom likes this.
  7. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,518
    2,369
    Yes, and IIRC the first displayable Ascii char is = ! = (0x21).
    Max.
     
  8. namratha_r

    Thread Starter New Member

    Jan 27, 2015
    23
    0
    am checking through serial port..
     
Loading...