Intermediate
30 min

Experience the magic of protocol transformation with SC18IM704 and STM32F412RE

UART to I2C wizardry: Your communication transformer!

UART to I2C Click with UNI Clicker

Published Sep 04, 2023

Click board™

UART to I2C Click

Dev. board

UNI Clicker

Compiler

NECTO Studio

MCU

STM32F412RE

Unlock the potential of your UART devices by effortlessly integrating them into I2C networks using our transformation solution, simplifying data exchange and enhancing control

A

A

Hardware Overview

How does it work?

UART to I2C Click is based on the SC18IM704, a bridge between the standard UART port and a serial I2C bus from NXP Semiconductors. The SC18IM704 consists of a full-functional advanced UART interface that communicates with the host MCU through the commonly used RX and TX pins of the mikroBUS™ socket. It is also characterized by a high baud rate of up to 460.8 kbit/s and 256-byte FIFO for the transfer/receive data process. The serial data format is fixed to a one start bit, 8 data bits, and one stop bit. After the reset feature, the baud rate defaults to 9600 bit/s and can be changed through the Baud Rate Generator (BRG) registers. After a Power-Up sequence or already-mentioned hardware reset, achievable through the RST pin of the mikroBUS™ socket, the

SC18IM704 will send two continuous bytes to the host MCU to indicate a Start-Up condition. These two continuous bytes are 0x4F and 0x4B, representing an ‘OK’ state in the ASCII messages protocol. After the correct initial sequence, direct communication is enabled with other I2C-bus devices connected to the populated I2C-bus terminal. The I2C bus uses two wires (SCL and SDA) to transfer information between connected devices, providing a byte-oriented interface that supports data transfers up to 400kHz. The SC18IM704 can also be placed in a software-configurable low-power mode (Power-Down mode). Upon entering the Power-Down state, the UART RX pin is used to exit Deep Power-down mode. The bridge remains in the Deep

Power-down mode as long as the RX pin remains in a high logic state. Any character sent brings the bridge out of Deep Power-down mode but ignores the character. In addition to all these features, the SC18IM704 has several general-purpose I/O pins on the populated header with labeled GP pins. These pins have the option of software setting their function as push-pull, open-drain, or input-only. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

UART to I2C Click top side image
UART to I2C Click bottom side image

Features overview

Development board

UNI Clicker is a compact development board designed as a complete solution that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It supports a wide range of microcontrollers, such as different ARM, PIC32, dsPIC, PIC, and AVR from various vendors like Microchip, ST, NXP, and TI (regardless of their number of pins), four mikroBUS™ sockets for Click board™ connectivity, a USB connector, LED indicators, buttons, a debugger/programmer connector, and two 26-pin headers for interfacing with external electronics. Thanks to innovative manufacturing technology, it allows you to build

gadgets with unique functionalities and features quickly. Each part of the UNI Clicker development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the UNI Clicker programming method, using a third-party programmer or CODEGRIP/mikroProg connected to onboard JTAG/SWD header, the UNI Clicker board also includes a clean and regulated power supply module for the development kit. It provides two ways of board-powering; through the USB Type-C (USB-C) connector, where onboard voltage regulators provide the appropriate voltage levels to each component on the board, or using a Li-Po/Li

Ion battery via an onboard battery connector. All communication methods that mikroBUS™ itself supports are on this board (plus USB HOST/DEVICE), including the well-established mikroBUS™ socket, a standardized socket for the MCU card (SiBRAIN standard), and several user-configurable buttons and LED indicators. UNI Clicker is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

UNI clicker double image

Microcontroller Overview

MCU Card / MCU

default

Type

8th Generation

Architecture

ARM Cortex-M4

MCU Memory (KB)

512

Silicon Vendor

STMicroelectronics

Pin count

64

RAM (Bytes)

262144

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PC13
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
UART TX
PA2
TX
UART RX
PA3
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

UART to I2C Click Schematic schematic

Step by step

Project assembly

UNI Clicker front image hardware assembly

Start by selecting your development board and Click board™. Begin with the UNI Clicker as your development board.

UNI Clicker front image hardware assembly
GNSS2 Click front image hardware assembly
SiBRAIN for STM32F745VG front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
UNI Clicker 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
Necto image step 7 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 to I2C Click driver.

Key functions:

  • uarttoi2c_gpio_write - This function writes a desired data to the gpio port

  • uarttoi2c_gpio_read - This function reads data from the gpio port

  • uarttoi2c_i2c_write_then_read - This function performs a write then read with a repeated start to the I2C target device.

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 to I2C Click Example.
 *
 * # Description
 * This example demonstrates the use of USB to I2C click board by reading the device ID
 * of a 3D Hall 11 click board connected to the I2C port and controlling the GPIO pins.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default config which resets
 * the device and sets the GPIO pins 0-3 as push-pull output and others as input.
 * After that, reads and displays the chip firmware version.
 *
 * ## Application Task
 * Reads the device ID of a 3D Hall 11 click board connected to the I2C port, 
 * toggles the output pins and displays the GPIO port state. The results will
 * be displayed on the USB UART approximately once per second.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "uarttoi2c.h"

// I2C target device configuration
#define DEVICE_NAME                 "3D Hall 11 click"
#define DEVICE_SLAVE_ADDRESS        0x35
#define DEVICE_REG_ID               0x0D
#define DEVICE_ID                   0x01

static uarttoi2c_t uarttoi2c;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    uarttoi2c_cfg_t uarttoi2c_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_info( &logger, " Application Init " );

    // Click initialization.
    uarttoi2c_cfg_setup( &uarttoi2c_cfg );
    UARTTOI2C_MAP_MIKROBUS( uarttoi2c_cfg, MIKROBUS_1 );
    if ( UART_ERROR == uarttoi2c_init( &uarttoi2c, &uarttoi2c_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( UARTTOI2C_ERROR == uarttoi2c_default_cfg ( &uarttoi2c ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    uint8_t version[ 16 ] = { 0 };
    if ( UARTTOI2C_OK == uarttoi2c_read_version ( &uarttoi2c, version ) )
    {
        log_printf( &logger, " Firmware version: %s\r\n", version );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    static uint8_t gpio_state = UARTTOI2C_NO_PIN_MASK;
    uint8_t slave_address = DEVICE_SLAVE_ADDRESS;
    uint8_t reg_addr = DEVICE_REG_ID;
    uint8_t device_id;
    if ( UARTTOI2C_OK == uarttoi2c_i2c_write_then_read ( &uarttoi2c, slave_address, 
                                                         &reg_addr, 1, &device_id, 1 ) )
    {
        log_printf( &logger, " %s - Device ID read: %s\r\n", ( char * ) DEVICE_NAME,
                    ( char * ) ( ( DEVICE_ID == device_id ) ? "Success" : "Fail" ) );
    }
    uarttoi2c_gpio_write ( &uarttoi2c, gpio_state );
    if ( UARTTOI2C_OK == uarttoi2c_gpio_read ( &uarttoi2c, &gpio_state ) )
    {
        log_printf( &logger, " GPIO state: 0x%.2X\r\n\n", ( uint16_t ) gpio_state );
        gpio_state = ~gpio_state;
    }
    Delay_ms ( 1000 );
}

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.