Forum : ST7/STM8
Original Post
Post Information | Post |
---|---|
January 15, 2010 - 12:22am
|
The STM8S Firmware Library documentation for the command UART3_ReceiveData8() states that the return value for this function is a u8 in the function prototype, but lower down in the documentation its a u16. u8 UART3_ReceiveData8 ( void ) Returns the most recent received data by the UART3 peripheral. Full description: Returns the most recent received data by the UART3 peripheral. Return values: u16 Received Data Required preconditions: UART3_Cmd(ENABLE); In my function UART3_RX_IRQHandler(void) interrupt 21, if i write the following (below) for a STM8S207, the received_data variable does not always correctly get the expected value. u8 recevied_data = UART3_ReceiveData8(); Reading some UART example code, I found the following which works (clears the MSB) u8 recevied_data = UART3_ReceiveData8() & 0x7F; Why are we required to clear the MSB of the received data from the UART? Thanks for your help :) |
Hi Clive,
The following code:
UART3_ReceiveData8() & 0x7F
is here to mask out the most significant bit of the received character.This is probably because you set your communication properties as 7-bit wide data. If you configure it as 8-bit and no parity, you will not have to mask out the high bit.
WARNING: On the STM8 UART, the number of bits includes the parity bit! This means that if you configure the UART in 8-bit, ODD parity, you will actually have a 7-bit value out.
Regards,
Bruno