Beginner
10 min

Achieve unparalleled control over your data flow with 74HC4066D and ATmega324PA

Seamless UART switching: Your data, your way!

UART MUX 4 Click with EasyAVR v8

Published Jul 11, 2024

Click board™

UART MUX 4 Click

Dev. board

EasyAVR v8

Compiler

NECTO Studio

MCU

ATmega324PA

Empower your projects with dynamic UART control – our solution lets you redirect your data flow on the fly, offering a new level of adaptability to suit your project’s communication demands.

A

A

Hardware Overview

How does it work?

UART MUX 4 Click is based on the 74HC4066D, a quad single-pole, single-throw analog switch from Nexperia. The CMOS level inputs of the 74HC4066D include clamp diodes, which in turn allow the use of current limiting resistors to interface inputs to voltages exceeding VCC. This Click board™ has two multiplexed 4-pin UART headers labeled UART1 and UART2. The UART header lines are labeled for corresponding pins. It

offers fast switching speeds with a turn-off time of 13ns and 11ns for turn-on if powered with 5V. The UART MUX 2 Click uses a standard UART interface to communicate with the host MCU, with commonly used RX and TX lines. To switch between the two output UART interfaces, this Click board™ features a switch in the form of an NPN transistor circuit. This switch circuit allows the use of one of the outputs UART interfaces via the

SW pin of the mikroBUS™ socket with a simple logic state. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Also, this Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used as a reference for further development.

UART MUX 4 Click hardware overview image

Features overview

Development board

EasyAVR v8 is a development board designed to rapidly develop embedded applications based on 8-bit AVR microcontrollers (MCUs). Redesigned from the ground up, EasyAVR v8 offers a familiar set of standard features, as well as some new and unique features standard for the 8th generation of development boards: programming and debugging over the WiFi network, connectivity provided by USB-C connectors, support for a wide range of different MCUs, and more. The development board is designed so that the developer has everything that might be needed for the application development, following the Swiss Army knife concept: a highly advanced programmer/debugger module, a reliable power supply module, and a USB-UART connectivity option. EasyAVR v8 board offers several different DIP sockets, covering a wide range of 8-bit AVR MCUs, from the smallest

AVR MCU devices with only eight pins, all the way up to 40-pin "giants". The development board supports the well-established mikroBUS™ connectivity standard, offering five mikroBUS™ sockets, allowing access to a huge base of Click boards™. EasyAVR v8 offers two display options, allowing even the basic 8-bit AVR MCU devices to utilize them and display graphical or textual content. One of them is the 1x20 graphical display connector, compatible with the familiar Graphical Liquid Crystal Display (GLCD) based on the KS108 (or compatible) display driver, and EasyTFT board that contains TFT Color Display MI0283QT-9A, which is driven by ILI9341 display controller, capable of showing advanced graphical content. The other option is the 2x16 character LCD module, a four-bit display module with an embedded character-based display controller. It

requires minimal processing power from the host MCU for its operation. There is a wide range of useful interactive options at the disposal: high-quality buttons with selectable press levels, LEDs, pull-up/pulldown DIP switches, and more. All these features are packed on a single development board, which uses innovative manufacturing technologies, delivering a fluid and immersive working experience. The EasyAVR v8 development board is also integral to the MIKROE rapid development ecosystem. Natively supported by the MIKROE Software toolchain, backed up by hundreds of different Click board™ designs with their number growing daily, it covers many different prototyping and development aspects, thus saving precious development time.

EasyAVR v8 horizontal image

Microcontroller Overview

MCU Card / MCU

ATmega324PA

Architecture

AVR

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

2048

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
UART Output Switch
PA4
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
UART TX
PD1
TX
UART RX
PD0
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

UART MUX 4 Click Schematic schematic

Step by step

Project assembly

EasyAVR v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyAVR v8 as your development board.

EasyAVR v8 front image hardware assembly
Stepper 24 Click front image hardware assembly
MCU DIP 40 hardware assembly
Stepper 24 Click complete accessories setup image hardware assembly
EasyAVR v8 Access DIP MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
EasyPIC PRO v7a Display Selection Necto Step hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for UART MUX 4 Click driver.

Key functions:

  • uartmux4_enable_uart1 - UART MUX 4 enable the UART 1 function.

  • uartmux4_enable_uart2 - UART MUX 4 enable the UART 2 function.

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * @file main.c
 * @brief UART MUX 4 Click Example.
 *
 * # Description
 * This example demonstrates the use of UART MUX 4 click board by processing
 * the incoming data and displaying them on the USB UART.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the UART driver and additional pins.
 *
 * ## Application Task
 * Writes demo message, echos it back, processes all incoming data 
 * and displays them on the USB UART.
 *
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "uartmux4.h"

#define PROCESS_BUFFER_SIZE 200
#define DEMO_MESSAGE "\r\nMikroE\r\n"

static uartmux4_t uartmux4;
static log_t logger;

static uint8_t app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    uartmux4_cfg_t uartmux4_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    uartmux4_cfg_setup( &uartmux4_cfg );
    UARTMUX4_MAP_MIKROBUS( uartmux4_cfg, MIKROBUS_1 );
    if ( UART_ERROR == uartmux4_init( &uartmux4, &uartmux4_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
    Delay_ms( 100 );
}

void application_task ( void ) 
{
    log_printf( &logger, " ---------------- \r\n" );
    log_printf( &logger, " UART 1 demo message:\r\n" );
    uartmux4_enable_uart1( &uartmux4 );
    Delay_ms( 100 );
    for ( uint8_t n_cnt = 0; n_cnt < 5; n_cnt++ )
    {
        if ( uartmux4_generic_write ( &uartmux4, DEMO_MESSAGE, sizeof( DEMO_MESSAGE ) ) )
        {
            if ( uartmux4_generic_read( &uartmux4, app_buf, sizeof( DEMO_MESSAGE ) ) )
            {
                log_printf( &logger, "%s", app_buf );
            }
        }
        Delay_ms( 2000 );
    }
    
    log_printf( &logger, " ---------------- \r\n" );
    log_printf( &logger, " UART 2 demo message:\r\n" );
    uartmux4_enable_uart2( &uartmux4 );
    Delay_ms( 100 );
    for ( uint8_t n_cnt = 0; n_cnt < 5; n_cnt++ )
    {
        if ( uartmux4_generic_write ( &uartmux4, DEMO_MESSAGE, sizeof( DEMO_MESSAGE ) ) )
        {
            if ( uartmux4_generic_read( &uartmux4, app_buf, sizeof( DEMO_MESSAGE ) ) )
            {
                log_printf( &logger, "%s", app_buf );
            }
        }
        Delay_ms( 2000 );
    }
}

void main ( void ) 
{
    application_init( );

    for ( ; ; ) 
    {
        application_task( );
    }
}

// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.