Hi,
I want to realize SPI communication, but I have only one MPC5604C.Then I use the master mode to realize a self-send and self-recive SPI communication function, What I want is a periodicaly send and receive funciton,but it can only self-send and self-recive one time. Following was the code without-Interrupt I modified from the CodeWarrior sample.When the functions in while() in main() is called again, the returned data is 0x0000.Can any one help find the problem in the code ? I think we may need Interrupt, and can you provide examples using Interrupt ?
void initModesAndClks(void) {
ME.MER.R = 0x0000001D; /* Enable DRUN, RUN0, SAFE, RESET modes */
/* Initialize PLL before turning it on: */
CGM.FMPLL_CR.R = 0x02400100; /* 8 MHz xtal: Set PLL0 to 64 MHz */
ME.RUN[0].R = 0x001F0074; /* RUN0 cfg: 16MHzIRCON,OSC0ON,PLL0ON,syclk=PLL */
ME.RUNPC[1].R = 0x00000010; /* Peri. Cfg. 1 settings: only run in RUN0 mode */
ME.PCTL[4].R = 0x01; /* MPC56xxB/P/S DSPI0: select ME.RUNPC[1] */
ME.PCTL[5].R = 0x01; /* MPC56xxB/P/S DSPI1: select ME.RUNPC[1] */
ME.PCTL[68].R = 0x01; /* MPC56xxB/S SIUL: select ME.RUNPC[0] */
/* Mode Transition to enter RUN0 mode: */
ME.MCTL.R = 0x40005AF0; /* Enter RUN0 Mode & Key */
ME.MCTL.R = 0x4000A50F; /* Enter RUN0 Mode & Inverted Key */
while (ME.GS.B.S_MTRANS) {} /* Wait for mode transition to complete */
/* Note: could wait here using timer and/or I_TC IRQ */
while(ME.GS.B.S_CURRENTMODE != 4) {} /* Verify RUN0 is the current mode */
}
void initPeriClkGen(void) {
/* Use the following code as required for MPC56xxB or MPC56xxS:*/
CGM.SC_DC[1].R = 0x80; ; /* MPC56xxB/S: Enable peri set 2 sysclk divided by 1 */
}
void disableWatchdog(void) {
SWT.SR.R = 0x0000c520; /* Write keys to clear soft lock bit */
SWT.SR.R = 0x0000d928;
SWT.CR.R = 0x8000010A; /* Clear watchdog enable (WEN) */
}
void initDSPI_0(void) {
DSPI_0.MCR.R = 0x80010001; /* Configure DSPI_0 as master */
DSPI_0.CTAR[0].R = 0x780A7727; /* Configure CTAR0 */
DSPI_0.MCR.B.HALT = 0x0; /* Exit HALT mode: go from STOPPED to RUNNING state*/
SIU.PCR[13].R = 0x0604; /* MPC56xxB: Config pad as DSPI_0 SOUT output */
SIU.PCR[12].R = 0x0103; /* MPC56xxB: Config pad as DSPI_0 SIN input */
SIU.PCR[14].R = 0x0604; /* MPC56xxB: Config pad as DSPI_0 SCK output */
SIU.PCR[15].R = 0x0604; /* MPC56xxB: Config pad as DSPI_0 PCS0 output */
}
void ReadDataDSPI_0(void) {
while (DSPI_0.SR.B.RFDF != 1){} /* Wait for Receive FIFO Drain Flag = 1 */
RecDataMaster = DSPI_0.POPR.R; /* Read data received by master SPI */
DSPI_0.SR.R = 0x90020000; /* Clear TCF, RDRF, EOQ flags by writing 1 */
}
int main(void) {
initModesAndClks(); /* Initialize mode entries and system clock, PLL */
initPeriClkGen(); /* Initize peripheral clock generation for DSPIs */
disableWatchdog(); /* Disable watchdog */
initDSPI_0(); /* Initialize DSPI_0 as master SPI and init CTAR0 */
while (1) {
i++;
DSPI_0.PUSHR.R = 0x08015678; /* Transmit data from master to slave SPI with EOQ */
ReadDataDSPI_0(); /* Read data on master DSPI */
} /* Wait forever */
}