UART with NRF24LE1
In this modern world, we all know USB. We all connect our pen drives, memory cards and other devices using USB. But have you ever thought what that is? Here is the answer; USB is a communication protocol by which two devices communicate with each other. Similarly, the microcontroller also communicates with other devices like sensors or PC using different communication protocols like USB, UART and I2C.
Today our focus will be on using UART communication for NRF24LE1.
Figure 1: Overview of serial communication with NRF24LE1 module
UART stands for Universal Asynchronous Receiver/Transmitter. It is a type of serial communication that uses two wires, one for transmission (Tx) and the other for reception (Rx). It uses start and stop bits in the packet to indicate the beginning and end of the packet. We also have the option of using parity bits within the data to indicate an error in the transmitted data. Before using UART we have to declare the transmission and reception speed known as baud rate. The most common baud rate is 9600 bps (bits per second).
Fig. 2: Image showing components used in serial communication with NRF24LE1 Module
The NRF module offers a range of baud rates from 600 bps to 38,400 bps. NRF P0.3 pin is Tx and P0.4 pin is Rx.
For more features, you can refer to the datasheet. Also, you can refer to our previous articles on UART with PC and NRF24LE1 for more help.
We will be using the nrfsdk (software development kit) provided by Nordic Semiconductors Ltd. Communication will be established between the NRF and the PC by sending “Hello” to the PC.
Functions that are useful for using UART are:
· hal_uart_init – This function uses the baud rate.
· hal_uart_tx_complete – Checks the completion of the transmission.
· Hal_uart_putchar – This function takes characters for transmission.
· hal_uart_chars_available – Checks whether a character was received or not.
· hal_uart_getchar – Returns the received character.
The description of the various functions is:
FUNCTION | INPUT PARAMETER | EXIT |
DESCRIPTION
|
---|---|---|---|
hal_uart_init |
UART_BAUD_600 UART_BAUD_1K2 UART_BAUD_2K4 UART_BAUD_4K8 UART_BAUD_9K6 UART_BAUD_19K2 UART_BAUD_38K4 UART_BAUD_57K6 UART_BAUD_115K2 |
– |
To initialize UART communication by selecting the baud rate |
hal_uart_putchar | 8-bit character | – | To transmit 8-bit characters |
hal_uart_tx_complete | – | 0/1 |
To check the transmission status 0: Transmitting 1:Transmitted |
hal_uart_char_available | – | 8-bit number | To get the number of characters received |
hal_uart_getchar | – | 8-bit character | To read the received 8-bit character |
Please check the commented code for the complete implementation of these functions to get a clear understanding.
Figure 3: Image showing message received on the virtual terminal of the NRF24LE1 Module PC
Project source code
###
//Program to
#include"reg24le1.h" // I/O header file for NRF24LE1
#include"hal_uart.h" // library containing serial communication functions
###
Circuit diagrams
Circuit Diagram-NRF24LE1-Module-interface with PC over UART |