adc

作者: 昨天剩下的一杯冷茶 | 来源:发表于2020-07-03 11:17 被阅读0次

    代码下载地址:

    https://download.csdn.net/download/qq_31806069/12572633

    芯片的P03引脚加入3.3V时读出1020,接入地时读出为0

    int main(void)
    {
    
        uint16_t adc;
        char buf[30];
        simple_uart_config(0xff,9,0xff,11,false);
        uart_exit();
        config_adc(AIN4_PIN03);
        
        while(1)
        {
    
            adc = Adc_Read();
            sprintf(buf,"adc:%d\r\n",adc);
            simple_uart_putstring((const uint8_t *)buf);
            nrf_delay_ms(1000);
        }
    }
    
    void config_adc(uint32_t AIN)
    {
        uint8_t tab[]={26,27,1,2,3,4,5,6};
        nrf_gpio_cfg_input(tab[AIN],NRF_GPIO_PIN_NOPULL);
        
        NRF_ADC->ENABLE = 0;
        NRF_ADC->CONFIG = (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos)
                          /*Bits 17..16 : ADC external reference pin selection. */
                          | ((1<<AIN) << ADC_CONFIG_PSEL_Pos)
                          /*!<Use analog input 2 as analog input. */
                          | (ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling << ADC_CONFIG_REFSEL_Pos)
                          /*!< Use internal 1.2V bandgap voltage as reference for conversion. */
                          | (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos)
                          /*!< Analog input specified by PSEL with no prescaling used as inputfor the conversion. */
                          | (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos);
        /*!< 8bit ADC resolution. */
        NRF_ADC->ENABLE = 1;
        
    
    }
    
    uint16_t Adc_Read(void)
    {
        uint16_t adc_data;
        NRF_ADC->TASKS_START = 1;
        while(NRF_ADC->EVENTS_END == 0);
        NRF_ADC->EVENTS_END = 0;
        adc_data = NRF_ADC->RESULT;
        NRF_ADC->TASKS_STOP = 1;
    
        
        return adc_data;
    }
    
    
    

    相关文章

      网友评论

          本文标题:adc

          本文链接:https://www.haomeiwen.com/subject/ultsqktx.html