While communicating with EEPROM through DSPI the DSPI B Peripheral Chip Select 0 is not set to High till all the bits are transmitted through DSPI B Serial Data Output pin. Please find the attached file for the waveform. Also find the code below of the configuration of DSPI B and read/ write functions to EEPROM. As per EEPROM write instruction timing diagram PCS to be high till all bits are transmitted
static void DSPI_B_Init(void)
{
DSPI_B.MCR.R = 0xC0010001;
DSPI_B_CTAR0 = 0x78021003;
DSPI_B.MCR.B.HALT = 0x1;
}
static void DSPI_GPIO_Init(void)
{
/*DSPI_B*/
SIU.PCR[105].R = 0x06D3; //DSPI_B_CS0 //Input
SIU.PCR[102].R = 0x06D3; //DSPI_B_SCK
SIU.PCR[104].R = 0x06D3; //DSPI_B_SOUT
SIU.PCR[103].R = 0x05D3; //DSPI_B_SIN
}
void WriteToEEPROM(uint16_t addr, uint16_t data)
{
uint32_t i = 0,Iter = 0,uSlaveData = 0,uMastereData = 0,uLastWord = 0;
uint32_t shift_addr = 0;
uint32_t finaldata = 0, temp = 0, tempdata = 0,temp1 = 0;
uint32_t Startdata = 0, Enddata =0;
DSPI_B.MCR.B.HALT = 0x1;
uMastereData = (0x80010000 | 0x1400);
DSPI_B.PUSHR.PUSHR.R = uMastereData;
uMastereData = (0x80010000 | 0xA5); //0xA5A5
DSPI_B.PUSHR.PUSHR.R = uMastereData;
DSPI_B.MCR.B.HALT = 0x0;
while((DSPI_B.SR.B.TCF == 0))//Wait for Tx complete
{}
}
void ReadFromEEPROM(uint16_t addr, uint16_t data)
{
uint32_t i = 0,Iter = 0,uSlaveData = 0,uMastereData = 0,uLastWord = 0;
uint32_t shift_addr = 0;
uint32_t finaldata = 0, temp = 0, tempdata = 0,temp1 = 0;
uint32_t Startdata = 0, Enddata =0;
uint16_t RecDataMaster[300] = 0;
DSPI_B.MCR.B.HALT = 0x1;
uMastereData = (0x80010000 | 0x3000);//0x1800 //READ 1 10 A9-A0 0x1800
DSPI_B.PUSHR.PUSHR.R = uMastereData;
DSPI_B.MCR.B.HALT = 0x0;
while((DSPI_B.SR.B.TCF == 0))//Wait for Tx complete
{}
for(i=0;i<=0xFF;i++)
{
;
}
for(i=0;i<0x4;i++)
{
while (DSPI_B.SR.B.RFDF != 1){} /* Wait for Receive FIFO Drain Flag = 1 */
//DSPI_B.MCR.B.HALT = 0x1;
RecDataMaster[i] = DSPI_B.POPR.R; /* Read data received by master SPI */
DSPI_B.SR.R = 0x90020000;//0x90020000; /* Clear TCF, RDRF, EOQ flags by writing 1 */
}
}
Hi, I made such example for communication between DSPI memory and external EEPROM, used device
is MPC5676R that is similar device with backward compatible DSPI module:
Try to see ho I did it, I believe it can help you.