Hi,
I am using nrf5340 with Zephyr and nrf connect sdk 1.7.0 to drive two SPI bus devices off the same bus.
I have no problem configuring the SPI bus using nrfx_spim as below, and can communicate with each device individually switching devices at compile time.
But I am having difficulty understanding how to switch devices at run time i..e changing the chip select pin. I have read that it cannot simply be changed in the config structure.
I assume I could could control the CS pin outside of the SPI api, or that I could reinit the whole driver instance every device switch. Neither of these are great solutions, especially given a DMA based process.
Given SPI is a multi device bus I would assume the api has support for changing CS pin without full reinitialization?
Is there a best practice way to deal with this for nrfx_spim?
//current init code
#define SPI_INSTANCE 1
static const nrfx_spim_t spim = NRFX_SPIM_INSTANCE(SPI_INSTANCE);
nrfx_spim_config_t spim_config =
NRFX_SPIM_DEFAULT_CONFIG(APP_SPIM_SCK_PIN, APP_SPIM_MOSI_PIN, APP_SPIM_MISO_PIN, APP_SPIM_CS_PIN);
spim_config.frequency=NRF_SPIM_FREQ_4M;
spim_config.mode=NRF_SPIM_MODE_0;
spim_config.bit_order=NRF_SPIM_BIT_ORDER_MSB_FIRST;
if (NRFX_SUCCESS !=nrfx_spim_init(&spim, &spim_config, spim_event_single_byte_handler, NULL)) {
print_jr("Init Failed\n");
LOG_DBG("Init Failed\n");
return 0;
}
manual_isr_setup();
Thanks in advance