User`s manual
RX62N Group, RX621 Group 5. Usage Examples
5.14.4. Slave mode
In this example the MCU behaves as a virtual slave memory device on channel 0.
It will respond to 7-bit address 0001001b.
The sample is interrupt driven after the initial setup.
/* Peripheral driver function prototypes */
#include "r_pdl_iic.h"
#include "r_pdl_cgc.h"
/* RPDL device-specific definitions */
#include "r_pdl_definitions.h"
/* Define the size of the virtual memory */
#define STORAGE_SIZE 0x100
#define RX_BUFFER_SIZE (STORAGE_SIZE + 1)
#define SLAVE_CHANNEL 0
#define SLAVE_ADDRESS 0xB0
static void slave_callback(void);
static void StoreData(uint16_t count);
/* Current memory address */
volatile uint8_t data_storage_index = 0;
volatile uint8_t data_storage[STORAGE_SIZE];
volatile uint8_t Rx_Buffer[RX_BUFFER_SIZE];
void main(void)
{
/* Initialise the system clocks */
NOTE: The code to initialise the system clock using R_CGC_Set is omitted here.
/* Select IIC mode at 100kHz */
R_IIC_Create(
SLAVE_CHANNEL,
PDL_IIC_MODE_IIC | PDL_IIC_INT_PCLK_DIV_8,
PDL_IIC_SLAVE_0_ENABLE_7,
SLAVE_ADDRESS,
PDL_NO_DATA,
PDL_NO_DATA,
100E3,
0
);
/* Start monitor the channel */
R_IIC_SlaveMonitor(
SLAVE_CHANNEL,
PDL_NO_DATA,
Rx_Buffer,
RX_BUFFER_SIZE,
slave_callback,
7
);
/* The rest is interrupt driven */
while(1);
}
/* R_IIC_SlaveMonitor or R_IIC_SlaveSend callback */
static void slave_callback(void)
{
uint32_t status_flags = 0;
uint16_t tx_count = 0;
uint16_t rx_count = 0;
bool bStartMonitor = true;
R20UT0084EE0112 Rev.1.12 Page 5-59
July. 16, 2014