TOP Contributors

  1. MIKROE (2762 codes)
  2. Alcides Ramos (374 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (118 codes)
  5. Bugz Bensce (90 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (139250 times)
  2. FAT32 Library (71743 times)
  3. Network Ethernet Library (57115 times)
  4. USB Device Library (47429 times)
  5. Network WiFi Library (43082 times)
  6. FT800 Library (42403 times)
  7. GSM click (29835 times)
  8. mikroSDK (28073 times)
  9. PID Library (26885 times)
  10. microSD click (26198 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
mikroSDK Library

UART to I2C Click

Rating:

0

Author: MIKROE

Last Updated: 2024-10-31

Package Version: 2.1.0.8

mikroSDK Library: 2.0.0.0

Category: RS232

Downloaded: 170 times

Not followed.

License: MIT license  

UART to I2C Click is a compact add-on board allowing connections to UART controllers and I2C targets for protocol conversion. This board features the SC18IM704, a bridge between the standard UART host interface and a serial I2C bus from NXP Semiconductors. The SC18IM704 provides a high-speed UART interface with a baud rate of up to 460.8 kbit/s and 256-byte FIFO for the transfer/receive data process, alongside several user-configurable GPIO pins. The host MCU communicates with the SC18IM704 with ASCII messages protocol, allowing it to control all the specific I2C-bus sequences, protocol, arbitration, and timing.

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "UART to I2C Click" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "UART to I2C Click" changes.

Do you want to report abuse regarding "UART to I2C Click".

  • Information
  • Comments (0)

mikroSDK Library Blog


UART to I2C Click

UART to I2C Click is a compact add-on board allowing connections to UART controllers and I2C targets for protocol conversion. This board features the SC18IM704, a bridge between the standard UART host interface and a serial I2C bus from NXP Semiconductors. The SC18IM704 provides a high-speed UART interface with a baud rate of up to 460.8 kbit/s and 256-byte FIFO for the transfer/receive data process, alongside several user-configurable GPIO pins. The host MCU communicates with the SC18IM704 with ASCII messages protocol, allowing it to control all the specific I2C-bus sequences, protocol, arbitration, and timing.

uarttoi2c_click.png

Click Product page


Click library

  • Author : Stefan Filipovic
  • Date : Dec 2022.
  • Type : UART type

Software Support

We provide a library for the UART to I2C Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for UART to I2C Click driver.

Standard key functions :

  • uarttoi2c_cfg_setup Config Object Initialization function.

    void uarttoi2c_cfg_setup ( uarttoi2c_cfg_t *cfg );
  • uarttoi2c_init Initialization function.

    err_t uarttoi2c_init ( uarttoi2c_t *ctx, uarttoi2c_cfg_t *cfg );
  • uarttoi2c_default_cfg Click Default Configuration function.

    err_t uarttoi2c_default_cfg ( uarttoi2c_t *ctx );

Example key functions :

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

    void uarttoi2c_gpio_write ( uarttoi2c_t *ctx, uint8_t gpio_data );
  • uarttoi2c_gpio_read This function reads data from the gpio port.

    err_t uarttoi2c_gpio_read ( uarttoi2c_t *ctx, uint8_t *gpio_data );
  • uarttoi2c_i2c_write_then_read This function performs a write then read with a repeated start to the I2C target device.

    err_t uarttoi2c_i2c_write_then_read ( uarttoi2c_t *ctx, uint8_t slave_addr, uint8_t *data_in, uint8_t in_len, uint8_t *data_out, uint8_t out_len );

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.


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 " );
}

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.

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 );
}

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.UARTtoI2C

Additional notes and informations

Depending on the development board you are using, you may need USB UART Click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.


ALSO FROM THIS AUTHOR

Fan 2 Click

0

Fan 2 Click carries the MAX31760 precision fan-speed controller. It can measure temperature and adjust the fan speed to keep the temperature at the same level. Fan 2 Click can also control two fans at the same time.

[Learn More]

RadioStation Click

0

RadioStation Click is a unique Click board™ that can be used to broadcast the music via the FM radio band. It features the Si4713-B30 from Silicon Labs, the best in class integrated FM broadcast stereo transmitter, which operates in the frequency range of 76MHz to 108MHz. It can also broadcast RDS/RDBS data. The Click board™ can be equipped with a small FM antenna, which is used to extend the broadcasting range.

[Learn More]

Expand 9 Click

0

Expand 9 Click is a compact add-on board that contains a multi-port I/O expander. This board features the SX1509QB, the world’s lowest voltage level shifting GPIO expander from Semtech Corporation. The SX1509QB comes in a 16-channel configuration and allows easy serial expansion of I/O through a standard I2C serial interface. It also has a built-in level shifting feature making it highly flexible in power supply systems where communication between incompatible I/O voltages is required, an integrated LED driver for enhanced lighting, and a keypad scanning engine to implement keypad applications up to 8x8 matrix.

[Learn More]