Hello, everyone
I now use RSPI duplex to do transmission and reception. (SPI Slave mode)
But I have not been successful in receiving data and transmitting data
Here's my code.
-----------------------------------------------------------------------------------------------------
void RSPI_Init(void) //Slave{ //Set input/output ports PORTA.DDR.BIT.B5=1; // MISO 1: output 0: input //PORTA.ICR.BIT.B5=1; // 1: MISO pin = input PORTA.DDR.BIT.B4=0; // CLK 1: output 0: input //PORTA.ICR.BIT.B4=1; // 1: CLK pin = input PORTA.DDR.BIT.B3=0; // CS (SSL0) 1: output 0: input //PORTA.ICR.BIT.B3=1; // 1: CS pin = input PORTB.DDR.BIT.B0=0; // MOSI 1: output 0: input //PORTB.ICR.BIT.B0=1; // 1: MOSI pin = input IOPORT.PFHSPI.BIT.RSPIS=1; //select MOSI-B, MISO-B, CLK-B, SSL0-B IOPORT.PFGSPI.BIT.RSPCKE=1; //enable CLK IOPORT.PFGSPI.BIT.MISOE=1; //enable MISO IOPORT.PFGSPI.BIT.MOSIE=1; //enable MOSI IOPORT.PFGSPI.BIT.SSL0E=1; //enable CS /* Cancel RSPI module stop state */ MSTP(RSPI0) = 0; //enable RSPI /* Disable RSPI interrupts */ IR(RSPI0,SPTI0)=0; //clear flag //Disable SPTI0 interrupt IR(RSPI0,SPRI0)=0; //clear flag //Disable SPRI0 interrupt /* Disable RSPI function */ RSPI0.SPCR.BIT.SPE = 0; //RSPI0.SPPCR.BYTE = 0x00; RSPI0.SPPCR.BIT.MOIFV=1; //MOSI idle =1 RSPI0.SPPCR.BIT.MOIFE=1; //reset MOSI idle =1 //Set the bit rate RSPI0.SPBR = 0; //25MHz //Set MSB first. Set data length. Set clock phase. Set clock polarity. RSPI0.SPCMD0.BIT.CPHA = 1; //1: Data variation on falling edge, 0: data sampling on rising edge RSPI0.SPCMD0.BIT.CPOL = 1; //0: RSPCK = 0 when idle RSPI0.SPCMD0.BIT.BRDV = 0; //00: These bits select the base bit rate RSPI0.SPCMD0.BIT.SPB = 0xf; //f= 1 1 1 1: 16 bits RSPI0.SPCMD0.BIT.LSBF = 0; //0: MSB first //Set slave mode. Set mode fault error detection. Set interrupt mask. Set RSPI mode RSPI0.SPCR.BIT.SPMS=0; //SPI mode RSPI0.SPCR.BIT.TXMD=0; //0: Full-duplex synchronous serial communications RSPI0.SPCR.BIT.SPE=1; //enable SPI RSPI0.SPCR.BIT.MSTR=0; //0: slave mode 1: Master
}
void RSPI_SendReceive(long*w_data,long num, long*r_data){ RSPI0.SPDR.LONG = (*w_data)<<16; // Set write data. while(IR(RSPI0,SPRI0)==1); // Receive buffer full *r_data = RSPI0.SPDR.LONG; // read write data. IR(RSPI0,SPRI0)=0; //clear flag}
-----------------------------------------------------------------------------------------------------------
Can anyone give me some advice that can solve this problem?
Thx a lot!!!
In reply to JB:
I suggest you try the FIT RSPI driver module. It will do your full duplex and supports slave mode with no code development needed.
Or at least study it for reference. https://www.renesas.com/en-us/software/D6000896.html