User`s manual
RX62N Group, RX621 Group 5. Usage Examples
5.14.2. Master mode with DMAC
In the following example, data is written to an EEPROM in two bursts. DMAC channel 3 is used to handle the
data transfer.
The same EEPROM address locations are then read out in two bursts. DMAC channel 2 is used to handle the
data transfer.
/* Peripheral driver function prototypes */
#include "r_pdl_iic.h"
#include "r_pdl_cgc.h"
#include "r_pdl_cmt.h"
#include "r_pdl_dmac.h"
/* RPDL device-specific definitions */
#include "r_pdl_definitions.h"
static void write_eeprom_data(void);
static void read_eeprom_data(void);
void iic_tx_dmac_end_handler(void);
void iic_rx_dmac_end_handler(void);
#define EEPROM_MEMORY_ADDRESS_UPPER 0x00
#define EEPROM_MEMORY_ADDRESS_LOWER 0x00
#define EEPROM_ADDRESS (0x00A0 | EEPROM_MEMORY_ADDRESS_UPPER)
volatile uint8_t bus_busy;
volatile uint8_t data_storage[20];
void main(void)
{
const
uint8_t eeprom_data_array_1[] = {EEPROM_MEMORY_ADDRESS_LOWER, 0x01, 0x02, 0x03,
0x04, 0x05};
const
uint8_t eeprom_data_array_2[] = {EEPROM_MEMORY_ADDRESS_LOWER + 5, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
uint8_t i;
/* Configure the clocks */
R_CGC_Set(
12.0E6,
96E6,
48E6,
PDL_NO_DATA,
PDL_CGC_BCLK_DISABLE
);
/* Set up a DMAC channel for IIC transmission */
R_DMAC_Create(
3,
PDL_DMAC_NORMAL | PDL_DMAC_SIZE_8 |
PDL_DMAC_SOURCE_ADDRESS_PLUS |
PDL_DMAC_DESTINATION_ADDRESS_FIXED |
PDL_DMAC_IRQ_END,
PDL_DMAC_TRIGGER_IIC0_TX,
eeprom_data_array_1,
(uint8_t *)&RIIC0.ICDRT,
6,
PDL_NO_DATA,
PDL_NO_DATA,
PDL_NO_DATA,
PDL_NO_DATA,
iic_tx_dmac_end_handler,
7
);
R20UT0084EE0112 Rev.1.12 Page 5-51
July. 16, 2014