User`s manual
RX62N Group, RX621 Group 5. Usage Examples
5.15.2. Using one slave (2)
Figure 5-36 shows how strings of 8-bit data are copied into 32-bit buffers, then transmitted and received
simultaneously by the master and slave.
The received data is then checked to confirm that the transfer was successful.
/* Peripheral driver function prototypes */
#include "r_pdl_cgc.h"
#include "r_pdl_spi.h"
/* PDL device-specific definitions */
#include "r_pdl_definitions.h"
/* Required for this example */
#include <string.h>
void spi_slave_callback(void);
volatile bool slave_transfer_complete;
#define SLAVE_CHANNEL 0
#define MASTER_CHANNEL 1
#define BUFFER_LENGTH 25
const char master_data_to_be_sent[] = "SPI data to slave";
const char slave_data_to_be_sent[] = "SPI slave output ";
void main(void)
{
uint32_t master_tx_data[BUFFER_LENGTH];
uint32_t master_rx_data[BUFFER_LENGTH];
uint32_t slave_tx_data[BUFFER_LENGTH];
uint32_t slave_rx_data[BUFFER_LENGTH];
uint8_t i;
/* Configure the clocks */
R_CGC_Set(
12E6,
96E6,
48E6,
PDL_NO_DATA,
PDL_CGC_BCLK_DISABLE
);
/* Configure the master SPI channel using -A pins */
R_SPI_Create(
MASTER_CHANNEL,
PDL_SPI_MODE_SPI_MASTER | PDL_SPI_PIN_SSL1_LOW | PDL_SPI_PIN_A,
PDL_SPI_FRAME_1_1,
PDL_NO_DATA,
2E6
);
/* Configure the slave SPI channel using -A pins */
R_SPI_Create(
SLAVE_CHANNEL,
PDL_SPI_MODE_SPI_SLAVE | PDL_SPI_PIN_A,
PDL_SPI_FRAME_1_1,
PDL_NO_DATA,
PDL_NO_DATA
);
/* Configure the Master */
R_SPI_Command(
MASTER_CHANNEL,
R20UT0084EE0112 Rev.1.12 Page 5-65
July. 16, 2014