riscv-rust / e310x-hal

Implementation of the `embedded-hal` traits for E310x microcontrollers
17 stars 18 forks source link

SPI: switch CS between transfers #11

Closed laanwj closed 5 years ago

laanwj commented 5 years ago

I'm trying to use spi in the HAL. However, my board is wired such that the CS pin is used to switch between command and data mode between transfers. I don't think this is currently possible as spi.csid is only written in the constructor. Or is there something I'm missing?

Disasm commented 5 years ago

You can choose any of 4 hw-controlled chip selects as well as sw-controlled one. If you want to use sw-controlled chip-select, you should pass only 3 pins to Spi::spi1 and setup your CS pin as regular GPIO. For your case I'd recommend configuring CS pin as regular GPIO and using another pin as hw/sw-controlled slave-select.

laanwj commented 5 years ago

Ok, that would deviate from the C code I'm porting (which changes the CSID on the fly) but I'll give it a try to keep as as GPIO, thanks!

laanwj commented 5 years ago

I got this to work in the suggested fashion, thanks.