Hello All,
I have a bit of a strange one here and I just can't seem to find a solution. I use sprintf() to format strings which I then send out a SCI port a little later. My problem is one particular string that I build has an incorrect number in it after sprintf() is complete.
typedef struct MOT_PARAM{...unsigned int BaudRate; //Baudrate setting between Main and Interface PCB...}mot_param;mot_param UA_Param;unsigned char debug_buf[64];size = sprintf((char *)debug_buf, "SB%d\r", (unsigned)UA_Param.BaudRate);
So here is the issue:
if UA_Param.BaudRate = 4800 or 9600 or 19200 then he string created is always correct i.e.
SB4800\r
SB9600\r
SB19200\r
However when UA_Param.BaudRate is greater than 19200 (such as 38400, 57600 & 115200) then the output string has the negative value of the Baudrate i.e.
So if UA_Param.BaudRate = 38400 i get SB-27136\r but it should be SB38400\r
What I cannot figure out is why any number larger than 19200 is being converted incorrectly. Does anyone have any ideas?
Details:
Target CPU - DSC56F8323
Codewarrior 8.1.1a for the DSC56F8000E
My Desktop OS - Win XP SP3
Thanks in advance for any help.