![]() |
Synergy Software Package User's Manual
|
The I2C Master on RIIC HAL module provides a high-level API for industry standard I2C serial communications applications and uses the IIC peripheral on a Synergy MCU. Callbacks are provided for transmit complete and receive complete events notification.
The following hardware features are, or are not, supported by SSP for the RIIC Master Driver:
Legend:
| Symbol | Meaning |
|---|---|
| ✓ | Available (Tested) |
| ⌧ | Not Available (Not tested/not functional or both) |
| N/A | Not supported by MCU |
| MCU Group | I2C Format | SMBus Format | Master Mode | Slave Mode | Fast Mode Plus | Selectable duty cycle |
|---|---|---|---|---|---|---|
| S124 | ✓ | ⌧ | ✓ | ✓ | N/A | ⌧ |
| S128 | ✓ | ⌧ | ✓ | ✓ | N/A | ⌧ |
| S1JA | ✓ | ⌧ | ✓ | ✓ | N/A | ⌧ |
| S3A1 | ✓ | ⌧ | ✓ | ✓ | N/A | ⌧ |
| S3A3 | ✓ | ⌧ | ✓ | ✓ | N/A | ⌧ |
| S3A6 | ✓ | ⌧ | ✓ | ✓ | N/A | ⌧ |
| S3A7 | ✓ | ⌧ | ✓ | ✓ | N/A | ⌧ |
| S5D3 | ✓ | ⌧ | ✓ | ✓ | ✓ | ⌧ |
| S5D5 | ✓ | ⌧ | ✓ | ✓ | ✓ | ⌧ |
| S5D9 | ✓ | ⌧ | ✓ | ✓ | ✓ | ⌧ |
| S7G2 | ✓ | ⌧ | ✓ | ✓ | ✓ | ⌧ |
| MCU Group | Configurable to up to three different slave addresses | 7- and 10- bit address formats | General call address, Device ID address and SMBus host address detectable | Automatic loading of the acknowledge bit | SDA output delay function | Selectable Wait functions (8/9 or 9/1) |
|---|---|---|---|---|---|---|
| S124 | ⌧ | 7 and 10-bit | ⌧ | ✓ | ✓ | ⌧ |
| S128 | ⌧ | 7 and 10-bit | ⌧ | ✓ | ✓ | ⌧ |
| S1JA | ⌧ | 7 and 10-bit | ⌧ | ✓ | ✓ | ⌧ |
| S3A1 | ⌧ | 7 and 10-bit | ⌧ | ✓ | ✓ | ⌧ |
| S3A3 | ⌧ | 7 and 10-bit | ⌧ | ✓ | ✓ | ⌧ |
| S3A6 | ⌧ | 7 and 10-bit | ⌧ | ✓ | ✓ | ⌧ |
| S3A7 | ⌧ | 7 and 10-bit | ⌧ | ✓ | ✓ | ⌧ |
| S5D3 | ⌧ | 7 and 10-bit | ⌧ | ✓ | ✓ | ⌧ |
| S5D5 | ⌧ | 7 and 10-bit | ⌧ | ✓ | ✓ | ⌧ |
| S5D9 | ⌧ | 7 and 10-bit | ⌧ | ✓ | ✓ | ⌧ |
| S7G2 | ⌧ | 7 and 10-bit | ⌧ | ✓ | ✓ | ⌧ |
| MCU Group | Full Arbitration Support | Internal Detect Time-Out | Programmable Digital Noise Filters | Support all Interrupt Sources |
|---|---|---|---|---|
| S124 | Master, NACK arbitrations | ✓ | ⌧ | ✓ |
| S128 | Master, NACK arbitrations | ✓ | ⌧ | ✓ |
| S1JA | Master, NACK arbitrations | ✓ | ⌧ | ✓ |
| S3A1 | Master, NACK arbitrations | ✓ | ⌧ | ✓ |
| S3A3 | Master, NACK arbitrations | ✓ | ⌧ | ✓ |
| S3A6 | Master, NACK arbitrations | ✓ | ⌧ | ✓ |
| S3A7 | Master, NACK arbitrations | ✓ | ⌧ | ✓ |
| S5D3 | Master, NACK arbitrations | ✓ | ⌧ | ✓ |
| S5D5 | Master, NACK arbitrations | ✓ | ⌧ | ✓ |
| S5D9 | Master, NACK arbitrations | ✓ | ⌧ | ✓ |
| S7G2 | Master, NACK arbitrations | ✓ | ⌧ | ✓ |
The I2C Master on RIIC (I2C RIIC) HAL module defines API functions including reading and writing using a master I2C device. A complete list of the available API functions, an example API function call and a short description of each can be found in the following table. A table of status return values follows the API summary table.
I2C Master HAL Module API Summary
| Function Name | Example API Call and Description |
|---|---|
| open | g_i2c.p_api->open(g_i2c.p_ctrl, g_i2c.p_cfg);Open the instance and initialize the hardware. |
| close | g_i2c.p_api->close(g_i2c.p_ctrl);Closes the driver and releases the I2C device. |
| read | g_i2c.p_api->read(g_i2c.p_ctrl, &destination, bytes, restart);Performs a read operation on an I2C device. |
| write | g_i2c.p_api->write(g_i2c.p_ctrl, &destination, bytes, restart);Performs a write operation on an I2C device. |
| reset | g_i2c.p_api->reset(g_i2c.p_ctrl);Reset the peripheral. |
| versionGet | g_i2c.p_api->versionGet(&version);Retrieve the API version with the version pointer. |
| slaveAddressSet | g_i2c.p_api->slaveAddressSet(g_i2c.p_ctrl, slave_addr, addr_mode);Reconfigures the slave address. |
Status Return Values
| Name | Description |
|---|---|
| SSP_SUCCESS | API Call Successful. |
| SSP_ERR_INVALID_POINTER | Pointer is NULL. |
| SSP_ERR_IN_USE | I2C bus busy state detected during I2C transaction operation or attempted to open an already open device instance only during open API call. |
| SSP_ERR_ABORTED | Device was closed while a transfer was in progress. |
| SSP_ERR_INVALID_ARGUMENT | Parameter has invalid value. |
| SSP_ERR_INVALID_RATE | The requested rate cannot be set. |
| SSP_ERR_HW_LOCKED | Driver busy doing riic operation. |
The I2C master on RIIC HAL module supports transactions with an I2C Slave device. Callbacks are provided to interrupt the CPU when a transmission or receive has been completed. The RIIC HAL module invokes the callback with the argument i2c_callback_args_t, indicating the number of received or transmitted bytes in buffer, pointer to user provided context, and the event i2c_event_t.
Interrupts
IIC Rate Calculation
Triggering DMAC/DTC with the IIC
Triggering ELC Events with the IIC
Multiple Devices on the Bus
g_i2c.p_ctrl is the same control instance that was used in the last opened device. The module will use the same bus configuration to communicate with the new device when the application program subsequently calls the i2c_api_master_t::read or i2c_api_master_t::write API functions.Usage of Restart Condition
Multi-Master Support
If multiple masters are connected on the same bus, the I2C Master is capable of detecting bus busy state before initiating the communication.
SDA Delay Support
The SDA Delay function delays SDA output from the detection of a falling edge of SCL signal to ensure that
the SDA signal is output within the interval during which the SCL is low.
This section describes how to include the I2C Master HAL Module in an application using the SSP configurator.
To add the I2C Master Driver to an application, simply add it to a thread using the stacks selection sequence given in the following table. (The default name for the I2C Master Driver is g_i2c0. This name can be changed in the associated Properties window.)
I2C Master HAL Module Selection Sequence
| Resource | ISDE Tab | Stacks Selection Sequence |
|---|---|---|
| g_i2c0 I2C Master Driver on r_riic | Threads | New Stack> Driver> Communications> I2C Master Driver on r_riic |
When the I2C Master HAL module on r_riic is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower‑level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules; these are either optional or recommended. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.
The I2C Master HAL Module must be configured by the user for the desired operation. The available configuration settings and defaults for all the user-accessible properties are given in the properties tab within the SSP configurator and are shown in the following tables for easy reference. Only properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the Properties window in the ISDE. This approach simplifies the configuration process and makes 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 SSP Configurator and are shown in the following tables for easy reference.
Configuration Settings for the I2C Master HAL Module on r_riic
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Enable or disable parameter error checking. |
| Name | g_i2c0 | Module name. |
| Channel | 0 | Specify the IIC channel to be used with this configuration. |
| Rate | Standard, Fast-mode, Fast-mode Plus Default: Standard | Standard, Fast, and Fast-plus. (See IIC Rate Calculation.) |
| Slave Address | 0x00 | Set the address of the slave device the I2C master will be communicating with. |
| Address Mode | 7-Bit, 10-Bit Default: 7-Bit | Only 7-bit addresses are currently supported. |
| SDA Output Delay(nanoseconds) | Default: 300 | SDA output delay in nanoseconds. |
| Callback | NULL | A user callback function can be 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*. *Exact hardware generated error event is also provided when i2c_event_t is I2C_EVENT_ABORTED. 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. |
| Receive Interrupt Priority | Priority 0 (highest), Priority 1:2, Priority 3 (lowest - not valid if using ThreadX) Default: Priority 2 | Receive interrupt priority selection. |
| Transmit Interrupt Priority | Priority 0 (highest), Priority 1:2, Priority 3 (lowest - not valid if using ThreadX) Default: Priority 2 | Transmit interrupt priority selection. |
| Transmit End Interrupt Priority | Priority 0 (highest), Priority 1:2, Priority 3 (lowest - not valid if using ThreadX) Default: Priority 2 | Transmit end interrupt priority selection. |
| Error Interrupt Priority | Priority 0 (highest), Priority 1:2, Priority 3 (lowest - not valid if using ThreadX) Default: Priority 2 | Error interrupt priority selection. |
Typically, only a small number of settings must be modified from the default for lower level drivers as indicated via the red text in the thread stack block. Notice that some of the configuration properties must be set to a certain value for proper framework operation and will be locked to prevent user modification. The following tables identify all the settings within the properties section for the module:
Configuration Settings for the Transfer Driver on r_dtc Event IIC0 TXI
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Selects if code for parameter checking is to be included in the build. |
| Software Start | Enabled, Disabled Default: Disabled | Software start selection. |
| Linker section to keep DTC vector table | .ssp_dtc_vector_table | Linker section to keep DTC vector table. |
| Name | g_transfer0 | Module name. |
| Mode | Normal | Mode selection. |
| Transfer Size | 1 Byte | Transfer size selection. |
| Destination Address Mode | Fixed | Destination address mode selection. |
| Source Address Mode | Incremented | Source address mode selection. |
| Repeat Area (Unused in Normal Mode | Source | Repeat area selection. |
| Interrupt Frequency | After all transfers have completed | Interrupt frequency selection. |
| Destination Pointer | NULL | Destination pointer selection. |
| Source Pointer | NULL | Source pointer selection. |
| Number of Transfers | 0 | Number of transfers selection. |
| Number of Blocks (Valid only in Block Mode) | 0 | Number of blocks selection. |
| Activation Source (Must enable IRQ) | Event IIC0 TXI | Activation source selection. |
| Auto Enable | FALSE | Auto enable selection. |
| Callback (Only valid with Software start) | NULL | Callback selection. |
| ELC Software Event Interrupt Priority | Priority 0 (highest), Priority 1:2, Priority 3 (lowest - not valid if using ThreadX) Default: Disabled | ELC software event interrupt priority selection. |
Configuration Settings for the Transfer Driver on r_dtc Event IIC0 RXI
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Selects if code for parameter checking is to be included in the build. |
| Software Start | Enabled, Disabled Default: Disabled | Software start selection. |
| Linker section to keep DTC vector table | .ssp_dtc_vector_table | Linker section to keep DTC vector table. |
| Name | g_transfer1 | Module name. |
| Mode | Normal | Mode selection. |
| Transfer Size | 1 Byte | Transfer size selection. |
| Destination Address Mode | Incremented | Destination address mode selection. |
| Source Address Mode | Fixed | Source address mode selection. |
| Repeat Area (Unused in Normal Mode | Destination | Repeat area selection. |
| Interrupt Frequency | After all transfers have completed | Interrupt frequency selection. |
| Destination Pointer | NULL | Destination pointer selection. |
| Source Pointer | NULL | Source pointer selection. |
| Number of Transfers | 0 | Number of transfers selection. |
| Number of Blocks (Valid only in Block Mode) | 0 | Number of blocks selection. |
| Activation Source (Must enable IRQ) | Event IIC0 RXI | Activation source selection. |
| Auto Enable | FALSE | Auto enable selection. |
| Callback (Only valid with Software start) | NULL | Callback selection. |
| ELC Software Event Interrupt Priority | Priority 0 (highest), Priority 1:2, Priority 3 (lowest - not valid if using ThreadX) Default: Disabled | ELC software event interrupt priority selection. |
The IIC peripheral module uses the PCLKB as its clock source. The actual I2C transfer rate will be calculated and set internally by the driver depending on the selected transfer rate. If the PCLKB is configured in such a manner that the selected internal rate cannot be achieved, an error will be returned when initializing the driver.
The IIC peripheral module uses pins on the MCU to communicate to external devices. I/O pins must be selected and configured as required by the external device. The following table illustrates the method for selecting the pins within the SSP configuration window and the subsequent table illustrates an example selection for the pins:
Pin Selection Sequence for I2C Master HAL Module on r_riic
| Resource | ISDE Tab | Pin selection Sequence |
|---|---|---|
| IIC | Pins | Select Peripherals> Connectivity: IIC> IIC0 |
Pin Configuration Settings for the I2C Master HAL Module on r_sci_uart
| Pin Configuration Property | Value | Description |
|---|---|---|
| Pin Group Selection | _A only, _B only, Mixed Default: _A only | Pin group selection. |
| Operation Mode | Enabled, Disabled Default: Disabled | Enable or disable peripheral module. |
| SDA | None, P401, P407 Default: None | SDA Pin. |
| SCL | None, P400, P204 Default: None | SCL Pin. |
| SCK | None, P412, P102 Default: P412 | SCK Pin. |
| CTS_RTS_SS | None, P413, P103 Default: None | CTS Pin. |
| SDA | Disabled | SDA Pin (when Simple I2C is used). |
| SCL | Disabled | SCL Pin (when Simple I2C is used). |
The steps in using the I2C Master HAL module in a typical application are:
These common steps are illustrated in a typical operational flow diagram in the following figure: