Hi I'm building a battery-powered sensing device with Rust, based on the nRF52833.
For conserving power, I need to disable the SPI peripheral when not in use. Currently a nice solution for enabling/disabling peripherals is not provided in the nrf-hal (tracking #279), so for the moment I will be juggling the SPI in a wrapping enum encapsulating the enabled and disabled types/modes.
I ran into an unexpected problem though:
When initializing the SPI peripheral for the first time all works well!
Hi I'm building a battery-powered sensing device with Rust, based on the nRF52833.
For conserving power, I need to disable the SPI peripheral when not in use. Currently a nice solution for enabling/disabling peripherals is not provided in the nrf-hal (tracking #279), so for the moment I will be juggling the SPI in a wrapping
enum
encapsulating the enabled and disabled types/modes.I ran into an unexpected problem though:
free()
-ing the peripheral instance, the power usage drops as expected (side note: for anyone debugging inexplicable SPI power use, please be aware of: Erratum [195] SPIM: SPIM3 continues to draw current after disable)free
'd parts (spim and spins) can be made into a new spi instance, also good...write()
functions return without error, but nothing happens...It seems something is not working well when creating the new spim instance from the parts returned by
spidev.free()
Freeing and re-creating the SPI instance:
for completeness, initial initialization is done like this: