O'Reilly logo

Embedded Systems Architecture by Daniele Lacamera

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Receiving data

To enable the receiver on the same UART, the initialization function should also turn on the receiver using the corresponding switch in the UART_CR1 register:

UART3_CR1 |= UART_CR1_TX_ENABLE | UART_CR1_RX_ENABLE;

This ensures that the receiving side of the transceiver is enabled too. To read data in polling mode, blocking until a character is received, we can use the following function, which will return the value of the byte read:

char uart3_read(void){    char c;    volatile uint32_t reg;    do {        reg = UART3_SR;    } while ((reg & UART_SR_RX_NOTEMPTY) == 0);    c = (char)(UART3_DR & 0xff);    return c;}

This way we can, for example, echo back to the console each character received from the host:

void main(void) {    char c[2]; flash_set_waitstates(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required