Uart and M16C

Hi, I'm trying to understand a part of a C-program written for the M16C. This part of code should send a string through the uart. The previous code builds the string (an unsigned char array) to be sent. It manipulates every byte, then put it into the array, and then sent it byte after byte in the for-loop.

[...] tmp = InfoToBeSent >> 8; //What does this mean?

tmp = tmp & 0x0F; if (tmp < 0x0A) // And this? { tmp = tmp + 0x30; // And this?? } else { tmp = tmp + 0x37; // And this?!? }

StringToBeSent[7] = tmp;

[...]

for (tmp = 0; tmp < 11; tmp++) { TX_PORT = StringToBeSent[x]; }

I can't catch the meaning of the 3 lines where I put a comment... Have you any idea? Thanks

Reply to
Luke Phoenix
Loading thread data ...

Have a look at the M16C Manual / UART section and the corresponding SFR description of the U0RB/U1RB UART RX SFR.

You will see the it is a 16 bit register and the upper byte contains a error status of the serial UART. Thus only the lower byte contains data.

For details about the masks applied refer the to M16C62 (i.e) User Manual page: 140

The high byte contains the following bits:

SUM Error sum flag ABT Arbitration lost detecting OER Overrun error flag FER Framing error flag PER Parity error flag

You may want to check the contents during reception to detect possible transmission errors and handle them accordingly.

As for the code supplied: It should be known what type 'tmp', 'InfoToBeSent' , 'StringToBeSent' be sent are. Seeing the right shift one may assume 16 bit. Why the upper byte is manipulated in such a way can only be specuated. Seemingly some information is coded and the (speculation again) 16 bit array String to be sent will be pushed out byte by byte through the UART.

What information exactly the coding shall contain can only be extracted from the code context of the rest of the module.

Please note: the M16C UART Transmit register can only transmit 8 bit type. The high byte may not be used.

grtnx /jan Luke Phoenix schrieb in im Newsbeitrag: snipped-for-privacy@posting.google.com...

Reply to
Jan Homuth

Thank you very much! Very clarifying!

Reply to
Paul Phoenix

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.