Hallo together,
at the moment I want to transfer a serial chain of ASCII-Strings with the LIN/UART-Controller from the MPC5604B Board. So i need a function, which changes characters from binary to ASCII, so yesterday I try to use the "sprintf" - function, but without success. (stdio.h is already included).
How can I solve this problem? Perhaps one of you has already a solution...?
Best Regards and marry Christmas (and a happy new year)
void binarytoascii(uint16_t innum) {
uint16_t j1,in;
uint8_t p1,p2;
in = innum;
j1 = (in & 0x0f);
if (j1 > 9) p1 = (uint8_t)(j1 + 0x41 - 10);
else p1 = (uint8_t)(j1 +0x30);
j1 = (in & 0xf0) >> 4;
if (j1 > 9) p2 = (uint8_t)(j1 +0x41 - 10);
else p2 = (uint8_t)(j1 +0x30);
//TransmitCharacter(0x0a);
// TransmitCharacter(0x0d);
TransmitCharacter(p2);
TransmitCharacter(p1);
}
where TransmitCharacter() function looks like as below
void TransmitCharacter(uint8_t ch)
{
LINFLEX_0.BDRL.B.DATA0 = ch; /* write character to transmit buffer */
while (1 != LINFLEX_0.UARTSR.B.DTF) {} /* Wait for data transmission completed flag */
LINFLEX_0.UARTSR.R = 0x0002; /* clear the DTF flag and not the other flags */
}
set the proper baud rate of LINFLEX_0.UART
no hint for me?
You could ask a programmer to write an binary to ASCII converter for you. It is such a basic task that even a beginner programmer should be able to succesfully help you out with it.
Hi Mikaza,
Could you perhaps post some code snippet to see how exactly you are using sprintf in this case.
Thanks.
Stanish