rust-embedded / embedded-hal

A Hardware Abstraction Layer (HAL) for embedded systems
Apache License 2.0
1.86k stars 185 forks source link

Shared SPI bus between devices with different SPI modes #608

Open dan-corneanu opened 2 weeks ago

dan-corneanu commented 2 weeks ago

I have a small board that has 2 devices attached to the same SPI bus

Each device has its own CS pin.

I am using the following two drivers

The problem that I am facing is that my program can only communicate with one of the devices because the SpiDevice can not change the mode of the SpiBus.

I think this design decision was discussed back in 2022 in this comment https://github.com/rust-embedded/embedded-hal/pull/351#issuecomment-1043686888.

Could you please advise on how I could address this problem in my code?

If interested in the code of my application you can have a look at this branch https://github.com/dan-corneanu/ad983x_signal_generator/tree/features/configure_ushell.

eldruin commented 1 week ago

At the moment this must be implemented in a HAL-specific way. The difficulty will depend on the HAL you are using (I cannot access your application repo) but it will probably involve rewriting a bit of embedded-hal-bus so that when a device is activated, the bus is reconfigured.

dan-corneanu commented 1 week ago

Have made it public.