# UART - poll

Source: [https://docs.qualcomm.com/doc/80-58740-4/topic/uart-poll.html](https://docs.qualcomm.com/doc/80-58740-4/topic/uart-poll.html)

This demo mainly demonstrates the UART polling mode sending and receiving function.

## Hardware connection

- Chip UART Tx pin connected to USB2TTL module Rx
- Chip UART Rx pin connected to USB2TTL module Tx

The GPIO used in this demo is as follows:

| Signal | Chip | GPIO |
| --- | --- | --- |
| UART1\_TX | QCC743 | GPIO 23 |
| UART1\_RX | QCC743 | GPIO 24 |

## Software implementation

For specific software code, see
                    examples/peripherals/uart/uart\_poll.

    board_init();Copy to clipboard

- `board_init` turns on the UART IP clock and select the UART
                        clock source and frequency division.

    board_uartx_gpio_init();Copy to clipboard

- Configure the relevant pins as `UARTx TX` and `UARTx
                            RX` functions. By default, the demo uses the UART1
                        peripheral.

    uartx = qcc74x_device_get_by_name(DEFAULT_TEST_UART);
    
    struct qcc74x_uart_config_s cfg;
    
    cfg.baudrate = 2000000;
    cfg.data_bits = UART_DATA_BITS_8;
    cfg.stop_bits = UART_STOP_BITS_1;
    cfg.parity = UART_PARITY_NONE;
    cfg.flow_ctrl = 0;
    cfg.tx_fifo_threshold = 7;
    cfg.rx_fifo_threshold = 7;
    qcc74x_uart_init(uartx, &cfg);Copy to clipboard

- Get the `DEFAULT_TEST_UART` handle and initialize the UART

    int ch;
    while (1) {
        ch = qcc74x_uart_getchar(uartx);
        if (ch != -1) {
            qcc74x_uart_putchar(uartx, ch);
        }
    }Copy to clipboard

- Call `qcc74x_uart_getchar` to read data from UART RxFIFO. If
                        -1 is returned, it means that there is no data.
- Call `qcc74x_uart_putchar` to fill data `ch`
                        into UART TxFIFO

## Experimental phenomena

Connect the UART1 Tx, Rx, and GND pins to the USB2TTL module Rx, Tx, and GND
                respectively, and press the reset button. Use the serial port to send
                    `0123456789` to UART1, and the USB2TTL module can receive the
                same data.

**Parent Topic:** [UART](https://docs.qualcomm.com/doc/80-58740-4/topic/uart.html)

Last Published: Feb 10, 2025

[Previous Topic
UART](https://docs.qualcomm.com/bundle/publicresource/80-58740-4/topics/uart.md) [Next Topic
UART - dma](https://docs.qualcomm.com/bundle/publicresource/80-58740-4/topics/uart-dma.md)