Embedded Lesson 006: UART Input - Summary


#1

Today we will be looking at getting input from the UART module. The code is an extension from Lesson 005.

We will need an additional buffer as well as an index pointer to the current location within the buffer, and finally an additional flag for when reception of data is complete.

In our callback function, we will also need to handle the new event for when a UART character is received. Initially it would seem that the event UART_EVENT_RX_COMPLETE would be the correct choice, but this event only occurs when we use a transfer instance (see 11.1.316.7 in the Renesas Synergy Software Package User Manual for additional details).

Instead of the UART_EVENT_RX_COMPLETE event, we will be handling the UART_EVENT_RX_CHAR which is called when a character is received on the UART device.

Inside the callback function, we will place the received character in the buffer and advance the buffer index. If a new line or carriage return character is received or if an overflow occurs, we will set the receive flag to true.

/* HAL-only entry function */
#include "hal_data.h"

#include 
#include 
#include 

// Buffer Sizes
#define OUTPUT_BUFFER_SIZE 1024
#define INPUT_BUFFER_SIZE 1024

// Buffers
char outputBuffer[OUTPUT_BUFFER_SIZE];
char inputBuffer[INPUT_BUFFER_SIZE];

volatile int inputBufferIndex;

Read Full Article