新聞中心

        EEPW首頁 > 測試測量 > 設計應用 > DMM電阻測量分析筆記三~ADS1232驅動程序

        DMM電阻測量分析筆記三~ADS1232驅動程序

        作者: 時間:2017-01-12 來源:網絡 收藏
        雖然一開始打算做的是四位半萬用表,但是,我們的終極目標是用高檔表—— 六位半,向經典表王——安捷倫34401A學習。所以,我思前想后,LT2440無疑是最好的選擇,因為其是積分型ADC,溫漂夠小,但是其價格昂貴,所以我打算在后期六位半中使用,四位半試驗階段就用TI的ADS1232,同是24位ADC,但ADS1232的淘寶價格是12元,與LT2440的幾十個大洋想比,還是很便宜的。

        下面是ADS1232的STM32驅動程序

        本文引用地址:http://www.104case.com/article/201701/338045.htm

        #include"stm32f10x.h"
        #include"delay.h"
        #include"ads1232.h"
        extern unsigned char flag;
        #define DOUT GPIO_Pin_0
        #define SCLK GPIO_Pin_1
        #define PDWN GPIO_Pin_2
        #define SPEED GPIO_Pin_3
        #define GAIN0 GPIO_Pin_4
        #define GAIN1 GPIO_Pin_5
        #define A0 GPIO_Pin_6
        #define ADPORT GPIOB
        #define DOUT_H GPIO_SetBits(ADPORT,DOUT)
        #define DOUT_L GPIO_ResetBits(ADPORT,DOUT)
        #define SCLK_H GPIO_SetBits(ADPORT,SCLK)
        #define SCLK_L GPIO_ResetBits(ADPORT,SCLK)
        #define SPEED_H GPIO_SetBits(ADPORT,SPEED)
        #define SPEED_L GPIO_ResetBits(ADPORT,SPEED)
        #define PDWN_H GPIO_SetBits(ADPORT,PDWN)
        #define PDWN_L GPIO_ResetBits(ADPORT,PDWN)
        #define A0_H GPIO_SetBits(ADPORT,A0) //AIN 2
        #define A0_L GPIO_ResetBits(ADPORT,A0) //AIN 1
        #define GAIN_1 GPIO_ResetBits(ADPORT,GAIN0|GAIN1);
        /****************************************************
        *function name: void AD_InitIO(void)
        *description : AD GPIO Initialization,PB0-DOUT,PB1-SCLK
        *input : null
        *output : null
        *return ºnull
        ******************************************************/
        void AD_InitIO(void)
        {
        GPIO_InitTypeDef GPIO_InitStructure;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
        GPIO_InitStructure.GPIO_Pin=SCLK;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
        GPIO_Init(ADPORT,&GPIO_InitStructure);
        }
        /****************************************************
        *function name: void DOUT_IN(void)
        *description : ADS1232s DOUT PB0 config input
        *input : null
        *output : null
        *return ºnull
        ******************************************************/
        void DOUT_IN(void)
        {
        GPIO_InitTypeDef GPIO_InitStructure;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
        GPIO_InitStructure.GPIO_Pin=DOUT;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU; //ÉÏÀ­ÊäÈë
        GPIO_Init(ADPORT,&GPIO_InitStructure);
        }
        /****************************************************
        *function name: void DOUT_OUT(void)
        *description : ADS1232s DOUT PB0 config input
        *input : null
        *output : null
        *return ºnull
        ******************************************************/
        void DOUT_OUT(void)
        {
        GPIO_InitTypeDef GPIO_InitStructure;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
        GPIO_InitStructure.GPIO_Pin=DOUT;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
        GPIO_Init(ADPORT,&GPIO_InitStructure);
        }
        /****************************************************
        *function name: unsigned long AD_read(void)
        *description : read AD data
        *input : null
        *output : null
        *return ºnull
        ******************************************************/
        unsigned long AD_read(unsigned char channel)
        {
        int i=0;
        unsigned long ad_value=0;
        AD_InitIO();
        SCLK_L;
        PDWN_L;
        delay_us(20);
        if(channel == 1)
        {
        A0_L; //AIN1
        }
        else
        {
        A0_H; //AIN2
        }
        GAIN_1;
        SPEED_H; //80SPS
        PDWN_H;
        delay_us(20);
        // DOUT_OUT();
        // DOUT_H;
        // delay_us(1);
        DOUT_IN();
        while(GPIO_ReadInputDataBit(ADPORT,DOUT)==1);
        //delay_ms(200);
        flag=1;
        for(i=0;i<24;i++)
        {
        ad_value=ad_value<<1;
        SCLK_H;
        delay_us(2);
        if(GPIO_ReadInputDataBit(ADPORT,DOUT)==1)
        {
        ad_value|=0x00000001; //or ad_value+=1;
        }
        else
        SCLK_L;
        delay_us(2);
        }
        SCLK_H;
        delay_us(2);
        SCLK_L;
        delay_ms(1);
        return ad_value;
        }


        評論


        技術專區

        關閉
        主站蜘蛛池模板: 呼伦贝尔市| 贺州市| 孟村| 灵石县| 深泽县| 内乡县| 永和县| 宝兴县| 大同县| 潮州市| 石嘴山市| 淮安市| 阿克苏市| 图片| 滁州市| 封开县| 始兴县| 涪陵区| 南涧| 福泉市| 民乐县| 刚察县| 仲巴县| 开阳县| 文登市| 牙克石市| 德清县| 洞头县| 土默特左旗| 神池县| 万州区| 开鲁县| 城口县| 微博| 中牟县| 自贡市| 高邑县| 阿城市| 会东县| 昌都县| 仁布县|