The following build time configurations are defined in fsp_cfg/r_riic_slave_cfg.h:
This module can be added to the Stacks tab via New Stack > Connectivity > I2C Slave Driver on r_riic_slave.
Configuration | Options | Default | Description |
Interrupt Priority Level > Transmit, Receive, and Transmit End | Value must be an integer between 0 and 31 | 24 | Select the interrupt priority level. This is set for TXI, RXI, and TEI interrupts. |
Interrupt Priority Level > NACK, Start, Stop, Timeout, Arbitration lost | Value must be an integer between 0 and 31 | 24 | Select the interrupt priority level. This is set for NAKI, SPI, STI, ALI, TMOI interrupt. |
Name | Name must be a valid C symbol | g_i2c_slave0 | Module name. |
Channel | Value must be an integer between 0 and 3 | 0 | Specify the RIIC channel. |
Rate |
-
Standard
-
Fast-mode
-
Fast-mode plus
| Standard | Select the transfer rate. |
Internal Reference Clock |
-
P0CLK / 1
-
P0CLK / 2
-
P0CLK / 4
-
P0CLK / 8
-
P0CLK / 16
-
P0CLK / 32
-
P0CLK / 64
-
P0CLK / 128
| P0CLK / 1 | Select the internal reference clock for RIIC slave. The internal reference clock is used only to determine the clock frequency of the noise filter samples. |
Digital Noise Filter Stage Select |
-
Disabled
-
Single-stage filter
-
2-stage filter
-
3-stage filter
-
4-stage filter
| 3-stage filter | Select the number of digital filter stages for RIIC Slave. |
Slave Address | Value must be non-negative | 0x08 | Specify the slave address. |
General Call |
| Disabled | Allows the slave to respond to general call address: 0x00. |
Address Mode |
| 7-Bit | Select the slave address mode. |
Clock Stretching |
| Disabled | Configure Clock Stretching. |
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) to report I2C Slave transaction events and status. |
The RIIC peripheral module uses the P0 clock as its clock source. The actual I2C transfer rate will be calculated and set by the tooling depending on the selected transfer rate. If the P0 clock is configured in such a manner that the selected transfer rate cannot be achieved, an error will be returned.
The IIC 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.
This is a basic example of minimal use of the R_RIIC_SLAVE in an application. This example shows how this driver can be used for basic read and write operations.
{
.slave = I2C_7BIT_ADDR_IIC_SLAVE,
.p_callback = i2c_master_callback,
.p_context = &g_i2c_master_ctrl,
.p_transfer_tx = NULL,
.p_transfer_rx = NULL,
.rxi_irq = RIIC0_RI_IRQn,
.txi_irq = RIIC0_TI_IRQn,
.tei_irq = RIIC0_TEI_IRQn,
.ipl = 24,
.p_extend = &g_iic_master_cfg_extend_standard_mode
};
iic_slave_instance_ctrl_t g_i2c_slave_ctrl;
{
.slave = I2C_7BIT_ADDR_IIC_SLAVE,
.rxi_irq = RIIC1_RI_IRQn,
.txi_irq = RIIC1_TI_IRQn,
.tei_irq = RIIC1_TEI_IRQn,
.ipl = 24,
.p_callback = i2c_slave_callback,
.p_context = &g_i2c_slave_ctrl,
.p_extend = &g_iic_slave_cfg_extend_standard_mode
};
{
g_i2c_master_callback_event = p_args->
event;
}
{
g_i2c_slave_callback_event = p_args->
event;
{
}
{
err =
R_RIIC_SLAVE_Read(&g_i2c_slave_ctrl, g_i2c_slave_buffer, g_slave_transfer_length);
assert(FSP_SUCCESS == err);
}
{
assert(FSP_SUCCESS == err);
}
else
{
}
}
void basic_example (void)
{
uint32_t i;
uint32_t timeout_ms = I2C_TRANSACTION_BUSY_DELAY;
g_slave_transfer_length = I2C_BUFFER_SIZE_BYTES;
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
for (i = 0; i < I2C_BUFFER_SIZE_BYTES; i++)
{
g_i2c_master_tx_buffer[i] = (uint8_t) i;
}
err =
R_RIIC_MASTER_Write(&g_i2c_master_ctrl, &g_i2c_master_tx_buffer[0], I2C_BUFFER_SIZE_BYTES,
false);
assert(FSP_SUCCESS == err);
{
timeout_ms--;
}
{
__BKPT(0);
}
timeout_ms = I2C_TRANSACTION_BUSY_DELAY;
err =
R_RIIC_MASTER_Read(&g_i2c_master_ctrl, &g_i2c_master_rx_buffer[0], I2C_BUFFER_SIZE_BYTES,
false);
assert(FSP_SUCCESS == err);
{
timeout_ms--;
}
{
__BKPT(0);
}
if (0U != memcmp(g_i2c_master_tx_buffer, g_i2c_master_rx_buffer, I2C_BUFFER_SIZE_BYTES))
{
__BKPT(0);
}
}