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
PIC18F57Q43 Curiosity Nano evaluation kit is a cutting-edge hardware platform designed to evaluate microcontrollers within the PIC18-Q43 family. Central to its design is the inclusion of the powerful PIC18F57Q43 microcontroller (MCU), offering advanced functionalities and robust performance. Key features of this evaluation kit include a yellow user LED and a responsive
mechanical user switch, providing seamless interaction and testing. The provision for a 32.768kHz crystal footprint ensures precision timing capabilities. With an onboard debugger boasting a green power and status LED, programming and debugging become intuitive and efficient. Further enhancing its utility is the Virtual serial port (CDC) and a debug GPIO channel (DGI
GPIO), offering extensive connectivity options. Powered via USB, this kit boasts an adjustable target voltage feature facilitated by the MIC5353 LDO regulator, ensuring stable operation with an output voltage ranging from 1.8V to 5.1V, with a maximum output current of 500mA, subject to ambient temperature and voltage constraints.
Microcontroller Overview
MCU Card / MCU
Architecture
PIC
MCU Memory (KB)
128
Silicon Vendor
Microchip
Pin count
48
RAM (Bytes)
8196
You complete me!
Accessories
Curiosity Nano Base for Click boards is a versatile hardware extension platform created to streamline the integration between Curiosity Nano kits and extension boards, tailored explicitly for the mikroBUS™-standardized Click boards and Xplained Pro extension boards. This innovative base board (shield) offers seamless connectivity and expansion possibilities, simplifying experimentation and development. Key features include USB power compatibility from the Curiosity Nano kit, alongside an alternative external power input option for enhanced flexibility. The onboard Li-Ion/LiPo charger and management circuit ensure smooth operation for battery-powered applications, simplifying usage and management. Moreover, the base incorporates a fixed 3.3V PSU dedicated to target and mikroBUS™ power rails, alongside a fixed 5.0V boost converter catering to 5V power rails of mikroBUS™ sockets, providing stable power delivery for various connected devices.
Used MCU Pins
mikroBUS™ mapper
Take a closer look
Schematic
Step by step
Project assembly
Track your results in real time
Application Output via Debug Mode
1. Once the code example is loaded, pressing the "DEBUG" button initiates the build process, programs it on the created setup, and enters Debug mode.
2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.
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
This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.
/*!
* @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