9 years, 1 month ago.

Switching SPI mode on the fly doesn't work with Nucleo-F334R8

I want to use two types of SPI devices. One works with mode 3 and another with 2. After third switching (mode 2 back to mode 3) the SPI doesn't work rirght. The SW chip select is set too early back to one. Why it isn't waited for the SPI_FLAG_RXNE? Has anyone the same problem?

Example:

  1. include "mbed.h"

SPI spi1(D11, NC, D13, NC); SPI spi2(D11, NC, D13, NC);

DigitalOut _CS1(D4,1); DigitalOut _CS2(D2,1);

int main() {

while(1) {

spi1.format(8,3); spi1.frequency(2000000); _CS1=0; spi1.write(0xAB); _CS1=1;

spi2.format(8,2); spi2.frequency(2000000); _CS2=0; spi2.write(0xFF); _CS2=1;

} }

1 Answer

9 years, 1 month ago.

Please use code tags around posted code to keep it readable.

The problem has been reported before. Use a short delay wait_us (1) between spi.write and raising of cs line. Maybe it would be better to just use two separate spi ports and avoid switching modes.