With our UART line-switching solution, you can confidently address applications such as multi-device communication, data logging, and UART interface management, where precise and flexible routing is essential
A
A
Hardware Overview
How does it work?
UART MUX Click is based on the SN74LV4052A, a dual 4-channel multiplexer and demultiplexer from Texas Instruments. Two control pins are used to switch to one of four available outputs, from a single UART input, from the mikroBUS™. Control pins labeled as A and B, are routed to the mikroBUS™ and can be operated by both 3.3V and 5V MCUs. The fourth control pin is labeled as EN pin, and it is used to enable the internal multiplexing switches of the IC, when is set to a HIGH logic level (it is active HIGH). A and B pins are routed to CS and PWM pins of the mikroBUS™ respectively. The active low Inhibit (INH) tri-state all the channels when high and when low, depending on the A and B inputs, one of the four independent input/outputs is connected to the
UART communication pins. INH pin is routed to the RST pin on the mikroBUS™. The ultra-low leakage current ensures that there is no signal interference from the inputs that are not selected by the A and B pins. A low crosstalk also ensures that the signal on one channel remains clean of interferences caused by other channels. This ensures a reliable operation of the IC and the Click board™ itself. The output signals can be connected via the 2x4 pin headers. Besides RX and TX pins, every output also has dedicated VCC and GND pins avalilable, so that user can easily route multple devices with this Click board™. Independent power supply input allows the user to work with a wide range of signal amplitudes, depending on the application requirements, as
long as the power supply stays within the limits. More information about the SN74LV4052A can be found in the attached datasheet. However, the Click board™ comes equipped with a library that contains easy to use functions and a usage example that may be used as a reference for the development. 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.
Features overview
Development board
Arduino Mega 2560 is a robust microcontroller platform built around the ATmega 2560 chip. It has extensive capabilities and boasts 54 digital input/output pins, including 15 PWM outputs, 16 analog inputs, and 4 UARTs. With a 16MHz crystal
oscillator ensuring precise timing, it offers seamless connectivity via USB, a convenient power jack, an ICSP header, and a reset button. This all-inclusive board simplifies microcontroller projects; connect it to your computer via USB or power it up
using an AC-to-DC adapter or battery. Notably, the Mega 2560 maintains compatibility with a wide range of shields crafted for the Uno, Duemilanove, or Diecimila boards, ensuring versatility and ease of integration.
Microcontroller Overview
MCU Card / MCU
![default](https://dbp-cdn.mikroe.com/catalog/mcus/resources/ATmega2560.jpeg)
Architecture
AVR
MCU Memory (KB)
256
Silicon Vendor
Microchip
Pin count
100
RAM (Bytes)
8192
You complete me!
Accessories
Click Shield for Arduino Mega comes equipped with four mikroBUS™ sockets, with two in the form of a Shuttle connector, allowing all the Click board™ devices to be interfaced with the Arduino Mega board with no effort. Featuring an AVR 8-bit microcontroller with advanced RISC architecture, 54 digital I/O pins, and Arduino™ compatibility, the Arduino Mega board offers limitless possibilities for prototyping and creating diverse applications. This board is controlled and powered conveniently through a USB connection to program and debug the Arduino Mega board efficiently out of the box, with an additional USB cable connected to the USB B port on the board. Simplify your project development with the integrated ATmega16U2 programmer and unleash creativity using the extensive I/O options and expansion capabilities. There are eight switches, which you can use as inputs, and eight LEDs, which can be used as outputs of the MEGA2560. In addition, the shield features the MCP1501, a high-precision buffered voltage reference from Microchip. This reference is selected by default over the EXT REF jumper at the bottom of the board. You can choose an external one, as you would usually do with an Arduino Mega board. There is also a GND hook for testing purposes. Four additional LEDs are PWR, LED (standard pin D13), RX, and TX LEDs connected to UART1 (mikroBUS™ 1 socket). This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the Arduino Mega board with Click Shield for Arduino Mega, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.
Used MCU Pins
mikroBUS™ mapper
Take a closer look
Click board™ Schematic
![UART MUX Click Schematic schematic](https://dbp-cdn.mikroe.com/catalog/click-boards/resources/1ee790ca-2201-65c6-b0d9-0242ac120009/schematic.webp)
Step by step
Project assembly
Track your results in real time
Application Output
This Click board can be interfaced and monitored in two ways:
Application Output
- Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
UART Terminal
- Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.
Software Support
Library Description
This library contains API for UART MUX Click driver.
Key functions:
uartmux_send_command
- Send commanduartmux_set_inhibit_communication
- Set INT pinuartmux_choose_channel
- Choose channel
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
* \brief UartMux Click example
*
* # Description
* This example reads and processes data from UART Mux clicks.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes driver.
*
* ## Application Task
* Reads the received data.
*
* ## Additional Function
* - uartmux_process ( ) - The general process of collecting response
* from module.
*
* \author MikroE Team
*
*/
// ------------------------------------------------------------------- INCLUDES
#include "board.h"
#include "log.h"
#include "uartmux.h"
#include "string.h"
#define PROCESS_COUNTER 10
#define PROCESS_RX_BUFFER_SIZE 500
#define TEXT_TO_SEND "MikroE\r\n"
// ------------------------------------------------------------------ VARIABLES
#define DEMO_APP_RECEIVER
// #define DEMO_APP_TRANSMITER
static uartmux_t uartmux;
static log_t logger;
static uartmux_channel_t channel;
static int32_t rsp_size;
static char uart_rx_buffer[ PROCESS_RX_BUFFER_SIZE ] = { 0 };
// ------------------------------------------------------- ADDITIONAL FUNCTIONS
static void uartmux_process ( void )
{
rsp_size = uartmux_generic_read( &uartmux, &uart_rx_buffer, PROCESS_RX_BUFFER_SIZE, &channel );
if ( rsp_size > 0 )
{
for ( int32_t cnt = 0; cnt < rsp_size; cnt++ )
{
log_printf( &logger, "%c", uart_rx_buffer[ cnt ] );
}
}
}
// ------------------------------------------------------ APPLICATION FUNCTIONS
void application_init ( void )
{
log_cfg_t log_cfg;
uartmux_cfg_t cfg;
/**
* 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.
uartmux_cfg_setup( &cfg );
UARTMUX_MAP_MIKROBUS( cfg, MIKROBUS_1 );
uartmux_init( &uartmux, &cfg );
uartmux_set_inhibit_communication( &uartmux, UARTMUX_PIN_STATE_LOW );
}
void application_task ( void )
{
#ifdef DEMO_APP_RECEIVER
uartmux_process( );
#endif
#ifdef DEMO_APP_TRANSMITER
channel.state_a = UARTMUX_STATE_A_CHANNEL_1;
channel.state_b = UARTMUX_STATE_B_CHANNEL_1;
uartmux_generic_write( &uartmux, TEXT_TO_SEND, strlen( TEXT_TO_SEND ), &channel );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
#endif
}
int main ( void )
{
/* Do not remove this line or clock might not be set correctly. */
#ifdef PREINIT_SUPPORTED
preinit();
#endif
application_init( );
for ( ; ; )
{
application_task( );
}
return 0;
}
// ------------------------------------------------------------------------ END