Hello,
I want to send float values via the serial port.
Consider the fallowing code:
void SendData(float a, float b, float c)
{
#define bufLen 16
uint16_t sendBuff[bufLen];
sendBuff[0] = SOM1;
sendBuff[1] = SOM2;
sendBuff[2] = 0x00;
GPIO_writePin(TEST_128, 0);
loadDataToArray(&sendBuff[ 3], a);
loadDataToArray(&sendBuff[ 7], b);
loadDataToArray(&sendBuff[11], c);
GPIO_writePin(TEST_128, 1);
sendBuff[bufLen - 1] = EOM;
SCI_writeCharArray(SCIA_BASE, sendBuff, bufLen);
}
void loadDataToArray(uint16_t * dest, float data)
{
int * ptr = &data;
dest[0] = *(ptr) & 0x00FF;
dest[1] = *(ptr) >> 8;
dest[2] = *(ptr + 1) & 0x00FF;
dest[3] = *(ptr + 1) >> 8;
}
this code takes about 140us to run.
Any suggestion on how to do this process more efiisiantly?
Thanks!