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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

2,210 Views
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.

Labels (1)
Tags (4)
0 Kudos
Reply
4 Replies

1,551 Views
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,551 Views
nguyennhatminh
Contributor IV

Hi Mark,

Thank you for your reply,

I'll try it out.

Minh.

0 Kudos
Reply

1,551 Views
waqasbutt
Contributor II

Hello Nguyen,

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

Regards

Waqas Ehsan Butt

0 Kudos
Reply

1,551 Views
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 Kudos
Reply