This module guide will enable you to effectively use a module in your own design. Upon completion of this
guide, you will be able to add this module to your own design, configure it correctly for the target application
and write code, using the included application project code as a reference and efficient starting point .
References to more detailed API descriptions a nd suggestions of other application projects that il l ustrat e
more advanced uses of the module are available on the Renesas Synergy Knowledge Base (as described in
the References section at the end of this document) and should be valuable resources for creating more
complex designs.
2
C Framework module provides a ThreadX®-aware high-level API for I2C industry standard serial
The I
device communications and configures the I
by the framework. The I
2
C Framework module uses the I2C and SCI peripherals on the Synergy MCU.
Contents
1. I²C Framework Module Features ............................................................................................... 2
• Handles integration and synchronization of multiple I²C peripherals on the I²C bus
• Provides a single interface to access both SCI I²C and RIIC drivers
• The I²C framework module configures I²C communication in master mode
• The I²C framework module supports three data rates: 100 k Hz, 400 kHz, and 1 MHz
• The I²C framework module supports both 7-bit addressing and 10-bit addressing
• The I²C framework module also provides support for callbacks internally. User defined callback is not
used. The callback functions are called with the following events i2c_event_t:
Transfer aborted
Transmit complete
Receive complete.
The callback structure i2c_callback_args_t also provides the number of bytes that were sent or
A critical assertion has failed, or Null pointer(s) is(are) given
SSP_ERR_NOT_OPEN
Device instance not opened
SSP_ERR_TRANSFER_ABORTED
The data transfer was aborted
SSP_ERR_INVALID_RATE
The requested rate cannot be set
SSP_ERR_TIMEOUT
Timeout error occurs
2. I²C Framework Module APIs Overview
The I²C Framework interface defines APIs for opening, closing, reading, writing, locking, unlocking, and
resetting the bus using the I²C Framework. A com plete list of the available APIs, an example API call and a
short description of each can be found in the following table. A table of status return values follows the A P I
summary table.
Table 1. I²C Framework Module API Summary
g_sf_i2c_device.p_cfg)
Disables the I²C device designated by control handle. Closes the RTOS services
Locks the bus for a device. Locking the bus reserves it until unlocking and allows
timeout);
Locks the bus for a device. Locking the bus reserves it until unlocking and allows
several reads and writes without intervention f rom ot her devices on the same I
Timeout value is user configurable.
Note: For more complete descriptions of operation and definitions for the function data structures, typedefs,
defines, API data, API structures, and function variables, review the SSP User’s Manual API References for the associated module.
Table 2. Status Return Values
2
C bus.
Note: Lower-level drivers may return common er ror codes. Refer to the SSP User’s Manual API References
for the associated module for a definition of all relev ant status return values.
The I²C Framework module complies with the lay ered driver architecture of the SSP. It uses the lower-level
I²C HAL modules to communicate with the I²C peripherals and controls the I²C-capable peripheral s on a
Synergy microcontroller, as configured by a user. With the I²C Framework module, one or more I² C buses
can be created and multiple I²C peripherals can be connected to each I²C bus. The I²C Framework module
APIs use a ThreadX-mutex to acquire and release t he shared bus for I²C slave devices. In the I²C
Framework module, acquire and release are implem ented by lock (or lockWait) and unlock APIs,
respectively.
As the I²C framework module configures I²C comm unication in master mode, this allows the user to:
• Initialize the driver
• Read from a slave device
• Write to a slave device
• Reset the I²C peripheral
• Lock the I²C bus
• Unlock the I²C bus.
The I²C Framework module works with the Synergy MCU I²C hardware modules, the RIIC and SCI HAL
modules. Both I²C modules support the I²C fast-mode with bit rates of up to 400 kHz. The IIC peripheral and
the RIIC HAL module support fast-mode plus with 1-MHz bit-rates. The module supports only master mode
for both implementations.
Multiple Slave Devices on the Same Bus
The I²C Framework module uses a bus and device on bus architecture. If multiple salves are connected t o
the I²C bus, each slave communicates with an ass ociated and separate SF_I2C module instance. Each
SF_I2C instance is created in a separate thread. Every slave device is linked to the bus to which it will be
connected and share the bus with all other slave devices. The user must configure the framework share dbus and the lower-level I²C HAL layer for each framework device connecting to the bus. The user can add
the existing framework shared-bus when configuring multiple devices on the same bus. A common start and
stop procedure is used for all I²C data-transfer operations. Only one device is configured to the lower level
and the remaining devices perform read or write operations by switching the device address within t he
framework.
All I²C Framework devices on the same bus must use the same lower-level con fi guration sett ings (for
example, the I²C HAL module), except for the slave address and addressing mode. The framework uses the
configuration of the first device that it opens in the a pplication to configure the bus. This means that al l I²C
Framework devices on the same bus must have the same lower-level configuration settings (except for the
slave address and addressing mode). If different configurations are used, proper operation cannot be
guaranteed.
Bus Locking
The I²C Framework supports bus-locking funct ional i ty, meaning that the bus can be locked for a given
peripheral. The locking allows devices to reserve a bus to themselves for a given time period (between loc k
and unlock). This allows devices to complete sev eral reads and writes on the bus without interrupti on (which
is required in some instances).
The I²C bus is locked when lock or lockWait APIs are call ed. This API locks the I²C bus by acquiring the
mutex for the thread in which the I²C Framework device is used. Once locked, the I²C bus can only be
utilized by the associated device. The other I²C Framework device, or same I
2
C framework device from othe r
threads, cannot acquire the mutex, so they won’t be able to access the bus. Once the bus is unlocked by
calling the unlock API from the sf_i2c device that l ocked it, the mutex is released and the bus becomes
available for other sf_i2c devices. The lockWait and lock API are similar, except the lock API provides the
2
user with an option to set timeout value. The lockWait API waits for the specified timeout period if the I
is already locked by another device. In case of the lock API, the thread waits forever, if the I
New Stack> Framework> Con ne cti v it y > I²C Framework
3.1 I²C Framework Module Important Operational Notes and Limitations
3.1.1 I²C Framework Module Operational Notes
•The closest possible baud rate that can be achieved (less than or e qual t o t he requested rate) at the
current PCLKB settings is calculated and used. If a valid clock rate could not be calculated, an error is
returned.
•The I²C can trigger the start of other peripherals available from the ELC. See the ELC Module Guide for
further information.
•The I²C Framework can support multiple I²C devices on the same bus if the clock rate remains the same
for all the devices. That means multiple devices can b e opened in the same bus if they are of the same
clock rate. If devices have different clock rates, only one device can be opened at a time.
• SDA and SCL output pin type should be n-channel open drain wh en using I²C on SCI.
• Shared bus can be used by multiple slave devices with the respective configuration. The framework also
handles mutual exclusion in lock and unlock API s when multiple devices are using the same I²C channel.
•To configure multiple I²C devices on the same bus, add and configure the following modules for each
device to be connected to the bus:
I²C Framework device module
Configure the I²C shared bus module for the first dev ice being configured, then use the same bus for
the remaining devices
I²C HAL module
DTC module (optional)
• Lock functionality will be effective for devices from different t hreads. If multiple devices connected to the
bus are from the same thread, the I²C bus will be lock ed for all devices from that thread. In such case s,
even if the bus is locked, all devices from the same t hread can access the bus.
•In case a device is being used from multiple threads, and the dev ice locks the I²C bus from one thread,
the same device cannot access the I²C bus from other threads.
Note: Configure each I²C Framework device with a unique name in the ISDE configurator. Provide the same
configuration settings for devices connected on the same bus (except the slave address and
addressing modes).
3.1.2 I²C Framework Module Limitations
The I²C framework module does not currently support the use of DMA. Refer to the latest SSP Release Notes for any
additional operational limitations for this module.
4. Including the I²C Framework Module in an Application
This section describes how to include the I²C Framewor k module in an application using the SSP
configurator.
Note: It is assumed you are familiar with creating a project, adding threads, adding a stack to a thread, and
configuring a block within the stack. If you are unfami l i ar wit h any of these items, refer to the first few
chapters of the SSP User’s Manual to learn how to manage each of these important steps in creating
To add the I²C Framework module to an application, simply add it to a thread using the stacks selection
sequence given in the following table. (The default name for the I²C Framework Module is
g_sf_i2c_device0. This name can be changed in the associated Properties window.)
Table 3. I²C Framework Module Selection Sequence
The following figure shows when the I²C Framewo rk m odul e on sf_i2c is added to the thread stack, the
configurator automatically adds any needed low er-level modules. Any drivers that need additional
configuration information are box text highlighted in Red. Modules with a Gray band are individual modules
Give a name to identify the I²C Framework device.
based on this name.
Slave Address
0x00
Specify the address of the I²C slave device.
that stand alone. Modules with a Blue band are sh ared or common and need only be added once and can be
used by multiple stacks.
Figure 2. I²C Framework Module Stack
5. Configuring the I²C Framework Module
The I²C Framework module must be configured by y ou for the desired operation. The SSP configuration
window automatically identifies (by highlighting the block in red) any required configurat i on selections, such
as interrupts or operating modes, which must be configured for lower-level modules for successful operation.
Only those properties that can be changed without causing conflicts are available for modificat ion. Other
properties are ‘locked’ and unavailable for chang es. They are identified with a lock icon for the ‘locked’
property in the Properties window in the ISDE. Thi s appro ach simplifies the configuration process and mak es
it much less error-prone than previous ‘manual’ approaches to configuration. The available configuration
settings and defaults for all the user-accessible properties are given in the Properties tab within the S SP
configurator and are shown in the following table s f or easy ref erence.
Note: You may want to open your ISDE, create the module, and explore the property settings in parallel
with reviewing the following configuration table settings. This help to orient you and can be a useful
hands-on approach to learning the ins and outs of developing with SSP.
Table 4. Configuration Settings for the I²C Frame work Module Device on sf_i2c
Specify the SCI channel to be used with
this configuration.
Rate
Standard, Fast-mode
(Default: Standard)
Select the I²C data rate.
Slave Address
0
Address of the slave device.
Address Mode
7-Bit, 10-Bit
(Default: 7-Bit)
Only 7-bit addresses are currently
SDA Output Delay
(nano seconds)
300
SDA output delay in nanoseconds.
Bit Rate Modulation
Enable, Disable
(Default: Enable)
Enables bitrate modulation function.
Callback
NULL
A user callback function can be registered
system.
Receive Interrupt
Priority 0 (highest), Priority 1:14,
(Default: Priority 12)
Receive interrupt priority selection.
Note: The example values and defaults are for a project using the Synergy S7G2 MCU. Other MCUs may
In some cases, settings other than the defaults for lower-level modules can be desirable. For example, i t
might be useful to select different address mode or set different slave address. The configurable properties
for the lower-level modules are given in the following s ecti ons for completeness and as a reference.
Note: Most of the property settings for lower-level modules are intuitive and can usually be determined by
have different default values and available configuration settings.
inspection of the associated Properties window with the SSP configurator.
5.1 Configuration Settings for the I²C Framework Lower-Level Modules
Typically, only a small number of settings must be modified from the default for lower-level dri vers as
indicated by the red text in the thread stack block. Notice that some of the configuration properti es must be
set to a certain value for proper framework operati on and will be locked to prevent user modification. The
following table identifies all the settings within the pr operties section for the module:
Table 5. Configuration Settings for the I²C Framework Shared Bus on sf_i2c
Note: The example values and defaults are for a project using the Synergy S7G2 MCU. Other MCUs may
Table 6. Configuration Settings for the I²C Master Driver on r_sci_i2c
have different default values and available confi guration settings.
Enable
checking.
supported.
in i2c_api_master_t::open. If this callback
function is provided, it will be called from
the interrupt service routine (ISR) for each
of the conditions defined in i2c_event_t.
Warning: Since the callback is called from
an ISR, do not use blocking calls or lengthy
processing. Spending excessive time in an
ISR can affect the responsiveness of the
Specify the IIC channel to be used with
this configuration.
Rate
Standard, Fast-mode, Fast-mode plus
Standard, Fast and Fast-plus. (See IIC
Slave Address
0
Set the address of the slave device the
I²C master will be communicating with.
Address Mode
7-Bit, 10-Bit
Only 7-bit addresses are currently
Timeout Mode
Short Mode, Long Mode
(Default: Short Mode)
Select the timeout mode.
Callback
NULL
A user callback function can be
Receive Interrupt
Priority 0 (highest), Priority 1:14,
(Default: Priority 12)
Receive interrupt priority selection
Transmit Interrupt
Priority 0 (highest), Priority 1:14,
Transmit interrupt priority selection
Transmit End Interrupt
Priority 0 (highest), Priority 1:14,
(Default: Priority 12)
Transmit end interrupt priority selection
Error Interrupt Priority
Priority 0 (highest), Priority 1:14,
Error interrupt priority selection
Priority
Priority
Note: The example values and defaults are for a project using the Synergy S7G2 MCU. Other MCUs may
have different default values and available configuration settings.
Table 7. Configuration Settings for the I²C Master Driver on r_riic
Priority 15 (lowest - not valid if
using ThreadX)
Priority 15 (lowest - not valid if
using ThreadX)
(Default: Priority 12)
Default: Standard
(Default: 7-Bit)
checking
Rate Calculation.)
supported.
Priority
Priority
Priority
registered in i2c_api_master_t::open. If
this callback function is provided, it will
be called from the interrupt service
routine (ISR) for each of the conditions
defined in i2c_event_t.
Warning: Since the callback is called
from an ISR, do not use blocking calls
or lengthy processing. Spending
excessive time in an ISR can affect the
responsiveness of the system.
Priority 15 (lowest - not valid if using
ThreadX)
Priority 15 (lowest - not valid if using
ThreadX)
(Default: Priority 12)
Priority 15 (lowest - not valid if using
ThreadX)
Priority 15 (lowest - not valid if using
ThreadX)
(Default: Priority 12)