SPI ICs usually have an active low chip select pin (~CS, nCS, ...).
I have a Texas Instruments IC (stepper motor driver DRV8711) that has an active high CS.
Initially, I bit-banged the CS pin: set it high with the GPIO API before communication, and low when finished.
This is also what the Raspberry Pico SPI examples do.
gpio_init(PICO_DEFAULT_SPI_CSN_PIN);
gpio_put(PICO_DEFAULT_SPI_CSN_PIN, 0);
gpio_set_dir(PICO_DEFAULT_SPI_CSN_PIN, GPIO_OUT);
void write(uint16_t reg){
gpio_put(PICO_DEFAULT_SPI_CSN_PIN, 1); // add a few NOPs to stretch the time
spi_write16_blocking(spi_default, ®, 1);
gpio_put(PICO_DEFAULT_SPI_CSN_PIN, 0); // add a few NOPss to stretch the time
}
This works, but I'd prefer to use the full SPI native driver functionality, if possible.
Invert CS behaviour of native Pico SPI driver
I found that you can inverse behaviour of GPIO pins. As it turns out, this also works for pins that are set to a SPI function:
// CS is active-high, invert pin action
gpio_set_function(PICO_DEFAULT_SPI_CSN_PIN, GPIO_FUNC_SPI);
gpio_set_outover(PICO_DEFAULT_SPI_CSN_PIN, GPIO_OVERRIDE_INVERT );
void write(uint16_t reg){
spi_write16_blocking(spi_default, ®, 1);
}
Here is a capture of a conversation, fully managed by the SPI API command spi_write16_blocking().
The CS is active high, as needed by the DRV8711 pin.