MPC5604B: "sprintf(...)" is not possible

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MPC5604B: "sprintf(...)" is not possible

1,704 次查看
Mikaza
Contributor I

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)

标签 (1)
0 项奖励
回复
4 回复数

1,364 次查看
shri
Contributor II

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

0 项奖励
回复

1,364 次查看
Mikaza
Contributor I

no hint for me?

0 项奖励
回复

1,364 次查看
Lundin
Senior Contributor IV

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.

0 项奖励
回复

1,364 次查看
stanish
NXP Employee
NXP Employee

Hi Mikaza,

 

Could you perhaps post some code snippet to see how exactly you are using sprintf in this case.

 

Thanks.

Stanish

0 项奖励
回复