<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 測(cè)試測(cè)量 > 設(shè)計(jì)應(yīng)用 > DMM電阻測(cè)量分析筆記三~ADS1232驅(qū)動(dòng)程序

          DMM電阻測(cè)量分析筆記三~ADS1232驅(qū)動(dòng)程序

          作者: 時(shí)間:2017-01-12 來(lái)源:網(wǎng)絡(luò) 收藏
          雖然一開始打算做的是四位半萬(wàn)用表,但是,我們的終極目標(biāo)是用高檔表—— 六位半,向經(jīng)典表王——安捷倫34401A學(xué)習(xí)。所以,我思前想后,LT2440無(wú)疑是最好的選擇,因?yàn)槠涫欠e分型ADC,溫漂夠小,但是其價(jià)格昂貴,所以我打算在后期六位半中使用,四位半試驗(yàn)階段就用TI的ADS1232,同是24位ADC,但ADS1232的淘寶價(jià)格是12元,與LT2440的幾十個(gè)大洋想比,還是很便宜的。

          下面是ADS1232的STM32驅(qū)動(dòng)程序。

          本文引用地址:http://www.ex-cimer.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;
          }


          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();