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.

CCS/RM42L432: Sending and receiving integers using Hercules SCI

Part Number: RM42L432

Tool/software: Code Composer Studio

I just wish to receive an integer from serial port, add 2 to the integer and send it back through serial communication 

Here is my sciNotification code,  

void sciNotification(sciBASE_t *sci , unsigned flags)
{


dat = dat + 2;
sciSend(sci,sizeof(dat),(int*)&(dat));
sciReceive(sci,sizeof(dat),(int*)&dat);

}

When i use CCS's inbuilt terminal to send a number on serial transfer, the output result is inverted, ie if I send 1111 as input through terminal, output is 3111, also i am not able to send integers with undefined number of digits in them. I was following this TI tutorial however its only deals with character communication over serial, not integers.   

  • Harjatin,

    One of the basic principles of embedded systems is that we work with binary and hex data only. The terminal window utility and more generally the PC applications usually work with ASCII data in their display routines. Also keep in mind that the RM42 device is little endian so you half to consider the proper order of bytes when working with ASCII or string data.

    If we consider the specific function you are performing, you are sending '1'-'1'-'1'-'1' across the SCI. This is 0x41, 0x41, 0x41, 0x41 in hex. where the first byte entered into the terminal window and sent will be the the first byte received so it will be the most dignificant digit. When you receive it, you add 2 for a new hex value of 0x43 which happens to be an ASCII 3, then you get the remaining ASCII values. I suppose, you then send them back out in the order you received them or '3'-'1'-'1'-'1'. In order to properly perform math on the incoming number represented as a string you would need to convert the string to a hex value, perform the math operation, then convert back to a string to send back out and be properly represented in the PC world.