This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nRF52832 mutiplexing SPI-sck pin as GPIOTE pin during system running

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 with 
    static 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

Parents
  • Not sure I understand what happens here, but can you tro to add and connect a spare GPIO to implement the gpiote functionality (connect it to the SCK pin)? If you buld with DEBUG you should possible get more information about the cause of the error in the fault_handler().

    Kenneth

Reply
  • Not sure I understand what happens here, but can you tro to add and connect a spare GPIO to implement the gpiote functionality (connect it to the SCK pin)? If you buld with DEBUG you should possible get more information about the cause of the error in the fault_handler().

    Kenneth

Children
  • Dear Kenneth,

    Sorry for confusing you, but the project requires one pin to act two roles(sck and gpiote). I need to switch between these two roles at certain circumnstances.

    Could this assumption possibly be achieved? 

    The problem I occurred is -- when I switch the role from sck to gpiote, the program will run into the gpiote handler although no trggering signal was applied on the pin. 

    FYR, previous codes shows the way I config/de-config the pin.

    Best regard,

    Ava

  • Have you measured the the pin logically just to check that there is no noise or ripple on the SCK pin? Does the gpiote handler execute multiple times or only once?

    Best regardes,
    Kenneth

Related