Optimize your UART interface and simplify serial data communication by implementing our CMOS analog multiplexer, allowing four remote RS-232 transceivers to efficiently share a single UART connection
A
A
Hardware Overview
How does it work?
UART MUX 2 Click is based on the MAX399, a precise CMOS analog multiplexer that enables pseudo-multidrop RS232 transmission from Analog Devices. This multiplexer allows multiple channels, in this case, four, to share a single UART interface. It offers fast switching speeds with a transition time of less than 250ns and low on-resistance of less than 100Ω while retaining CMOS-logic input compatibility and fast switching. The dual four-to-one multiplexer permits transceiver MAX3221 to form a network with the four remote transceivers connected to terminals labeled as UART0-UART3 in the upper part of the Click board™. The circuit's supply-voltage range (3V to 5.5V) makes it compatible with 3V and 5V logic. MAX399 receives its power directly from the power terminals of MAX3221, whose ±5.5V outputs come
from an internal charge pump. The multiplexer handles rail-to-rail signals, so obtaining its power from MAX3221 ensures that RS232 signals pass directly through, regardless of amplitude. The UART MUX Click communicates with MCU through MAX3221 using the UART interface for the data transfer. The MAX3221 can run at data rates up to 250 kbps while maintaining RS232-compliant output levels. Channel selection is performed through a set of specific GPIO pins, labeled as A0 and A1, routed on the CS and RST pins of the mikroBUS™ socket. Selecting channel 1, for instance, enables MAX3221 to communicate with UART0 without being loaded by UART1 to UART3. Pulldown resistors inside the remote transceivers force the outputs of un-selected receivers to a known state. In addition to a
channel selection, this Click board™ also has an automatic power-down feature that can be turned off when ON and OFF pins are high, routed on the PWM and AN pins of the mikroBUS™ socket. Also, it uses the interrupt pin of the mikroBUS™ labeled as INV as an invalid indicator, making interfacing with the RS232 simple and easy, indicating whether a valid RS232 signal is present. 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 UNO is a versatile microcontroller board built around the ATmega328P chip. It offers extensive connectivity options for various projects, featuring 14 digital input/output pins, six of which are PWM-capable, along with six analog inputs. Its core components include a 16MHz ceramic resonator, a USB connection, a power jack, an
ICSP header, and a reset button, providing everything necessary to power and program the board. The Uno is ready to go, whether connected to a computer via USB or powered by an AC-to-DC adapter or battery. As the first USB Arduino board, it serves as the benchmark for the Arduino platform, with "Uno" symbolizing its status as the
first in a series. This name choice, meaning "one" in Italian, commemorates the launch of Arduino Software (IDE) 1.0. Initially introduced alongside version 1.0 of the Arduino Software (IDE), the Uno has since become the foundational model for subsequent Arduino releases, embodying the platform's evolution.
Microcontroller Overview
MCU Card / MCU
Architecture
AVR
MCU Memory (KB)
32
Silicon Vendor
Microchip
Pin count
28
RAM (Bytes)
2048
You complete me!
Accessories
Click Shield for Arduino UNO has two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the Arduino UNO board without effort. The Arduino Uno, a microcontroller board based on the ATmega328P, provides an affordable and flexible way for users to try out new concepts and build prototypes with the ATmega328P microcontroller from various combinations of performance, power consumption, and features. The Arduino Uno has 14 digital input/output pins (of which six can be used as PWM outputs), six analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP header, and reset button. Most of the ATmega328P microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. 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 UNO board with our Click Shield for Arduino UNO, 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
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 2 Click driver.
Key functions:
uartmux2_set_operation_mode
- UART MUX 2 set operation mode functionuartmux2_set_channel
- UART MUX 2 set channel functionuartmux2_send_data
- UART MUX 2 data writing 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 2 Click Example.
*
* # Description
* This library contains API for UART MUX 2 Click driver.
* This example transmits/receives and processes data from UART MUX 2 clicks.
* The library initializes and defines the UART bus drivers
* to transmit or receive data.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes driver and set UART channel module.
*
* ## Application Task
* Transmitter/Receiver task depend on uncommented code.
* Receiver logging each received byte to the UART for data logging,
* while transmitted send messages every 2 seconds.
*
* ## Additional Function
* - static void uartmux2_clear_app_buf ( void ) - Function clears memory of app_buf.
* - static err_t uartmux2_process ( void ) - The general process of collecting presponce
* that a module sends.
*
* @author Nenad Filipovic
*
*/
#include "board.h"
#include "log.h"
#include "uartmux2.h"
#define PROCESS_BUFFER_SIZE 200
#define TRANSMITTER
// #define RECIEVER
static uartmux2_t uartmux2;
static log_t logger;
static uint8_t uart_ch;
static char app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;
static int32_t app_buf_cnt = 0;
unsigned char demo_message[ 9 ] = { 'M', 'i', 'k', 'r', 'o', 'E', 13, 10, 0 };
/**
* @brief UART MUX 2 clearing application buffer.
* @details This function clears memory of application buffer and reset it's length and counter.
* @note None.
*/
static void uartmux2_clear_app_buf ( void );
/**
* @brief UART MUX 2 data reading function.
* @details This function reads data from device and concats data to application buffer.
*
* @return @li @c 0 - Read some data.
* @li @c -1 - Nothing is read.
* @li @c -2 - Application buffer overflow.
*
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t uartmux2_process ( void );
void application_init ( void ) {
log_cfg_t log_cfg; /**< Logger config object. */
uartmux2_cfg_t uartmux2_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_printf( &logger, "\r\n Application Init \r\n" );
// Click initialization.
uartmux2_cfg_setup( &uartmux2_cfg );
UARTMUX2_MAP_MIKROBUS( uartmux2_cfg, MIKROBUS_1 );
err_t init_flag = uartmux2_init( &uartmux2, &uartmux2_cfg );
if ( init_flag == UART_ERROR ) {
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
uartmux2_default_cfg ( &uartmux2 );
app_buf_len = 0;
app_buf_cnt = 0;
log_printf( &logger, "\r\n Application Task \r\n" );
log_printf( &logger, "------------------\r\n" );
Delay_ms( 500 );
#ifdef TRANSMITTER
log_printf( &logger, " Send data: \r\n" );
log_printf( &logger, " mikroE \r\n" );
log_printf( &logger, "------------------\r\n" );
log_printf( &logger, " Transmit data \r\n" );
Delay_ms( 1000 );
#endif
#ifdef RECIEVER
uart_ch = UARTMUX2_CHANNEL_0;
log_printf( &logger, " Receive data \r\n" );
log_printf( &logger, " UART%u \r\n", ( uint16_t ) uart_ch );
uartmux2_set_channel( &uartmux2, uart_ch );
Delay_ms( 2000 );
#endif
log_printf( &logger, "------------------\r\n" );
}
void application_task ( void ) {
#ifdef TRANSMITTER
for ( uart_ch = UARTMUX2_CHANNEL_0; uart_ch <= UARTMUX2_CHANNEL_3; uart_ch++ ) {
uartmux2_set_channel( &uartmux2, uart_ch );
Delay_ms( 100 );
uartmux2_send_data( &uartmux2, demo_message );
log_printf( &logger, " UART%u : ", ( uint16_t ) uart_ch );
for ( uint8_t cnt = 0; cnt < 9; cnt ++ ) {
log_printf( &logger, "%c", demo_message[ cnt ] );
Delay_ms( 100 );
}
}
log_printf( &logger, "------------------\r\n" );
Delay_ms( 100 );
#endif
#ifdef RECIEVER
uartmux2_process( );
if ( app_buf_len > 0 ) {
log_printf( &logger, "%s", app_buf );
uartmux2_clear_app_buf( );
}
#endif
}
void main ( void ) {
application_init( );
for ( ; ; ) {
application_task( );
}
}
static void uartmux2_clear_app_buf ( void ) {
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
app_buf_cnt = 0;
}
static err_t uartmux2_process ( void ) {
int32_t rx_size;
char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };
rx_size = uartmux2_generic_read( &uartmux2, rx_buff, PROCESS_BUFFER_SIZE );
if ( rx_size > 0 ) {
int32_t buf_cnt = 0;
if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE ) {
uartmux2_clear_app_buf( );
return -2;
} else {
buf_cnt = app_buf_len;
app_buf_len += rx_size;
}
for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) {
if ( rx_buff[ rx_cnt ] != 0 ) {
app_buf[ ( buf_cnt + rx_cnt ) ] = rx_buff[ rx_cnt ];
} else {
app_buf_len--;
}
}
return 0;
}
return -1;
}
// ------------------------------------------------------------------------ END