Hello,
i'm trying to understand how the management of the SS pin is (or has to be) performed when using nrf9160 as SPI master.
In this post Håkon said that:
"Most driver implementations has its own property for SS pin, as this is essentially a GPIO output that is set/cleared (SPIM doesn't have a dedicated hardware CSN/SS pin). The nrfx_spim driver itself supports handling the SS pin, but this is disabled for the zephyr SPI port layer: https://github.com/NordicPlayground/fw-nrfconnect-zephyr/blob/master/drivers/spi/spi_nrfx_spim.c#L411" "
So i have to implement my own SS-pin management and that's generally fine. It's here that i become confused. In the SPI API provided is defined this:
struct spi_config {
u32_t frequency;
u16_t operation;
u16_t slave;
const struct spi_cs_control *cs;
};
where:
struct spi_cs_control {
struct device *gpio_dev;
u32_t gpio_pin;
u32_t delay;
};
Have the struct elements "operation" (it has cs_active_high option) and "spi_cs_control" have any effect on the behaviour of the ss-pin? Does it effectively pull the pin high/low? Or i can leave these struct empty because this part is disabled?
In the case these struct elements are ineffective, i suppose this is the summarized way to proceed:
//NOT REAL CODE, JUST TO SUMMARIZE OPERATIONS
void spi_dev_write(spi_dev, spi_cfg, gpio_ss_dev, ss_pin, ) {
gpio_pin_write(gpio_ss_dev, ss_pin, 0); //PULL CS LOW
err = spi_write(spi_dev, spi_cfg, const struct spi_buf_set tx); //WRITE
gpio_pin_write(gpio_ss_dev, ss_pin, 1); //PULL CS HIGH
}
Am i correct?
Thanks,
frax