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

nRF52 changing PIO from Analog to Digital Output

Dear Wang,

I am unable find any documentation and board Initialisation code on how to change PIO from analog to digital output. but can't seem to locate the setting.

Need PIO1 to operate in Digital mode. And similarly other PIOs as well.

Regards, jagadish.H

Parents
  • Hi,

    There are no analog outputs on the nRF52, as this would require a DAC. The closest to analog output will be to output PWM signals on the pins.

    Take a look at the GPIO abstraction API documentation about how to configure GPIO. The simples configuration of an output would be to call the function nrf_gpio_cfg_output(uint32_t pin_number).

    Best regards,

    Jørgen

  • Hi,

    Within the same code (the overall project is trying to use PIO1 as chip select for the flash), I am not able to toggle the PIO22 (like below) also, without commenting out nrf_drv_spi_init and nrf_drv_spi_transfer. This code is the spi example from keil5 with SPI pins reassigned from default to flash. Behaviour is identical to what we are observing on nRF52-DK.

    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG(SPI_INSTANCE);
    spi_config.ss_pin = SPI_CS_PIN;
    //APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler));
    		
    nrf_gpio_cfg_output(22);
        
    while(1)
    {
    			
    
            // Reset rx buffer and transfer done flag
            memset(m_rx_buf, 0, m_length);
            spi_xfer_done = false;
    	    m_tx_buf[0] = 0x5;
            m_length = 1;
    	    m_length2 = 4;
    	   m_rx_buf[0] = m_rx_buf[1] = m_rx_buf[2] = m_rx_buf[3] = 0xAA;
    	   //APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, m_length, m_rx_buf, m_length2));
    
    
            while(spi_xfer_done == false)
            {
                __SEV();
                __WFE();
                __WFE();
            }
    
            LEDS_INVERT(BSP_LED_0_MASK);
    	    nrf_delay_ms(1000);
    	    nrf_gpio_pin_toggle(22);
    

    }

    Thx, AmitKumar

Reply
  • Hi,

    Within the same code (the overall project is trying to use PIO1 as chip select for the flash), I am not able to toggle the PIO22 (like below) also, without commenting out nrf_drv_spi_init and nrf_drv_spi_transfer. This code is the spi example from keil5 with SPI pins reassigned from default to flash. Behaviour is identical to what we are observing on nRF52-DK.

    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG(SPI_INSTANCE);
    spi_config.ss_pin = SPI_CS_PIN;
    //APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler));
    		
    nrf_gpio_cfg_output(22);
        
    while(1)
    {
    			
    
            // Reset rx buffer and transfer done flag
            memset(m_rx_buf, 0, m_length);
            spi_xfer_done = false;
    	    m_tx_buf[0] = 0x5;
            m_length = 1;
    	    m_length2 = 4;
    	   m_rx_buf[0] = m_rx_buf[1] = m_rx_buf[2] = m_rx_buf[3] = 0xAA;
    	   //APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, m_length, m_rx_buf, m_length2));
    
    
            while(spi_xfer_done == false)
            {
                __SEV();
                __WFE();
                __WFE();
            }
    
            LEDS_INVERT(BSP_LED_0_MASK);
    	    nrf_delay_ms(1000);
    	    nrf_gpio_pin_toggle(22);
    

    }

    Thx, AmitKumar

Children
No Data
Related