cancel
Showing results for 
Search instead for 
Did you mean: 

Need help No SPI Signal output

jannwaivut
Associate II
Posted on March 05, 2014 at 05:37

Something wrong with dspi ?

I have try debug with code for spi output signal with dspi module, it's not running. need some advide

this my code init :

void initDSPI(void){

SIU.ISEL2.R = 0x0;

DSPI_B.MCR.R = 0x80010000; // Configure DSPI_B as master

DSPI_B.CTAR0.R = 0x78003255;; // Configure CTAR0

//DSPI_B.MCR.B.HALT = 0x0; // Exit HALT mode: go from STOPPED to RUNNING state

SIU.PCR102.R = 0x0600; // DSPI_B_SCK

SIU.PCR103.R = 0x0500; // DSPI_B_SIN

SIU.PCR104.R = 0x0600; // DSPI_B_SOUT

SIU.PCR105.R = 0x0600; // DSPI_B_PCS[0]

}

and this one is code function, it's call in main program :

uint8_t EEPROM_WRITE_CMD(uint8_t cCmd, uint8_t cData){

uint8_t iloop;

if(cCmd == 1){

EEPROM_CS = EEPROM_ON;

DSPI_B.PUSHR.R = 0x08010000 | cData;

for(iloop=0;iloop<0xFF;iloop++);

EEPROM_CS = EEPROM_OFF;

return 0;

}

return 1;

}

thank you

Waivut J.

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
3 REPLIES 3
Erwan YVIN
ST Employee
Posted on March 10, 2014 at 11:36

Hello Waivut J ,

Could you confirm the Microcontroller unit used ?

For your information, there are some DSPI Test Applications in SPC5Studio 2.0

You can import it by using SPC5Studio Wizard (Novel Users)

I have put the source code in attachment (Low Level drivers and high level drivers)

Example of Test Application:

/*

* Application entry point.

*/

int main(void) {

unsigned i;

/* Initialization of all the imported components in the order specified in

the application wizard. The function is generated automatically.*/

componentsInit();

/* Prepare transmit pattern.*/

for (i = 0; i < sizeof(txbuf); i++)

txbuf[i] = (uint8_t)i;

/* Starting driver for test, DSPI_0 I/O pins setup.*/

spiStart(&SPID1, &spi_config_low_speed);

SIU.PCR[37].R = PAL_MODE_OUTPUT_ALTERNATE(1); /* SCK */

SIU.PCR[38].R = PAL_MODE_OUTPUT_ALTERNATE(1); /* SOUT */

SIU.PCR[36].R = PAL_MODE_OUTPUT_ALTERNATE(1); /* CS[0] */

SIU.PCR[54].R = PAL_MODE_OUTPUT_ALTERNATE(1); /* CS[2] */

/* Testing sending and receiving at the same time.*/

spiExchange(&SPID1, 4, txbuf, rxbuf);

spiExchange(&SPID1, 32, txbuf, rxbuf);

spiExchange(&SPID1, 512, txbuf, rxbuf);

/* Testing clock pulses without data buffering.*/

spiIgnore(&SPID1, 4);

spiIgnore(&SPID1, 32);

/* Testing sending data ignoring incoming data.*/

spiSend(&SPID1, 4, txbuf);

spiSend(&SPID1, 32, txbuf);

/* Testing receiving data while sending idle bits (high level).*/

spiReceive(&SPID1, 4, rxbuf);

spiReceive(&SPID1, 32, rxbuf);

/* Testing stop procedure.*/

spiStop(&SPID1);

/* Testing 16bits wide frames.*/

spiStart(&SPID1, &spi_config_low_speed_16);

spiExchange(&SPID1, 4, txbuf, rxbuf);

spiExchange(&SPID1, 32, txbuf, rxbuf);

spiExchange(&SPID1, 256, txbuf, rxbuf);

spiStop(&SPID1);

/* Application main loop, two SPI configuration are used alternating them.*/

while (1) {

palClearPad(PORT_D, PD_LED1); /* LED ON. */

spiStart(&SPID1, &spi_config_high_speed); /* Setup parameters. */

spiExchange(&SPID1, 512, txbuf, rxbuf);

palSetPad(PORT_D, PD_LED1); /* LED OFF. */

spiStart(&SPID1, &spi_config_low_speed); /* Setup parameters. */

spiExchange(&SPID1, 512, txbuf, rxbuf);

}

}

Example of Pre-Fill (in SPI LLD)

/**

* @brief Prefills the TX FIFO using 8 bits frames.

*

* @param[in] spip pointer to the @p SPIDriver object

* @param[in,out] np pointer to the number of frames to send, must be

* greater than zero, contains the number of remaining

* frames on return

* @param[in,out] txpp pointer to the pointer to the transmit buffer

*

* @notapi

*/

static void spi_dspi_prefill_txfifo8(SPIDriver *spip,

size_t *np,

const uint8_t **txpp) {

uint32_t cmd = spip->config->pushr;

while (spip->dspi->SR.B.TXCTR < SPC5_DSPI_FIFO_DEPTH) {

uint32_t frame = **txpp;

(*txpp)++;

if (--(*np) == 0) {

spip->dspi->PUSHR.R = (SPC5_PUSHR_EOQ | cmd | frame) & ~SPC5_PUSHR_CONT;

break;

}

spip->dspi->PUSHR.R = cmd | frame;

}

}

I advice you to herit from these SPI drivers or to update the test application ;)

Full source code are available in attachment

Best regards

Erwan YVIN

________________

Attachments :

SPC56ELxx_OS-Less_DSPI_Example_Application.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0V2&d=%2Fa%2F0X0000000bZl%2FdrsmS3os1vfcY.KaFZrsXjH5tRzZY6kwuJunXAjkPQ0&asPdf=false
jannwaivut
Associate II
Posted on March 11, 2014 at 07:58

Hi,

0690X0000060MoRQAU.gifThank youfor your advice. I found the problem now, I forgot to setslew rate control in siu_pcr for sck, sout and sin. and now spi is working.

ps. I used spc563m64 for my project.

Best regards

Waivut J.

Patriks
Senior
Posted on August 19, 2014 at 16:08

I have a similar problem with SPI on a SPC560D discovery board. I tired to understand the DSPI test application for the discovery board, but it seems that there is no SPI output signal generated.

For testing purpose, I added following line to the test application to configure the DSPI input pin.

SIU.

PCR

[12].

B

.

IBE

= 1;

//PA[12]

Then, I connected output(PCR[13]) and input(PCR[12]) and used the command

spiExchange(&SPID1, 32, txbuf, rxbuf);

to send the content of the txbuf variable (as it is already done in the test application). For my understanding the variable rxbuf should afterwards have the same content as txbuf within the first 32 elements. But in my case, the first 32 entries of rxbuf have the value 0xFF.

By the way, I found an error in the User Manual UM1681 for the SPC560D-DIS discovery board. The pinning of the I/O header shown in table 4 is not the same as shown in figure 14. There is at least one error e.g. at connector X2, pin 31. In the table it is PF[13] but in the figure it is PA[13].

Best regards,

Patrik