This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

EK-TM4C1294XL: Sending array of Data Bytes via UART

Part Number: EK-TM4C1294XL


Hello All,

I'am using TM4C1294 launchpad and I'am trying to send array of data to my thermal printer for printing. Is It Correct If I use the below command to send the data array using UART ?

for(i=0;i<10;i++)

{

UARTCharPut(UART2_BASE,data[i]);

}

When I send the same data using Arduino , it works like a charm! However When I try sending it with TM4C129 it does not work and prints some gibberish things!

I mentioned Arduino because Initially I test my peripherals using Arduino so that Iam sure that the peripheral works fine

In Arduino there is a function called Serial.write("data") which sends BYTES. I'am sure UARTCharPut(UART2_BASE,data) is equivalent to Arduino Serial.write() or is it NOT??

My arduino code is mentioned below which works fine

val = analogRead(analogPin);

mySensVals[i]=val;


i= i+1;

Serial.write(0xFE);
Serial.write(0x03);
Serial.write(0x01);
Serial.write(0x04);
Serial.write(0x03);
Serial.write(0x05);
Serial.write(0x02);
Serial.write(0x14);
Serial.write(0x06);
Serial.write(0x14);
Serial.write(0xFD);
Serial.write(0xFA);
Serial.write(240);

for(i=0;i<=239;i++)
{
Serial.write(mySensVals[i]);
}

Now my TM4C129 code is shown below which is not printing the same result as the Arduino code

uint8_t CH1therm[11]={0xFE,0x03,0x01,0x04,0x03,0x05,0x02,0x14,0x06,0x14,0xFD};
volatile int32_t CH1thermdata[240];

CH1thermdata[g]=ui32ADC0Value[0];

g=g+1;

if (g==240)
{
g=0;

for(i=0;i<=10;i++)
{
UARTCharPut(UART2_BASE,CH1therm[i]);
}
UARTCharPut(UART2_BASE,0xFA);
UARTCharPut(UART2_BASE,0xF0);


for(i=0;i<=239;i++)
{
UARTCharPut(UART2_BASE,CH1thermdata[i]);
}


}

Kindly suggest some solution for this!!

  • Sumit,

    Yes, UARTCharPut() sends a byte to the uart port for hardware controlled transferring.

    Do you have access to a PC Terminal or Logic Analyzer to visualize the data that is sent? If so:
    - Can you tell if the first sequence (the "fixed" one with 11 bytes) is being sent properly?
    - What do you expect on the ADC converted sequence? You are reading 240 bytes of analog conversion, but you don't show how that was captured... did you first create a manually array with 240 know values to test the output? Can you see that those manually created bytes get sent?

    Also, you don't show the uart configuration. Are you using the proper baud rate, system clock, length, parity, etc?
    Are you properly connecting your printer to UART2 port? Did you configure the GPIO's?
    Does your printer accept TTL at the Tiva's 3.3V level? Or is there a proper RS232 shifter between them?

    Bruno
  • This is rather confused and contradictory.

    Here

    Sumit Mourya said:
    In Arduino there is a function called Serial.write("data") which sends BYTES.

    You suggest Serial.Write sends a string

    And here

    Sumit Mourya said:
    Serial.write(0xFE);

    You suggest it sends a single byte.

    Any chance you are using a set C++ overloaded functions? If so then they are not the same as UARTCHARPut. If no, then something is wrong (or at least missing) in your explanation.

    Robert

  • Hi Bruno,

    Thanks for giving me suggestions for debugging the problem!! It actually helped me in realizing the problem.There was nothing wrong in the code!!

    The problem was I Was repeating the code in while(1) loop which was confusing the printer and it was printing garbage. Instead I moved all the printing code in a function and used the user switch(PJ0) to call the function to print. Basically I had to send all the data to printer only once to print.

  • Hi Robert,

    It was a typo mistake.
    I should have written Serial.write(data) instead!!
    Anyways my problem was solved. Thanks for replying