convert data 16 bit to 8 bit so as to use UART

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

convert data 16 bit to 8 bit so as to use UART

1,960 次查看
nguyennhatminh
Contributor IV

Hi Guys,

I'm working on KL05Z. I accomplished 12 bit ADC of temperature of MCU and now I wish to send the result to PC.

I used the 16 bit variant to content the result , when I try to cast (byte), for sending data ,the result become " #".

Do you know how to solve this problem ?

your reply will be highly appreciate ,

Thanks,

Minh.

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

1,301 次查看
mjbcswitzerland
Specialist V

Hi

Usually one would send the value as ASCII coded hex (for example)

0x1234 from ADC could be sent as "1234" (4 bytes on the UART).

If you simply cast to a byte you will lose 8 bits of the value. You could also send as 2 binary values rather than 1 (0x1234 -> 0x12 + 0x34)

Regards

Mark

1,301 次查看
nguyennhatminh
Contributor IV

Hi Mark,

Thank you for your reply,

I'll try it out.

Minh.

0 项奖励

1,301 次查看
waqasbutt
Contributor II

Hello Nguyen,

I can't understand your problem what do you mean by "the result becomes #"

Regards

Waqas Ehsan Butt

0 项奖励

1,301 次查看
nguyennhatminh
Contributor IV

Hi Waqas Butt,

uinit16_t Temp;

Temp=(25-(ADCR_temp-ADC_temp25)*100/ADC_m);

The result is in 16bit data. when I cast (byte) Temp. The result will be error , and I get " #" character.

MInh.

0 项奖励