Intermediate
30 min

Modernize your data communication using SC16IS740 and ATmega328P

Bridging legacy and modern: The RS232 to I2C/SPI solution

UART I2C/SPI Click with Arduino UNO Rev3

Published Feb 14, 2024

Click board™

UART I2C/SPI Click

Dev Board

Arduino UNO Rev3

Compiler

NECTO Studio

MCU

ATmega328P

Experience the power of data transformation with our solution, seamlessly converting RS232 bus data into the I2C or SPI serial interface of your choice

A

A

Hardware Overview

How does it work?

UART I2C/SPI Click is based on the SC16IS740, an I2C/SPI to UART interface, 64 bytes of transmit and receive FIFOs, and IrDA SIR built-in support, from NXP. This IC bridges the data communication between the two interfaces, offering many additional features, such as the support for the automatic hardware and software flow control, RS-485 support and software reset of the UART. The SC16IS740 can be configured over the SPI or I2C interface, by writing values to a 16C450 compatible set of registers. Maintaining the backward compatibility with the widely popular 16C450 asynchronous communications element (ACE). This allows the software to be easily written or ported from another platform. The second IC provides a physical level conversion for RS-232 communication, as well as the ESD protection within the range of ±15kV. Since the SC16IS740 operates using only TTL/CMOS logic levels, another IC had to be used in order to provide a proper signal conversion on a hardware level. The voltage level of the RS-232 signal can vary between -15V and +15V (-3V to -15V when the line is de-asserted and +3V to +15V when asserted). The MAX3237 IC, a low-power, true RS-232 transceiver from Maxim Integrated is used for the purpose of conditioning

the CMOS/TTL level UART signal from the SC16IS740, into a proper RS-232 signal. All UART lines are driven through this IC, including RXD, TXD, CTS, and RTS lines. After being translated to RS-232 signal levels, these signals are available over the standard RS232 connector (DE-9). The Click board™ is equipped with a number of SMD jumpers. There are five jumpers grouped under the COMM SEL label, used to select one of two available interfaces: SPI, and I2C. By moving all the jumpers at the desired position, the user can select the interface used for the communication with the host MCU. It is advisable to move all the jumpers at once to either left (SPI) or the right (I2C) position. The #RESET pin performs the hardware reset of the SC16IS740 IC. Besides the hardware reset, this device also supports the software reset, by writing a value into the SRESET register. After the Power ON reset, or after a reset pulse is sent over the #RESET pin, it is advised to wait for the external clock oscillator to stabilize. The provided external clock oscillator operates at 1.8432 MHz and takes up to 3ms to stabilize. The #RESET pin is routed to the mikroBUS™ RST pin and it is active LOW. The #INT allows the host MCU to receive an interrupt from the SC16IS740. This pin

allows seven different interrupt sources to generate an interrupt signal. This allows more optimized software (firmware) to be written, as the host MCU does not have to continuously poll the LSR register to see if any interrupt needs to be serviced. However, the software does not have to use interrupts, since each of the interrupt sources will be indicated within the Line Status Register (LSR). The A0/#CS line has two purposes: when the SC16IS740 IC is used in the SPI mode, this pin performs the usual SPI Chip Select function. When used during the I2C mode, this pin determines the I2C address of the device. Therefore, the I2C address of the SC16IS740 IC can be easily changed by applying the specific logic level to this pin. The datasheet of the SC16IS740 offers more information about using and configuring the SC16IS740 IC. However, the Click board™ is supported by a mikroSDK library, offering functions that simplify the prototyping and firmware development. This Click board™ is operated by 3.3V only. To be able to use it with MCUs that use 5V logic level on their communication lines, a proper level-translation circuit should be used.

UART I2C/SPI Click top side image
UART I2C/SPI Click bottom side image

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.

Arduino UNO Rev3 double side image

Microcontroller Overview

MCU Card / MCU

default

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.

Click Shield for Arduino UNO accessories 1 image

DB9 Cable Female-to-Female (2m) cable is essential for establishing dependable serial data connections between devices. With its DB9 female connectors on both ends, this cable enables a seamless link between various equipment, such as computers, routers, switches, and other serial devices. Measuring 2 meters in length, it offers flexibility in arranging your setup without compromising data transmission quality. Crafted with precision, this cable ensures consistent and reliable data exchange, making it suitable for industrial applications, office environments, and home setups. Whether configuring networking equipment, accessing console ports, or utilizing serial peripherals, this cable's durable construction and robust connectors guarantee a stable connection. Simplify your data communication needs with the 2m DB9 female-to-female cable, an efficient solution designed to meet your serial connectivity requirements easily and efficiently.

UART I2C/SPI Click accessories image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PD2
RST
SPI Chip Select / I2C Address Selection
PB2
CS
SPI Clock
PB5
SCK
SPI Data OUT
PB4
MISO
SPI Data IN
PB3
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PC3
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PC5
SCL
I2C Data
PC4
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

UART I2C/SPI Click Schematic schematic

Step by step

Project assembly

Click Shield for Arduino UNO front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Arduino UNO Rev3 as your development board.

Click Shield for Arduino UNO front image hardware assembly
Arduino UNO Rev3 front image hardware assembly
Charger 27 Click front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Arduino UNO Rev3 Access 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 image step 5 hardware assembly
Necto image step 6 hardware assembly
Arduino UNO MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware 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.

Software Support

Library Description

This library contains API for UART I2C/SPI Click driver.

Key functions:

  • uarti2cspi_advanced_init - Advanced initialization function.

  • uarti2cspi_uart_write_text - Uart write text function.

  • uarti2cspi_uart_read - This function reads one byte from the click module.

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 UARTI2CSPI Click example
 * 
 * # Description
 * This example showcases how to initialize, configure and use the UART I2C/SPI click module. 
 * The click is a I2C/SPI to UART bridge interface. It requires a RS232/485 cable in order to be 
 * connected to other click module or an adapter.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes the driver, configures UART, and enables UART interrupts. 
 * 
 * ## Application Task  
 * Depending on the selected mode, it reads all the received data or sends the desired message
 * every 2 seconds.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "uarti2cspi.h"

// ------------------------------------------------------------------ VARIABLES

// #define DEMO_APP_TRANSMITTER
#define DEMO_APP_RECEIVER

#define TEXT_TO_SEND    "MikroE - UART I2C/SPI click\r\n"

static uarti2cspi_t uarti2cspi;
static log_t logger;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    uarti2cspi_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.

    uarti2cspi_cfg_setup( &cfg );
    UARTI2CSPI_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    uarti2cspi_init( &uarti2cspi, &cfg );
    Delay_ms( 1000 );

    uarti2cspi_advanced_init( &uarti2cspi, 115200, UARTI2CSPI_UART_8_BIT_DATA, 
                                                   UARTI2CSPI_UART_NOPARITY,
                                                   UARTI2CSPI_UART_ONE_STOPBIT );
    Delay_ms( 100 );
    uarti2cspi_interrupt_enable( &uarti2cspi, UARTI2CSPI_RXD_INT_EN | UARTI2CSPI_THR_EMPTY_INT_EN );

    Delay_ms( 100 );

#ifdef DEMO_APP_TRANSMITTER
    log_info( &logger, "---- TRANSMITTER MODE ----" );
#endif
#ifdef DEMO_APP_RECEIVER
    log_info( &logger, "---- RECEIVER MODE ----" );
#endif
    Delay_ms( 1000 );
}

void application_task ( void )
{
#ifdef DEMO_APP_TRANSMITTER
    uarti2cspi_uart_write_text( &uarti2cspi, TEXT_TO_SEND );
    log_info( &logger, "---- The message has been sent ----" );
    Delay_ms( 2000 );
#endif
#ifdef DEMO_APP_RECEIVER
    if ( uarti2cspi_uart_data_ready( &uarti2cspi ) )
    {
        uint8_t rx_data = uarti2cspi_uart_read( &uarti2cspi );
        log_printf( &logger, "%c", rx_data );
    }
#endif
}

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.