Multiple SPI slave initialization. Strange behaviour

Hello !
I am using Mbed OS 6.17 with MAX32630FTHR and 2 SPI slave devices (also MAX*) connected as shared SPI bus with 2 different CS pins to talk to them. Let’s name them as slave A and slave B.
When I initialize slaves A then B - everything goes very fast (in a second or less) and both devices print correct firmware/revision_id information.
When I initialize them B then A - it goes really bad. Sometimes B doesn’t initialize at all or it takes 10-15 second to get correct firmware version from the register. Printing out data shows it is either all 0 or random data. Output is unstable.

Initialization procedure is very simple: read status/information register and that is all.
The only difference for slave A is it also registers interrupt routine while B - doesn’t yet. I am not using interrupts anywhere yet and to my understanding it shouldn’t affect.
Can this be a reason for such a strange behavior? I am trying to get as simple code as possible in the beginning and this situation is confusing.

Thanks!

Hello there,

See in my opinion you should simplify your code as much as possible to isolate the issue. Remove any unnecessary functionality or complexity, such as interrupt handling, to see if the problem persists in a more basic configuration.

I have to simplify 3-rd party library from mbed site to simplify it even more. I have 5-10 lines of my own code and the rest is imported.
Hope I shouldn’t go to mbed-os source code to understand why it is happening… If I don’t get the answer I will simply use proven initialization sequence A than B that works well.

Hello,

Would be cool to share what libraries do you use

BR, Jan

MAX32630FTHR for the board and MAX8614X as library “A” that makes 2nd library initialization easy.

And what is the second slave?

BR, Jan

Second SPI slave is MAX30002

and any library?..

There is not specific for this chip. I am writing my own. Just SPI initialization and INFO register reading.

How exactly?
Slaves on same bus should have same format, same frequency and ideally use same SPI object.
So i suppose you have something like below for example:

SPI spi(SPI0_MOSI, SPI0_MISO, SPI0_SCK);
spi.format(8,0);
spi.frequency(1000000);
MAX8614X slaveA(&spi, ....);
MAX30002 slaveB(&spi, ....);
DigitalOut slaveA_CS(D10);
DigitalOut slaveB_CS(D11);

BR, Jan

Exactly like this, Jan. Shared SPI object. The only difference I have is DigitalOut slaveA(P5_3) and slaveB(P5_4) according to MAX32630FHR board pins to select chip.
The problem appears in the next step. If I try to read revision ID from the device A first it goes fast (though with errors sometimes) and reading rev id from device B afterwards – smoothly. If I try to read rev ID from device B first than it may not even happen… Very unstable.

I see nothing there. Maybe try to use two SPI buses, for each slave one bus. This will show if this is an issue around shared SPI bus or not.

BR, Jan

Thank you, Jan, I can do it only in the next board revision. Will use this workaround to test.

Oh, you do not have dev board with a breadboard or similar possibility?

BR, Jan

This is development board assembled by myself and fit into hard dimentional requirements. Has to be run on different CPU.
In the future product SPI must be shared. Not enough ports to have 2 different SPI lines. But I believe it is not a problem of the SPI as such, IC’s of wiring. Software. Hope I can find the reason, but if not this sequence A->B works fine for prototype.