Renesas RL78/G13 Application Note

Renesas RL78/G13 Application Note

Handshake-based spi master transmission/reception
Hide thumbs Also See for RL78/G13:

Advertisement

Quick Links

RL78/G13
Handshake-based SPI Master Transmission/Reception
Introduction
This application note describes how the serial array unit (SAU) performs master transmission/reception by
the simple SPI (CSI). The SAU uses the chip select (CS) signal to select a slave device and perform single
transmission/reception. The SAU also performs handshake processing using the BUSY signal.
Target Device
RL78/G13
When applying the sample program covered in this application note to another microcomputer, modify the
program according to the specifications for the target microcomputer and conduct an extensive evaluation of
the modified program.
R01AN6883EJ0100 Rev.1.00
June.15.23
APPLICATION NOTE
Page 1 of 38

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the RL78/G13 and is the answer not in the manual?

Questions and answers

Summary of Contents for Renesas RL78/G13

  • Page 1 APPLICATION NOTE RL78/G13 Handshake-based SPI Master Transmission/Reception Introduction This application note describes how the serial array unit (SAU) performs master transmission/reception by the simple SPI (CSI). The SAU uses the chip select (CS) signal to select a slave device and perform single transmission/reception.
  • Page 2: Table Of Contents

    RL78/G13 Handshake-based SPI Master Transmission/Reception Contents Specifications .......................... 4 Outline of CSI Communication ........................ 4 Outline of Communication ........................5 Communication Format ........................... 7 Handshake .............................. 7 Specification Details ..........................8 Operation Confirmation Conditions ..................11 Related Application Notes...................... 11 Hardware Descriptions ......................
  • Page 3 RL78/G13 Handshake-based SPI Master Transmission/Reception R01AN6883EJ0100 Rev.1.00 Page 3 of 38 June.15.23...
  • Page 4: Specifications

    RL78/G13 Handshake-based SPI Master Transmission/Reception 1. Specifications The serial array unit (SAU) described in this application note performs CSI master transmission/reception. for the slave device selected by the CS signal. The chip select (CS) signal uses the port.CS Handshake processing using the BUSY signal is also performed 1.1 Outline of CSI Communication...
  • Page 5: Outline Of Communication

    RL78/G13 Handshake-based SPI Master Transmission/Reception 1.2 Outline of Communication In this application note, a command and communication for the command are performed at intervals of 1 ms. A set of a command and communication for the command is defined as a slot. Figure 1-2 shows an outline of slot processing and Table 1-1 lists the commands to be used.
  • Page 6 RL78/G13 Handshake-based SPI Master Transmission/Reception Figure 1-3 Timing chart for status check commands Slave Selection CS1 / CS2 BUSY SCK00 Status transmission SI00 from the slave SO00 00H: Status Confirmation FFH: Dummy FFH: Dummy INTCSI00 Send/receive Send/receive Send/receive completed completed...
  • Page 7: Communication Format

    RL78/G13 Handshake-based SPI Master Transmission/Reception 1.3 Communication Format Table 1-3 lists the characteristics of the CSI communication format that is used in the sample code. Table 1-3 Communication Format Item Specification Remarks Communication speed 1 Mbps About 200 kbps at minimum...
  • Page 8: Specification Details

    RL78/G13 Handshake-based SPI Master Transmission/Reception 1.5 Specification Details After completion of initialization, this sample code selects a slave, checks that slave’s status, and then transmits and receives data, switches slaves, and repeats the same operation. (1) Initialize the port. Use P52 controlling the CS1 signal as an output port to output a high-level signal.
  • Page 9 RL78/G13 Handshake-based SPI Master Transmission/Reception (4) After initialization is completed, the master performs communication with the slave as shown in the following steps. When the master is released from HALT mode by an INTTM03 interrupt, it issues the CS signal to The master waits in HALT mode for a 1-ms interval timer interrupt (INTTM03H).
  • Page 10 RL78/G13 Handshake-based SPI Master Transmission/Reception (6) Switching communication commands Receive, transmit, and transmit/receive commands can be switched by changing the comment-out lines in the r_main.c file. The transmit/receive command is set by default. R01AN6883EJ0100 Rev.1.00 Page 10 of 38 June.15.23...
  • Page 11: Operation Confirmation Conditions

    Integrated development IAR Embedded Workbench for Renesas RL78 V4.21.2 from IAR environment (IAR) Systems Corp. C compiler (IAR) IAR C/C++ Compiler for Renesas RL78 V4.21.2.2420 from IAR Systems Corp. Board used RL78/G13 (R5F100LE) Target Board(QB-R5F100LE-TB) 3. Related Application Notes See also the following application notes, which are related to this application note: RL78/G13 Handshake-based SPI Slave Transmission/Reception (R01AN6884E) APPLICATION NOTE R01AN6883EJ0100 Rev.1.00...
  • Page 12: Hardware Descriptions

    RL78/G13 Handshake-based SPI Master Transmission/Reception 4. Hardware Descriptions 4.1 Example of Hardware Configuration Figure 4-1shows an example of the hardware configuration used in the application note. Figure 4-1 Hardware Configuration Master Slave1 RL78/G13 RESET RESET RL78/G13 BUSY P40/TOOL0 P137/INTP0 P10/SCK00...
  • Page 13: List Of Pins To Be Used

    RL78/G13 Handshake-based SPI Master Transmission/Reception 4.2 List of Pins to be Used Table 4-1 lists the pins to be used and their functions Table 4-1 Pins to be Used and Their Functions Pin Name Description P10/SCK00/SCL00/(TI07)/(TO07) Output Serial clock output pin...
  • Page 14: Description Of The Software

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5. Description of the Software 5.1 List of Option Byte Settings Table 5-1 summarizes the settings of the option bytes. Table 5-1 Option Byte Settings Address Setting Value Description 000C0H 1110 1111B (EFH) Stops the watchdog timer operation.
  • Page 15: List Of Variables

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.3 List of Variables Table 5-3 lists the global variables that are used in this sample code. Table 5-3 Global Variables Used in the Sample Code Type Variable Name Contents Function Used r_main.c uint8_t g_tx_data Buffer for transmit data r_main.c...
  • Page 16: List Of Functions

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.4 List of Functions Table 5-4 lists the functions that are used in the sample code. Table 5-4 Functions Function Name Outline Source file R_Systeminit Initialization process r_systeminit.c R_CGC_Get_ResetSource Reset source reading r_cg_cgc_user.c R_CGC_Create CPU clock Configuration r_cg_cgc.c...
  • Page 17 RL78/G13 Handshake-based SPI Master Transmission/Reception [Function Name] R_CGC_Create Synopsis CPU clock Configuration Header r_cg_macrodriver.h r_cg_cgc.h r_cg_userdefine.h Declaration void R_CGC_Create (void) Explanation Set the CPU clock. Arguments • None Return value • None Remarks None [Function Name] R_PORT_Create Synopsis Port Configuration Header r_cg_macrodriver.h...
  • Page 18 RL78/G13 Handshake-based SPI Master Transmission/Reception [Function Name] R_TAU0_Create Synopsis TAU0 Configuration Header r_cg_macrodriver.h r_cg_timer.h r_cg_userdefine.h Declaration void R_CSI00_Create (void) Explanation Configure TAU0 settings. Arguments • None Return value • None Remarks None [Function Name] main Synopsis Main processing Header r_cg_macrodriver.h r_cg_cgc.h...
  • Page 19 RL78/G13 Handshake-based SPI Master Transmission/Reception [Function Name] R_TAU0_Channel3_Higher8bits_Start Synopsis TAU0 channel 3 upper 8 bits start operating Header r_cg_macrodriver.h r_cg_timer.h r_cg_userdefine.h Declaration void R_TAU0_Channel3_Higher8bits_Start (void) Explanation Starts operation of the upper 8 bits of TAU0 channel 3. Arguments • None Return value •...
  • Page 20 RL78/G13 Handshake-based SPI Master Transmission/Reception [Function Name] CSI00_Send Synopsis CSI transmission Header r_cg_macrodriver.h r_cg_cgc.h r_cg_port.h r_cg_serial.h r_cg_timer.h r_cg_userdefine.h Declaration void CSI00_Send (void) Explanation Performs the master transmission processing. Arguments • None Return value • None Remarks None [Function Name] CSI00_Receive...
  • Page 21 RL78/G13 Handshake-based SPI Master Transmission/Reception [Function Name] wait Synopsis Wait for slave response Header r_cg_macrodriver.h r_cg_cgc.h r_cg_port.h r_cg_serial.h r_cg_timer.h r_cg_userdefine.h Declaration uint8_t wait(void) Explanation Waits until the BUSY signal goes low. Arguments • None Return value 0: Detects that the BUSY signal goes low.
  • Page 22: Flowcharts

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.6 Flowcharts 5.6.1 Initialization process Figure 5-1 shows the flow of Initialization process. Figure 5-1 Initialization process R_Systeminit Peripheral I/O Redirection PIOR → 0x00U Function Inhibit Reset source reading R_CGC_Get_ResetSource() CPU clock initialization R_CGC_Create() Input/output settings...
  • Page 23: Cpu Clock Configuration

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.6.3 CPU clock Configuration Figure 5-3 shows the flow of CPU clock Configuration. Figure 5-3 CPU clock Configuration R_CGC_Create() CMC resistor ← 00H : High-speed system clock, High-speed system clock / Subsystem MSTOP bit ← 1   Subsystem clock not used Clock Settings XTSTOP bit ←...
  • Page 24: Sau Configuration

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.6.5 SAU Configuration Figure 5-5 shows the flow of SAU Configuration. Figure 5-5 SAU Configuration R_SAU0_Create() SAU0EN ← 1 Clock supply to SAU0 SAU0 operation setting SPS0 ← 0000H ・Set the operating clock for SAU00...
  • Page 25: Csi00 Configuration

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.6.6 CSI00 Configuration Figure 5-6 shows the flow of CSI00 Configuration. Figure 5-6 CSI00 Configuration R_CSI00_Create() ST0 resistor ← 0001H CSI00 operation stopped CSIMK00 bit ← 1 Disable CSI00 interrupt Clear CSI00 interrupt request flag CSIIF00 bit ←...
  • Page 26: Tau0 Configuration

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.6.7 TAU0 Configuration Figure 5-7 shows the flow of TAU0 Configuration. Figure 5-7 TAU0 Configuration R_TAU0_Create() Clock supply to timer array unit TAU0EN bit ← 1 Set TAU0 operation clock TPS0 register ← 0000H TAU0 operation stopped TT0 register ←...
  • Page 27: Flowchart Of Main Processing

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.6.8 Flowchart of Main Processing Figure 5-8 to Figure 5-9 show the overall flow of processing in this application note. Figure 5-8 Main Processing 1/2 Main() User Main Initialization R_MAIN_UserInit() g_timeout_flag Clear timeout flag ← 0 Disable interrupts IE ←...
  • Page 28: User Main Initialization

    RL78/G13 Handshake-based SPI Master Transmission/Reception Figure 5-9 Main Processing 2/2 g_status_confirmation_flag = 0 CSI transmission/reception CSI status check CSI00_Send_Receive CSI00_Status_check () Change g_slave_select_flag Timeout occurred? Clear g_status_confirmation_flag Change g_slave_select_flag Clear g_status_confirmation_flag Deselect the slave 5.6.9 User Main Initialization Figure 5-10 shows the flow of User Main Initialization.
  • Page 29: Tau0 Channel 3 Upper 8 Bits Start Operation

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.6.10 TAU0 channel 3 upper 8 bits start operation Figure 5-11 shows the flow of TAU0 channel 3 upper 8 bits start operation. Figure 5-11 TAU0 channel 3 upper 8 bits start operation R_TAU0_Channel3_Higher8bits_Start TMIF03H bit← 0 TMMK03H bit←...
  • Page 30: Csi00 Transmit/Receive Processing

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.6.12 CSI00 Transmit/Receive Processing Figure 5-13 shows the flow of CSI00 Transmit/Receive Processing. Figure 5-13 CSI00 Transmit/Receive Processing [Argument] *tx_buf: Transmit data R_CSI00_Send_Receive () tx_num: Number of transmit data *rx_buf: Receive data Initialize status flag...
  • Page 31: Inicsi00 Interrupt Processing

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.6.13 INICSI00 interrupt processing Figure 5-14 shows the flow of INICSI00 interrupt processing. Figure 5-14 INICSI00 interrupt processing R_CSI00_Interrupt () Set value of overrun detection flag in err_type Clear error flag Overrun error has occurred?
  • Page 32: Flowchart Of Csi Status Check

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.6.14 Flowchart of CSI Status Check Figure 5-15 shows the flow of status checking. Figure 5-15 CSI Status Check CSI00_Status_check() cnt = 0 cnt <= 2 Is a return value from wait() 0? Enable interrupts...
  • Page 33: Flowchart Of Csi Transmission/Reception

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.6.15 Flowchart of CSI Transmission/Reception Figure 5-16 shows the flow of transmission and reception. Figure 5-16 CSI Transmission/Reception CSI00_Send_Receive() Extract slave transmittable data count and set it in g_num g_num >= TX_RX_NUM g_rx_data_stored[1] >= TX_RX_NUM...
  • Page 34: Flowchart Of Csi Transmission

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.6.16 Flowchart of CSI Transmission Figure 5-17 shows the flow of transmission. Figure 5-17 CSI Transmission CSI00_Send() g_rx_data_stored[1] >= TX_NUM Is slave receivable data greater than transmit/receive data? Enable interrupts cnt = 0 cnt <= TX_NUM+1...
  • Page 35: Flowchart Of Csi Reception

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.6.17 Flowchart of CSI Reception Figure 5-18 shows the flow of reception. Figure 5-18 CSI Reception CSI00_Receive() Extract slave transmittable data count and set it in g_num g_num >= RX_NUM Enable interrupts cnt = 0 RX_NUM+1 cnt <=...
  • Page 36: Flowchart Of Wait For Slave Response

    RL78/G13 Handshake-based SPI Master Transmission/Reception 5.6.18 Flowchart of Wait for Slave Response Figure 5-19 shows the flow of wait for slave response. Figure 5-19 Wait for Slave Response wait() Timer array unit 0 Channel 3 Start operation of lower 8 bits...
  • Page 37: Sample Code

    7. Reference Documents RL78/G13 User’s Manual: Hardware (R01UH0146J) RL78 family user's manual software (R01US0015) The latest versions can be downloaded from the Renesas Electronics website. Technical update The latest versions can be downloaded from the Renesas Electronics website. All trademarks and registered trademarks are the property of their respective owners.
  • Page 38 RL78/G13 Handshake-based SPI Master Transmission/Reception Revision History Description Rev. Date Page Summary 1.00 2023.6.15 First Edition R01AN6883EJ0100 Rev.1.00 Page 38 of 38 June.15.23...
  • Page 39 Unit Products The following usage notes are applicable to all Microprocessing unit and Microcontroller unit products from Renesas. For detailed usage notes on the products covered by this document, refer to the relevant sections of the document as well as any technical updates that have been issued for the products.
  • Page 40 Renesas Electronics disclaims any and all liability for any damages or losses incurred by you or any third parties arising from the use of any Renesas Electronics product that is inconsistent with any Renesas Electronics data sheet, user’s manual or other Renesas Electronics document.

Table of Contents