RZV Flexible Software Package Documentation
Release v3.0.0
|
|
Functions | |
fsp_err_t | R_RIIC_MASTER_Open (i2c_master_ctrl_t *const p_api_ctrl, i2c_master_cfg_t const *const p_cfg) |
fsp_err_t | R_RIIC_MASTER_Read (i2c_master_ctrl_t *const p_api_ctrl, uint8_t *const p_dest, uint32_t const bytes, bool const restart) |
fsp_err_t | R_RIIC_MASTER_Write (i2c_master_ctrl_t *const p_api_ctrl, uint8_t *const p_src, uint32_t const bytes, bool const restart) |
fsp_err_t | R_RIIC_MASTER_Abort (i2c_master_ctrl_t *const p_api_ctrl) |
fsp_err_t | R_RIIC_MASTER_SlaveAddressSet (i2c_master_ctrl_t *const p_api_ctrl, uint32_t const slave, i2c_master_addr_mode_t const addr_mode) |
fsp_err_t | R_RIIC_MASTER_Close (i2c_master_ctrl_t *const p_api_ctrl) |
fsp_err_t | R_RIIC_MASTER_CallbackSet (i2c_master_ctrl_t *const p_api_ctrl, void(*p_callback)(i2c_master_callback_args_t *), void const *const p_context, i2c_master_callback_args_t *const p_callback_memory) |
fsp_err_t | R_RIIC_MASTER_StatusGet (i2c_master_ctrl_t *const p_api_ctrl, i2c_master_status_t *p_status) |
Driver for the RIIC peripheral on RZ MPUs. This module implements the I2C Master Interface.
The I2C master on RIIC HAL module supports transactions with an I2C Slave device. Callbacks must be provided which are invoked when a transmit or receive operation has completed. The callback argument will contain information about the transaction status, bytes transferred and a pointer to the user defined context.
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
DMAC Support | MCU Specific Options | If enabled, DMAC instances will be included in the build for both transmission and reception. | |
10-bit slave addressing |
| Disabled | If enabled, the driver will support 10-bit slave addressing mode along with the default 7-bit slave addressing mode. |
Configuration | Options | Default | Description |
---|---|---|---|
Name | Name must be a valid C symbol | g_i2c_master0 | Module name. |
Channel | Value must be a non-negative integer | 0 | Specify the RIIC channel. |
Rate |
| Standard | Select the transfer rate. |
Custom Rate (bps) | Value must be a non-negative integer | 0 | Set a custom bitrate (bps). Set to 0 to use the maximum bitrate for the selected mode. Standard-mode: up to 100000; Fast-mode: up to 400000; Fast-mode plus: up to 1000000 |
Rise Time (ns) | Value must be a non-negative integer | 120 | Set the rise time (tr) in nanoseconds. |
Fall Time (ns) | Value must be a non-negative integer | 120 | Set the fall time (tf) in nanoseconds. |
Duty Cycle (%) | Value must be an integer between 4 and 96 | 50 | Sets the duty ratio of the High-level period of the SCL clock for the bit rate. The recommended range of duty ratio to satisfy the minimum value for SCL High-level or Low-level period of AC characteristic is shown below. Standard : 40-53% Fast-mode : 24-48% Fast-mode plus : 27-51% |
Noise Filter Stages | Value must be an integer between 1 and 4 | 1 | Set the noise filter stages |
Slave Address | Value must be non-negative | 0x00 | Specify the slave address. |
Address Mode |
| 7-Bit | Select the slave address mode. Ensure 10-bit slave addressing is enabled in the configuration to use 10-Bit setting here. |
Timeout Mode |
| Short Mode | Select the timeout mode to detect bus hang. |
Timeout during SCL Low |
| Enabled | Select if the timeout can occur when SCL is held low for a duration longer than what is set in the timeout mode. |
Callback | Name must be a valid C symbol | NULL | A user callback function must be provided. This will be called from the interrupt service routine (ISR) upon RIIC transaction completion reporting the transaction status. |
Interrupt Priority Level | Value must be an integer between 0 and 255 | 12 | Select the interrupt priority level. This is set for RXI, TXI, TEI, NAKI, SPI, STI, ALI and TMOI interrupts. When DMA transfer is used in RIIC communication, interrupt priorities of DMA and RIIC must be set to meet the following conditions: Set the IPL value of the transfer completion interrupt of the DMAC to be greater than or equal to the IPL value of the RIIC interrupts. |
The RIIC peripheral module uses the clock shown in the following table as its clock source.
Device | Source Clock |
---|---|
RZ/V2L | P0 clock |
RZ/V2H | Ch0 to Ch7: PLLCLN/16, Ch8: PLLCM33/16 |
RZ/V2N | Ch0 to Ch7: PLLCLN/16, Ch8: PLLCM33/16 |
The actual I2C transfer rate will be calculated and set by the tooling depending on the selected transfer rate. If the clock source is configured in such a manner that the selected internal rate cannot be achieved, an error will be returned.
The RIIC peripheral module uses pins on the MPU to communicate to external devices. I/O pins must be selected and configured as required by the external device. An I2C channel would consist of two pins - SDA and SCL for data/address and clock respectively.
The Configuration editor calculates the internal baud-rate setting based on the configured transfer rate.
When the Custom Rate setting is set to 0 the bitrate is fixed to the maximum values shown below. Otherwise, the supplied value is used to generate bitrate settings.
This is a basic example of minimal use of the r_riic_master in an application. This example shows how this driver can be used for basic read and write operations.
This example demonstrates how a single RIIC driver can be used to communicate with different slave devices which are on the same channel.
Data Structures | |
struct | iic_master_clock_settings_t |
struct | iic_master_instance_ctrl_t |
struct | riic_master_extended_cfg_t |
Enumerations | |
enum | iic_master_timeout_mode_t |
enum | iic_master_timeout_scl_low_t |
struct iic_master_clock_settings_t |
struct iic_master_instance_ctrl_t |
I2C control structure. DO NOT INITIALIZE.
struct riic_master_extended_cfg_t |
RIIC extended configuration
Data Fields | ||
---|---|---|
iic_master_timeout_mode_t | timeout_mode | Timeout Detection Time Select: Long Mode = 0 and Short Mode = 1. |
iic_master_timeout_scl_low_t | timeout_scl_low | Allows timeouts to occur when SCL is held low. |
iic_master_clock_settings_t | clock_settings | I2C Clock settings. |
uint8_t | noise_filter_stage | Noise Filter Stage Selection. |
IRQn_Type | naki_irq | NACK IRQ Number. |
IRQn_Type | sti_irq | Start condition IRQ Number. |
IRQn_Type | spi_irq | Stop condition IRQ Number. |
IRQn_Type | ali_irq | Arbitration lost IRQ Number. |
IRQn_Type | tmoi_irq | Timeout IRQ Number. |
fsp_err_t R_RIIC_MASTER_Open | ( | i2c_master_ctrl_t *const | p_api_ctrl, |
i2c_master_cfg_t const *const | p_cfg | ||
) |
Opens the I2C device.
FSP_SUCCESS | Requested clock rate was set exactly. |
FSP_ERR_ALREADY_OPEN | Module is already open. |
FSP_ERR_IP_CHANNEL_NOT_PRESENT | Channel is not available on this MPU. |
FSP_ERR_ASSERTION | Parameter check failure due to one or more reasons below:
|
fsp_err_t R_RIIC_MASTER_Read | ( | i2c_master_ctrl_t *const | p_api_ctrl, |
uint8_t *const | p_dest, | ||
uint32_t const | bytes, | ||
bool const | restart | ||
) |
Performs a read from the I2C device. The caller will be notified when the operation has completed (successfully) by an I2C_MASTER_EVENT_RX_COMPLETE in the callback.
FSP_SUCCESS | Function executed without issue. |
FSP_ERR_ASSERTION | p_api_ctrl, p_dest or bytes is NULL. |
FSP_ERR_IN_USE | Bus busy condition. Another transfer was in progress. |
FSP_ERR_NOT_OPEN | Handle is not initialized. Call R_RIIC_MASTER_Open to initialize the control block. |
fsp_err_t R_RIIC_MASTER_Write | ( | i2c_master_ctrl_t *const | p_api_ctrl, |
uint8_t *const | p_src, | ||
uint32_t const | bytes, | ||
bool const | restart | ||
) |
Performs a write to the I2C device. The caller will be notified when the operation has completed (successfully) by an I2C_MASTER_EVENT_TX_COMPLETE in the callback.
FSP_SUCCESS | Function executed without issue. |
FSP_ERR_ASSERTION | p_api_ctrl or p_src is NULL. |
FSP_ERR_IN_USE | Bus busy condition. Another transfer was in progress. |
FSP_ERR_NOT_OPEN | Handle is not initialized. Call R_RIIC_MASTER_Open to initialize the control block. |
fsp_err_t R_RIIC_MASTER_Abort | ( | i2c_master_ctrl_t *const | p_api_ctrl | ) |
Safely aborts any in-progress transfer and forces the RIIC peripheral into ready state.
FSP_SUCCESS | Channel was reset successfully. |
FSP_ERR_ASSERTION | p_api_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Handle is not initialized. Call R_RIIC_MASTER_Open to initialize the control block. |
fsp_err_t R_RIIC_MASTER_SlaveAddressSet | ( | i2c_master_ctrl_t *const | p_api_ctrl, |
uint32_t const | slave, | ||
i2c_master_addr_mode_t const | addr_mode | ||
) |
Sets address and addressing mode of the slave device. This function is used to set the device address and addressing mode of the slave without reconfiguring the entire bus.
FSP_SUCCESS | Address of the slave is set correctly. |
FSP_ERR_ASSERTION | Pointer to control structure is NULL. |
FSP_ERR_IN_USE | Another transfer was in-progress. |
FSP_ERR_NOT_OPEN | Handle is not initialized. Call R_RIIC_MASTER_Open to initialize the control block. |
fsp_err_t R_RIIC_MASTER_Close | ( | i2c_master_ctrl_t *const | p_api_ctrl | ) |
Closes the I2C device. May power down RIIC peripheral. This function will safely terminate any in-progress I2C transfers.
FSP_SUCCESS | Device closed without issue. |
FSP_ERR_ASSERTION | p_api_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Handle is not initialized. Call R_RIIC_MASTER_Open to initialize the control block. |
fsp_err_t R_RIIC_MASTER_CallbackSet | ( | i2c_master_ctrl_t *const | p_api_ctrl, |
void(*)(i2c_master_callback_args_t *) | p_callback, | ||
void const *const | p_context, | ||
i2c_master_callback_args_t *const | p_callback_memory | ||
) |
Updates the user callback and has option of providing memory for callback structure. Implements i2c_master_api_t::callbackSet
FSP_SUCCESS | Callback updated successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |
fsp_err_t R_RIIC_MASTER_StatusGet | ( | i2c_master_ctrl_t *const | p_api_ctrl, |
i2c_master_status_t * | p_status | ||
) |
Provides driver status.
FSP_SUCCESS | Status stored in p_status. |
FSP_ERR_ASSERTION | NULL pointer. |