This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SPI with multiple chip selects

As I understand the SPI HW driver documentation, it appears to be at least biased for using a single chip select (slave select in the API). I have an application where I have 5 devices on the SPI bus.

Should I create an SPI master configuration structure for each of the 5 devices? Only the SPI_Pin_SS would be different in each of them, and I think I would need to close and open SPI to switch between the devices.

Or can I use a single structure with spi configuration function to configure the SPI pins (CLK, MOSI, MISO) and manually configure the chip selects? And then when I want to change device I want, just change the SPI_Pin_SS?

Another way? After reading RK's answer, began to wonder if could use GPIOTE to handle the multiple chip selects. Would it work to assign SPI_Pin_SS to an "unused" pin, and cofigure GPIOTE task to toggle desired CS when SPI toggles _SS ? I haven't explored GPIOTE at all yet so this may be a naive idea.

Parents
  • Hi

    Thank you for your feedback with your solution. By looking at the spi driver code, it seems to me that your solution is perfectly valid.

    To minimize the delay, you could call the spi_master_change_cs in the spi_master_event_handler. Then you will change the chip select pin as soon as the previous spi transaction finishes. Keep a single spi_send_recv function call in main, which should be called as soon as the spi_master_event_handler finishes execution.

Reply
  • Hi

    Thank you for your feedback with your solution. By looking at the spi driver code, it seems to me that your solution is perfectly valid.

    To minimize the delay, you could call the spi_master_change_cs in the spi_master_event_handler. Then you will change the chip select pin as soon as the previous spi transaction finishes. Keep a single spi_send_recv function call in main, which should be called as soon as the spi_master_event_handler finishes execution.

Children
Related