Hi!
I already read some other posts about strcat and strcpy but I can't figure out why my string sent like this. The output should be:
"rpm:1234 mA:0213" but instead I got "rpm:1234 {4 bytes of LF or garbage} mA:0213"
Here is the code snippet:
void SendData()
{
volatile unsigned int TempDataInt = 0;
strcpy(&StrBuf[0], " ");
strcpy(&StrBuf[0], "rpm:");
TempDataInt = binToBCD((long unsigned int)Rpm);
DataBuf[3] = (TempDataInt & 0x000F) | 0x30; // u
TempDataInt >>= 4;
DataBuf[2] = (TempDataInt & 0x000F) | 0x30; // d
TempDataInt >>= 4;
DataBuf[1] = (TempDataInt & 0x000F) | 0x30; // c
TempDataInt >>= 4;
DataBuf[0] = (TempDataInt & 0x000F) | 0x30; // m
TempDataInt >>= 4;
strcat(&StrBuf[0], &DataBuf[0]);
strcat(&StrBuf[0], "mA:");
TempDataInt = binToBCD((long unsigned int)(Current*1000));
DataBuf[3] = (TempDataInt & 0x000F) | 0x30;
TempDataInt >>= 4;
DataBuf[2] = (TempDataInt & 0x000F) | 0x30;
TempDataInt >>= 4;
DataBuf[1] = (TempDataInt & 0x000F) | 0x30;
TempDataInt >>= 4;
DataBuf[0] = (TempDataInt & 0x000F) | 0x30;
TempDataInt >>= 4;
strcat(&StrBuf[0], &DataBuf[0]);
__no_operation();
for(r=0;r<strlen(&StrBuf[0]);r++)
{
UCA0TXBUF = StrBuf[r];
while(UCA0STAT & UCBUSY);
}
}