Hello!
I am wandering how does the Arduino communicate via SPI with two or more sensors, each of which has its own library. I know that the peripheral selection happens with the CS setting. But how does it actually happen? If the two sensors have different libraries, then they are bound to have different event handlers on their SPI instances. What happens after that? Are the event handlers combined?
If the different libraries for hardware devices use different SPI settings then the librairies need to have implmented the recommended SPI.beginTransaction() command before each SPI access.
As I said, each SPI transaction will generate a completion event. Each library though, has a different event handling function for SPI events. When I combine the two libraries on one SPI, which event handler will be executed? Will both be executed?
You seem to assume that SPI is being handled by interrupt. This isn't usually the case. Most of the code I've seen cues up a transmission and then blocks waiting for it to end.
It is possible to do SPI using an interrupt. If you want to have more than one thing then whenever you engage your CS pin you attach the appropriate interrupt.
Because you have a single SPI , the only one SPI event handler can be installed at the time. So if you use a two libraries, and each of them want to install its own handler, the SPI will execute the handler, that was installed last.