Hi everyone!
I have some questions about the SPI setting of TMS320F28379D.
I have tried to use the DSP as SPI master to write data to the slave piece named IVQ3005 part,but I can't get the right wave output from the slave part,and it seems that the slave part didn't receive any data.
1. The slave part only use the SPI_CLK , SPI_MOSI and a SPI_Chipselect wire,so I set the dsp SPI-A in the three-wire mode.So,what about the concerned GPIO 16~GPIO 19 setting?I tried to configure them as below,and Initial the SPIA with the function InitSpia() below in the mode :8-bit per char ,disable loopback,disable FIFO, three-wire enable:
void InitSpiaGpio() { EALLOW; // // Enable internal pull-up for the selected pins // // Pull-ups can be enabled or disabled by the user. // This will enable the pullups for the specified pins. // Comment out other unwanted lines. // GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0; // Enable pull-up on GPIO16 (SPISIMOA) // GpioCtrlRegs.GPAPUD.bit.GPIO5 = 0; // Enable pull-up on GPIO5 (SPISIMOA) GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up on GPIO17 (SPISOMIA) // GpioCtrlRegs.GPAPUD.bit.GPIO3 = 0; // Enable pull-up on GPIO3 (SPISOMIA) GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0; // Enable pull-up on GPIO18 (SPICLKA) // GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0; // Enable pull-up on GPIO19 (SPISTEA) // // Set qualification for selected pins to asynch only // // This will select asynch (no qualification) for the selected pins. // Comment out other unwanted lines. // GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3; // Asynch input GPIO16 (SPISIMOA) // GpioCtrlRegs.GPAQSEL1.bit.GPIO5 = 3; // Asynch input GPIO5 (SPISIMOA) GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch input GPIO17 (SPISOMIA) // GpioCtrlRegs.GPAQSEL1.bit.GPIO3 = 3; // Asynch input GPIO3 (SPISOMIA) GpioCtrlRegs.GPAQSEL2.bit.GPIO18 = 3; // Asynch input GPIO18 (SPICLKA) // GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 3; // Asynch input GPIO19 (SPISTEA) // //Configure SPI-A pins using GPIO regs // // This specifies which of the possible GPIO pins will be SPI functional // pins. // Comment out other unwanted lines. // GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1; // Configure GPIO16 as SPISIMOA // GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 2; // Configure GPIO5 as SPISIMOA GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1; // Configure GPIO17 as SPISOMIA // GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 2; // Configure GPIO3 as SPISOMIA GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1; // Configure GPIO18 as SPICLKA // GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 1; // Configure GPIO19 as SPISTEA EDIS; }
void InitSpia(void) { // Initialize SPI-A // Set reset low before configuration changes // Clock polarity (0 == rising, 1 == falling) // 16-bit character // Enable loop-back SpiaRegs.SPICCR.bit.SPISWRESET = 0; SpiaRegs.SPICCR.bit.CLKPOLARITY = 1; SpiaRegs.SPICCR.bit.SPICHAR = (8-1);//(16-1) SpiaRegs.SPICCR.bit.SPILBK = 0;//1;loopback disable(0) // Enable master (0 == slave, 1 == master) // Enable transmission (Talk) // Clock phase (0 == normal, 1 == delayed) // SPI interrupts are disabled SpiaRegs.SPICTL.bit.MASTER_SLAVE = 1; SpiaRegs.SPICTL.bit.TALK = 1; SpiaRegs.SPICTL.bit.CLK_PHASE = 1;//0 SpiaRegs.SPICTL.bit.SPIINTENA = 0; // Set the baud rate SpiaRegs.SPIBRR.bit.SPI_BIT_RATE = SPI1_BRR; // Set FREE bit // Halting on a breakpoint will not halt the SPI SpiaRegs.SPIPRI.bit.FREE = 1; SpiaRegs.SPIPRI.bit.TRIWIRE = 1;//SPI 3-wire mode enable SpiaRegs.SPIFFTX.bit.SPIFFENA = 0;//disable FIFO // Release the SPI from reset SpiaRegs.SPICCR.bit.SPISWRESET = 1; }
Is there any error in my code ?
2.The second question is whether the operation of writing a data to the TXBUF means the master transmit the data to the slave?Can the following code implement the function of transmit TxData via the MOSI to the slave?
uint8_t REF_SPI_ReadWriteByte(uint8_t TxData) { uint8_t dummy = 0; // waiting for the complement of previous character shifting while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG == 1) { } SpiaRegs.SPICTL.bit.TALK = 1; // Enable Transmit path SpiaRegs.SPITXBUF = TxData; // Master transmits data if(SPIA_FIFO) while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) {} // Waits until data rx’d--FIFO mode else while(SpiaRegs.SPISTS.bit.INT_FLAG !=1){}//Non-FIFO mode dummy = SpiaRegs.SPIRXBUF; // Clears junk data from itself bc it rx’d same data tx’d return dummy; }
3. The last question is, Is there a way to see if the SPI is working correctly?I have tried to add GpioDataRegs.GPADAT.bit.GPIO18(which has been configured as the SPICLKA) to Watch Variables during debug with CCS,but it seemd that the value hadn't changed ever even during master tring to trismit data.Did this means that the SPI didn't work correctly?How can I fix this problem?
Thanks a lot.