SPI data lost at low frequency of bus

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

plyatov
Posts: 25
Joined: Tue Feb 25, 2014 10:24 am
Been thanked: 2 times

SPI data lost at low frequency of bus

Postby plyatov » Wed Sep 14, 2016 8:47 am

Hello everybody!

Please suggest how to understand what is going on and how to resolve issue.

I use STM32F4xx platform (STM32F427VI at 180 MHz), ChibiOS_16.1.5 and have issue with SPI data integrity at low bitrates.

Configuration and handling of SPI is following:

Code: Select all

SPIDriver *spi_drv_dac8562 = &SPID4;

void spi_cb_dac8562(SPIDriver *spip)
{
   (void)spip;
   
   chSysLockFromISR();
   spiUnselectI(spi_drv_dac8562);
   chSysUnlockFromISR();
}

SPIConfig spi_cfg_dac8562 = {
   .end_cb      = spi_cb_dac8562,
   .ssport      = GPIOB,
   .sspad      = GPIOB_DAC0_CS,
   .cr1      = SPI_CR1_BR_1 | \
           SPI_CR1_CPHA // 90 MHz / 4 = 11.25 MHz, SPI_MODE_1
};

void dac8562_en_vref(bool enable)
{
   (void)enable;
   uint8_t buf[3];

   buf[0] = 0xAA;
   buf[1] = 0x55;
   buf[2] = 0x33;

   spiSelect(spi_drv_dac8562);
   spiStartSend(spi_drv_dac8562, ARRAY_ITEMS(buf), buf);
   //while (spi_drv_dac8562->state != SPI_READY);
   //spiUnselect(spi_drv_dac8562);
}


If bus speed is high (11.25 MHz), then data transmitted fine, but if I decrease bus speed for example to 351 KHz, then last byte (buf[2]) is zeroed always.
I've checked this issue with help of logical analyser.

P.S. I can't use busy-waiting by "while (spi_drv_dac8562->state != SPI_READY);" to unselect bus, because this broke device responsiveness/performance. Callback is much better solution for performance.
--
Igor

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: SPI data lost at low frequency of bus

Postby Giovanni » Wed Sep 14, 2016 9:07 am

Could you try spiSend() without callback? it returns when the transfer is over.

Giovanni

plyatov
Posts: 25
Joined: Tue Feb 25, 2014 10:24 am
Been thanked: 2 times

Re: SPI data lost at low frequency of bus

Postby plyatov » Wed Sep 14, 2016 11:04 am

Could you try spiSend() without callback? it returns when the transfer is over.


Yes, Giovanni of course spiSend() works fine and does not distort data at any bitrate, but it is synchronous.

I need to use asynchronous functions and understand why they does not work as expected or what is wrong made by me in their usage.

Any other suggestions?

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: SPI data lost at low frequency of bus

Postby Giovanni » Wed Sep 14, 2016 12:20 pm

The problem is that your buffer is an automatic variable, when you exit the function the buffer no more exists and it is overwritten.

Giovanni

plyatov
Posts: 25
Joined: Tue Feb 25, 2014 10:24 am
Been thanked: 2 times

Re: SPI data lost at low frequency of bus

Postby plyatov » Wed Sep 14, 2016 1:16 pm

Dear Giovanni,

thank you very much!

I completely forget about lifetime of such variables and even does not pay attention to this fact.

Now everything works as expected.

Best wishes.
--
Igor


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 21 guests