SPI problem using 2 controllers

20 Aug 2015

Hi,

Im using a NUCLEO_F103RB board, with one device connected in SPI1 bus, and another device connected in SPI2 bus.

After accessing the device in SPI1, I got only zeros from the device in SPI2.

To fix this, I had to stop calling the aquire() function when writing to the devices, in libraries/mbed/common/SPI.cpp:

SPI.cpp

 int SPI::write(int value) {
//    aquire();
     return spi_master_write(&_spi, value);
 }

I dont know the side effects of doing this, but now it is working.

Any ideas?

Cheers,

20 Aug 2015

More information about the problem, I have something like this:

app.cpp

SPI dev1(PA_7, PA_6, PA_5, PA_4);
SPI dev2(PB_15, PB_14, PB_13, PB_12);

And in Mbed SPI:

SPI.cpp

// ignore the fact there are multiple physical spis, and always update if it wasnt us last
void SPI::aquire() {
     if (_owner != this) {
        spi_format(&_spi, _bits, _mode, 0);
        spi_frequency(&_spi, _hz);
        _owner = this;
    }
}

Debugging, I saw that in SPI::aquire(), the SPI instance dev1 is always _owner != this, and also different from NULL.

And for dev2, _owner == this.

I didnt understand the _owner/SPI::_owner trick....

Cheers,