Hi Nordic,
I'm using NRF52832 to design a producation that needs four SPI interfaces.
The four spi peripherals are: gSensor, LCD, SPI Nor Flash, and PPG Sensor. Now I'm planning to make gSensor and LCD share to use SPI0, LCD uses SPI1, and PPG Sensor uses SPI2 repectively.
When design the schematic, each the above peripheral has its own IO pins. So I have to dynmaic switch the pins selection through nrf_drv_spi_uninit() and nrf_drv_spi_init().
void spi_share_int(const spi_share_pins_t* spi_hw_info) { if (spi_share_init_flag) { spi_share_init_flag = 0; SPI_REG->ENABLE = 0; SPI_REG->INTENCLR = 0; SPI_REG->INTENSET = 0; SPI_REG->PSEL.MISO = 0xFFFFFFFF; SPI_REG->PSEL.MOSI = 0xFFFFFFFF; SPI_REG->PSEL.SCK = 0xFFFFFFFF; SPI_REG->FREQUENCY = 0x04000000; SPI_REG->CONFIG = 0; SPI_REG->EVENTS_READY = 0; nrf_drv_spi_uninit(&spi_share); } if (spi_share_init_flag == 0) { spi_share_init_flag = 1; nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG(SPI_INSTANCE); spi_config.frequency = NRF_DRV_SPI_FREQ_500K; spi_config.miso_pin = spi_hw_info->miso_pin; spi_config.mosi_pin = spi_hw_info->mosi_pin; spi_config.sck_pin = spi_hw_info->clk_pin; spi_config.ss_pin = 0xFF; spi_config.mode = spi_hw_info->mode; APP_ERROR_CHECK(nrf_drv_spi_init(&spi_share, &spi_config, spi_event_handler)); } }
The above spi_share_init() function will be called before each spi communication on SPI0.
But I'm failed, APP_ERROR_CHECK will stop the application run when the program goes to the nrf_drv_spi_init().
Are there some similar usage examples, please kindly help me to solve the probem.
Thanks for any reply.