Intermediate
30 min

Modernize your data communication using SC16IS740 and STM32F103RB

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

UART I2C/SPI Click with Nucleo 64 with STM32F103RB MCU

Published Oct 08, 2024

Click board™

UART I2C/SPI Click

Dev. board

Nucleo 64 with STM32F103RB MCU

Compiler

NECTO Studio

MCU

STM32F103RB

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

Nucleo-64 with STM32F103RB MCU offers a cost-effective and adaptable platform for developers to explore new ideas and prototype their designs. This board harnesses the versatility of the STM32 microcontroller, enabling users to select the optimal balance of performance and power consumption for their projects. It accommodates the STM32 microcontroller in the LQFP64 package and includes essential components such as a user LED, which doubles as an ARDUINO® signal, alongside user and reset push-buttons, and a 32.768kHz crystal oscillator for precise timing operations. Designed with expansion and flexibility in mind, the Nucleo-64 board features an ARDUINO® Uno V3 expansion connector and ST morpho extension pin

headers, granting complete access to the STM32's I/Os for comprehensive project integration. Power supply options are adaptable, supporting ST-LINK USB VBUS or external power sources, ensuring adaptability in various development environments. The board also has an on-board ST-LINK debugger/programmer with USB re-enumeration capability, simplifying the programming and debugging process. Moreover, the board is designed to simplify advanced development with its external SMPS for efficient Vcore logic supply, support for USB Device full speed or USB SNK/UFP full speed, and built-in cryptographic features, enhancing both the power efficiency and security of projects. Additional connectivity is

provided through dedicated connectors for external SMPS experimentation, a USB connector for the ST-LINK, and a MIPI® debug connector, expanding the possibilities for hardware interfacing and experimentation. Developers will find extensive support through comprehensive free software libraries and examples, courtesy of the STM32Cube MCU Package. This, combined with compatibility with a wide array of Integrated Development Environments (IDEs), including IAR Embedded Workbench®, MDK-ARM, and STM32CubeIDE, ensures a smooth and efficient development experience, allowing users to fully leverage the capabilities of the Nucleo-64 board in their projects.

Nucleo 64 with STM32F103RB MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M3

MCU Memory (KB)

128

Silicon Vendor

STMicroelectronics

Pin count

64

RAM (Bytes)

20480

You complete me!

Accessories

Click Shield for Nucleo-64 comes equipped with two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the STM32 Nucleo-64 board with no effort. This way, Mikroe allows its users to add any functionality from our ever-growing range of Click boards™, such as WiFi, GSM, GPS, Bluetooth, ZigBee, environmental sensors, LEDs, speech recognition, motor control, movement sensors, and many more. More than 1537 Click boards™, which can be stacked and integrated, are at your disposal. The STM32 Nucleo-64 boards are based on the microcontrollers in 64-pin packages, a 32-bit MCU with an ARM Cortex M4 processor operating at 84MHz, 512Kb Flash, and 96KB SRAM, divided into two regions where the top section represents the ST-Link/V2 debugger and programmer while the bottom section of the board is an actual development board. These boards are controlled and powered conveniently through a USB connection to program and efficiently debug the Nucleo-64 board out of the box, with an additional USB cable connected to the USB mini port on the board. Most of the STM32 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 STM32 Nucleo-64 board with our Click Shield for Nucleo-64, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Nucleo-64 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
PC12
RST
SPI Chip Select / I2C Address Selection
PB12
CS
SPI Clock
PB3
SCK
SPI Data OUT
PB4
MISO
SPI Data IN
PB5
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PC14
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB8
SCL
I2C Data
PB9
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 Nucleo-64 accessories 1 image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo 64 with STM32F103RB MCU as your development board.

Click Shield for Nucleo-64 accessories 1 image hardware assembly
Nucleo 64 with STM32F401RE MCU front image hardware assembly
LTE IoT 5 Click front image hardware assembly
Prog-cut hardware assembly
LTE IoT 5 Click complete accessories setup image hardware assembly
Nucleo-64 with STM32XXX MCU Access MB 1 Mini B Conn - 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
Clicker 4 for STM32F4 HA 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

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 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.