I want to test the DSPI for MPC5645S device. Need to know how to perform spi loopback test. Hardware and software help required.
I have tried but didn't get any ouput. Can you please look at my code and let me know what I did wrong.
Even I tried connecting MISO and MOSI of DSPI_1 but I can't see output on logic analyzer.
/* Copyright FreeScale Semiconductor, Inc. 2007, 2009 All rights reserved. */
#include "MPC5645S.h" /* Use proper include file */
vuint32_t i = 0; /* Dummy idle counter */
uint16_t RecDataMaster = 0; /* Data recieved on master SPI */
uint16_t RecDataSlave = 0; /* Data received on slave SPI */
static void initModesAndClks(void) {
ME.MER.R = 0x0000001D; /* Enable DRUN, RUN0, SAFE, RESET modes */
/* Initialize PLL before turning it on: */
CGM.FMPLL[0].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[5].R = 0x01; /* MPC56xxB/P/S DSPI1: select ME.RUNPC[0] */
ME.PCTL[68].R = 0x0000; /* 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 */
}
static void initPeriClkGen(void) {
CGM.SC_DC[1].R = 0x80; /* MPC56xxB/S: Enable peri set 2 sysclk divided by 1 */
}
static 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) */
}
static void initDSPI_1(void) {
DSPI_1.MCR.R = 0x80010001; /* Configure DSPI_1 as Master */
DSPI_1.CTAR[0].R = 0x780A7727; /* Configure CTAR0 */
// DSPI_1.RSER.R = 0x00020000; //Interrupt enabled 0x80020000
DSPI_1.MCR.B.HALT = 0x0; /* Exit HALT mode: go from STOPPED to RUNNING state*/
SIU.PCR[20].R = 0x0604; /* MPC56xxS: Config pad as DSPI_1 SCK output */
SIU.PCR[22].R = 0x0503; /* MPC56xxS: Config pad as DSPI_1 SIN input */
SIU.PCR[21].R = 0x0604; /* MPC56xxS: Config pad as DSPI_1 SOUT output*/
SIU.PCR[43].R = 0x0E04; /* MPC56xxS: Config pad as DSPI_1 PCS0/SS output */
//SIU.PSMI[15].R = 0x00; /* MPC56xxS: Connect Pad PCR 43 to DSPI_1 SS input */
//DSPI_1.TCR.R = 0x00000000;
}
static void ReadDataDSPI_1(void) {
while (DSPI_1.SR.B.RFDF != 1){} /* Wait for Receive FIFO Drain Flag = 1 */
RecDataSlave = (unsigned short)DSPI_1.POPR.R; /* Read data received by slave SPI */
DSPI_1.SR.R = 0x0020000; /* Clear TCF, RDRF flags by writing 1 to them */
}
static void ReadDataDSPI_0(void) {
while (DSPI_0.SR.B.RFDF != 1){} /* Wait for Receive FIFO Drain Flag = 1 */
RecDataMaster = (unsigned short)DSPI_0.POPR.R; /* Read data received by master SPI */
DSPI_0.SR.R = 0x80020000; /* Clear TCF, RDRF, EOQ flags by writing 1 */
}
int main(void) {
initModesAndClks(); /* Initialize mode entries */
initPeriClkGen(); /* Initialize peripheral clock generation for DSPIs */
disableWatchdog(); /* Disable watchdog */
initDSPI_1(); /* Initialize DSPI_1 as Slave SPI and init CTAR0 */
DSPI_1.PUSHR.R = 0x08015678; /* Initialize slave DSPI_1's response to master */
ReadDataDSPI_1(); /* Read data on slave DSPI */
while (1) {i++; } /* Wait forever */
}
I would recommend to pay attention to AN2865, section 24:
I cannot connect DSPI_0 on reference MPC5645S board, it has already been used by some other function and pins are not free to connect with DSPI_1 . Can I connect MOSI of DSPI_1 with MISO of DSPI_1 for loopback.
Yes, you can.
No reply please help to get it resolved