TOP Contributors

  1. MIKROE (2655 codes)
  2. Alcides Ramos (353 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (112 codes)
  5. Chisanga Mumba (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 (136781 times)
  2. FAT32 Library (69978 times)
  3. Network Ethernet Library (55948 times)
  4. USB Device Library (46274 times)
  5. Network WiFi Library (41888 times)
  6. FT800 Library (41184 times)
  7. GSM click (28987 times)
  8. PID Library (26419 times)
  9. mikroSDK (26372 times)
  10. microSD click (25381 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

I2C to SPI click

Rating:

0

Author: MIKROE

Last Updated: 2024-04-03

Package Version: 2.1.0.16

mikroSDK Library: 2.0.0.0

Category: Adapter

Downloaded: 148 times

Not followed.

License: MIT license  

I2C to SPi Click is an all-in-one solution which allows serving as an interface between a standard I2C-bus of a microcontroller and an SPi bus, which allows the microcontroller to communicate directly with SPi devices through its I2C-bus. It is equipped with the stacking headers, so it can be easily connected.

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "I2C to SPI click" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "I2C to SPI click" changes.

Do you want to report abuse regarding "I2C to SPI click".

  • mikroSDK Library 1.0.0.0
  • Comments (0)

mikroSDK Library Blog


I2C to SPI click

I2C to SPi Click is an all-in-one solution which allows serving as an interface between a standard I2C-bus of a microcontroller and an SPi bus, which allows the microcontroller to communicate directly with SPi devices through its I2C-bus. It is equipped with the stacking headers, so it can be easily connected.

i2ctospi_click.png

click Product page


Click library

  • Author : MikroE Team
  • Date : maj 2020.
  • Type : I2C type

Software Support

We provide a library for the I2cToSpi 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 form compilers IDE(recommended way), or downloaded from our LibStock, or found on mikroE github account.

Library Description

This library contains API for I2cToSpi Click driver.

Standard key functions :

  • Config Object Initialization function.

    void i2ctospi_cfg_setup ( i2ctospi_cfg_t *cfg );

  • Initialization function.

    I2CTOSPI_RETVAL i2ctospi_init ( i2ctospi_t ctx, i2ctospi_cfg_t cfg );

  • Click Default Configuration function.

    void i2ctospi_default_cfg ( i2ctospi_t *ctx );

Example key functions :

  • Function SPI write the byte of data to the targeted 8-bit register address of the SC18IS602B I2C-bus to SPI bridge on the I2C to SPI click board.

    void i2ctospi_spi_write_byte ( i2ctospi_t ctx, i2ctospi_spi_t spi, uint8_t write_data );

  • Function SPI read the byte of data from the targeted 8-bit register address of the SC18IS602B I2C-bus to SPI bridge on the I2C to SPI click board.

    uint8_t i2ctospi_spi_read_byte ( i2ctospi_t ctx, i2ctospi_spi_t spi );

  • Function clear interrupt is generated by the SC18IS602B after any SPI transmission has been completed.

    void i2ctospi_clear_interrupt ( i2ctospi_t *ctx );

Examples Description

I2C to SPi Click allows serving as an interface between a standard I2C-bus of a microcontroller and an SPi bus, which allows the microcontroller to communicate directly with SPi devices through its I2C-bus. By offering an I2C-bus slave-transmitter or slave-receiver and SPI master, this Click controls all the SPi bus-specific sequences, protocol, and timing. It also has its own internal oscillator, and it supports the SPi chip select output that may be configured as GPIO when not used.

The demo application is composed of two sections :

Application Init

Initialization driver enable's - I2C, hardware reset, SS0 ( CS ) configured to be used as slave select outputs, set the configuration of SPI: order MSB first, clock Idle low, leading-edge transition, SPI clock rate to 115kHz, set SPI EEPROM write enable SS0, clear interrupt, clear RT5 register, sets starting time: hours, minutes and seconds ( enable counting ), also write log.


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

    i2ctospi_cfg_setup( &cfg );
    I2CTOSPI_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    i2ctospi_init( &i2ctospi, &cfg );

    i2ctospi_default_cfg( &i2ctospi );

    //Set Time :  23h 59m 48s
    rtc5_clear( &i2ctospi, &i2ctospi_spi );  
    rtc5_set_time_hours( &i2ctospi, &i2ctospi_spi, 23 );
    Delay_1ms( );
    rtc5_set_time_minutes( &i2ctospi, &i2ctospi_spi, 59 );
    Delay_1ms( );
    rtc5_set_time_seconds( &i2ctospi, &i2ctospi_spi, 48 );
    Delay_1ms( );
}

Application Task

This is an example which demonstrates the use of RTC 5 click is wired to I2C to SPI click board. I2C to SPI click communicates with register via the I2C interface, serve as an interface between a standard I2C-bus of a microcontroller and an SPI bus. RTC 5 click communicates with register via SPI interface. In this examples, we display RTC time which we received reading from the target register address of MCP79510 chip on RTC 5 click board via I2C interface of I2C to SPI click board. Results are being sent to the Usart Terminal where you can track their changes. All data logs write on usb uart changes for every 1 sec.


void application_task ( void )
{
    time_seconds = rtc5_get_time_seconds( &i2ctospi, &i2ctospi_spi );
    Delay_1ms( );
    time_minutes = rtc5_get_time_minutes( &i2ctospi, &i2ctospi_spi );
    Delay_1ms( );
    time_hours = rtc5_get_time_hours( &i2ctospi, &i2ctospi_spi );
    Delay_1ms( );

    if ( time_seconds_new != time_seconds )
    {
        log_printf( &logger, " Time :  " );

        display_log_uart( time_hours );
        log_printf( &logger, ":" );

        display_log_uart( time_minutes );
        log_printf( &logger, ":" );

        display_log_uart( time_seconds );
        log_printf( &logger, "\r\n" );

        log_printf( &logger, "------------------\r\n" );

        time_seconds_new = time_seconds;
    }

    Delay_1ms( );
} 

Note

Additional Functions :
 - void display_log_uart( uint8_t value ) - Write the value of time or date as a two-digit number.
 - void rtc5_clear( i2ctospi_t *ctx, i2ctospi_spi_t *spi ) - Clear RTCC and SRAM memory of RTC 5 click.
 - void rtc5_set_time_seconds( i2ctospi_t *ctx, i2ctospi_spi_t *spi, uint8_t seconds ) - Set the seconds and enable counting.
 - uint8_t rtc5_get_time_seconds( i2ctospi_t *ctx, i2ctospi_spi_t *spi ) - Get the seconds.
 - void rtc5_set_time_minutes( uint8_t minutes ) - Set the minutes.
 - uint8_t rtc5_get_time_minutes( i2ctospi_t *ctx, i2ctospi_spi_t *spi ) - Get the minutes.
 - void rtc5_set_time_hours( i2ctospi_t *ctx, i2ctospi_spi_t *spi, uint8_t hours ) - Set the hours.
 - uint8_t rtc5_get_time_hours( i2ctospi_t *ctx, i2ctospi_spi_t *spi ) - Get the hours.

The full application code, and ready to use projects can be installed directly form compilers IDE(recommneded) or found on LibStock page or mikroE GitHub accaunt.

Other mikroE Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.I2cToSpi

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. The terminal available in all Mikroelektronika compilers, or any other terminal application of your choice, can be used to read the message.


ALSO FROM THIS AUTHOR

AnyNet 3G click

5

AnyNet 3G click is a cellular to AWS gateway device, which provides developers with the complete solution for various IoT applications, by using the AWS IoT and Cloud Storage services for the data storage, analyzing and processing.

[Learn More]

Multi Stepper TB67S209 click

0

Multi Stepper Click is a compact add-on board that contains a bipolar stepper motor driver. This board features the TB67S209FTG, CLOCK-in controlled bipolar stepping motor driver from Toshiba Semiconductor. It supports a PWM constant-current control drive, selectable mixed decay mode, and allows from full-step up to 1/32 steps resolution for less motor noise and smoother control. It has a wide operating voltage range of 10V to 47V with an output current capacity of 2.8A in addition to several built-in error detection circuits.

[Learn More]

VCP Monitor 3 click

5

VCP Monitor 3 Click is a high precision Voltage, Current and Power measurement Click board with an input capable of taking up to 15V. It features the LTC2947, from Analog Devices, a high precision power and energy monitor with an internal sense resistor supporting up to ±30A.

[Learn More]