Hi,
I initiated pin 28 as SCK of SPI as normal condition, and I'd like to switch pin 28 as GPIOTE while receiving a command via BLE.
Basically this is how I achieve this:
- I configure pin 28 as SPI_SCK as follow
static void spi_init(bool speed) { nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG; spi_config.miso_pin = FLASH_MISO; spi_config.mosi_pin = FLASH_MOSI; spi_config.sck_pin = FLASH_SCK; if(speed == LOW_SPD) spi_config.frequency= NRF_DRV_SPI_FREQ_250K; else spi_config.frequency= NRF_DRV_SPI_FREQ_8M; spi_config.mode = NRF_DRV_SPI_MODE_0; APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, NULL, NULL)); }
- When receiving the command, I'll deinit pin 28 with
nrf_drv_spi_uninit(&spi);
and initialize it as GPIOTE withstatic void reset_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { reset_flag = true; } void SYNC_init() { ret_code_t err_code; if (!nrf_drv_gpiote_is_init()) { err_code = nrf_drv_gpiote_init(); } //RESET nrf_drv_gpiote_in_config_t reset_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true); reset_config.pull = NRF_GPIO_PIN_PULLDOWN; err_code = nrf_drv_gpiote_in_init(RESET_IN, &reset_config, reset_handler); APP_ERROR_CHECK(err_code); nrf_drv_gpiote_in_event_enable(RESET_IN, true); }(RESET_IN is the same pin with SPI_SCK)
But the problem is, system runs into the reset_handler immediatedly after pin 28 is set to GPIOTE. I've tried to add delay or to set trigger to HITOLO/LOTOHI but it appears still.
SPI is connected to an sd_flash which supplied by an independent LDO, I turned the LDO off after deinit the SPI_SCK. What might be the cause? If more information is needed, please let me know.
Thanks,
Ava