Send and Receive large arrays through UART

Thread Starter

namratha_r

Joined Jan 27, 2015
23
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:
unsigned char bitmap[104]= {
                              0x0000,0x0070,0x0000,0x0032,0x0081,0x003E,0x0011,0x000E,
                              0x0011,0x002E,0x0012,0x000D,0x0011,0x000E,0x0011,0x000E,
                              0x0011,0x000D,0x0012,0x000D,0x0011,0x000E,0x0011,0x000E,
                              0x0011,0x000D,0x0012,0x000D,0x0011,0x000E,0x0011,0x000E,
                              0x0011,0x002E,0x0011,0x000E,0x0011,0x000E,0x0011,0x000D,
                              0x0012,0x000D,0x0011,0x000E,0x0011,0x000E,0x0011,0x000D,
                              0x0011,0x000D,0x0011,0x000E,0x0011,0x002E,0x0011,0x000E,
                              0x0011,0x000E,0x0011,0x000E,0x0011,0x000D,0x0011,0x000D,
                              0x0011,0x000E,0x0011,0x000E,0x0011,0x000D,0x0011,0x002E,
                              0x0011,0x000E,0x0011,0x000D,0x0012,0x000D,0x0011,0x000E,
                              0x0011,0x002E,0x0012,0x000D,0x0011,0x000E,0x0011,0x002E,
                              0x0012,0x000D,0x0011,0x000E,0x0011,0x000E,0x0011,0x000D,
                              0x0012,0x002E,0x0011,0x000E,0x0011,0x002E,0x0011,0x0AB9
                            };



void SerialTransmit(unsigned char *buffer)
{
        while(U1STAbits.UTXBF);    // wait while TX buffer full
        for(i=0; i<104; i++)
        {
            U1TXREG = buffer[i];          // send single character to transmit buffer
        }
    while(!U1STAbits.TRMT);        // wait for last transmission to finish
}

char SerialReceive(unsigned char *buffer, unsigned int max_size)
{
    unsigned int i;
     while(!U1STAbits.URXDA);   // wait until data available in RX buffer
    for(i=0; i< max_size;i++)
    {      
      buffer[i] = U1RXREG;         
    }
    return (*buffer);
}
 

MrChips

Joined Oct 2, 2009
30,805
You have to test the UART flags on each character transmitted and received.

Code:
void SerialTransmit(unsigned char *buffer)
{
   unsigned int i;
   for(i=0; i<104; i++)
   {
      while(!U1STAbits.TRMT); // wait while TX is busy
      U1TXREG = buffer[i]; // send single character to transmit buffer
   }
}


void SerialReceive(unsigned char *buffer, unsigned int max_size)
{
  unsigned int i;
  for(i=0; i< max_size;i++)
  {
    while (!U1STAbits.URXDA); // wait until data available in RX buffer
    buffer[i] = U1RXREG;
  }
}
 

Thread Starter

namratha_r

Joined Jan 27, 2015
23
Code:
0x0000,0x0070,0x0000,0x0032,0x0081,0x003E,0x0011,0x000E,
                              0x0011,0x002E,0x0012,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
now its transmitting like this
 

MrChips

Joined Oct 2, 2009
30,805
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.
 
Top