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.
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.
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:
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.
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.