Comunicação UART usando NRF24le1 (Parte 10/14)

UART communication using NRF24le1 (Part 10/14)

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.

Visão geral da comunicação serial com módulo 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).

Imagem mostrando componentes usados ​​na comunicação serial com módulo NRF24LE1

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.

Imagem mostrando mensagem recebida no terminal virtual do PC do módulo NRF24LE1

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
#include"hal_delay.h" // header file containing delay functions
// Putchar repeated to print a string void putstring(char *s) { while(*s != 0) hal_uart_putchar(*s++); } // main function main void { P0DIR = 0xf0; // configure P03 as output and P04 as input; // Initialize the UART hal_uart_init(UART_BAUD_9K6); //Enable global interrupts EA = 1; // infinite loop while(1) { //Prints "Hello everyone" putstring("rnHello everyone!!rn") ; delay_ms(1000); // 1 second delay } }

###

Circuit diagrams

Circuit Diagram-NRF24LE1-Module-interface with PC over UART

Project video

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.