|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2013-6-1 08:03:08
|
显示全部楼层
z708875378 发表于 2013-5-29 09:23 ![](static/image/common/back.gif)
请发给我一份吧,我按照你这个配置了,但结果还是不正确。我想对照参考下,谢谢了。 ... - #define WakeUp 0x00 //退出睡眠模式
- #define Sleep 0x02 //进入睡眠模式
- #define SYNC 0x04 //同步A/D转换
- #define Reset 0x06 //复位上电
- #define NOP 0xff //无操作
- #define RData 0x12 //一次读取数据
- #define RDataC 0x14 //连续读取数据
- #define SDataC 0x16 //停止连续读取数据
- #define RReg 0x20 //读取寄存器
- #define WReg 0x40 //写寄存器
- #define SYSOCAL 0x60 //系统失调自校准
- #define SYSGCAL 0x61 //系统增益校准
- #define SELFOCAL 0x62 //自偏移校准
- #define Reg_MUX0 0x00 //
- #define Reg_VBias 0x01 //
- #define Reg_MUX1 0x02 //
- #define Reg_SYS0 0x03 //
- #define Reg_CFC0 0x04 //
- #define Reg_CFC1 0x05 //
- #define Reg_CFC2 0x06 //
- #define Reg_FSC0 0x07 //
- #define Reg_FSC1 0x08 //
- #define Reg_FSC2 0x09 //
- #define Reg_IDAC0 0x0a //
- #define Reg_IDAC1 0x0b //
- #define Reg_GPIOCFG 0x0c //
- #define Reg_GPIODIR 0x0d //
- #define Reg_GPIODAT 0x0e //
- #define ADS1247_MUX0 0x01 //AIN0(+)-AIN1(-)
- #define ADS1247_VBias 0x00 //不使用偏置电压
- #define ADS1247_MUX1 0x38 //外部参考REF,正常运行
- #define ADS1247_SYS0 0x00 //放大1倍,5Hz
- #define ADS1247_IDAC0 0x06 //1mA
- #define ADS1247_IDAC1 0x03 //电流从AIN0输出1mA
- #define ADS1247_DIN_CLR() GPIO_ResetBits(GPIOC,GPIO_Pin_7);
- #define ADS1247_DIN_SET() GPIO_SetBits(GPIOC,GPIO_Pin_7);
- #define ADS1247_SCLK_CLR() GPIO_ResetBits(GPIOC,GPIO_Pin_8);
- #define ADS1247_SCLK_SET() GPIO_SetBits(GPIOC,GPIO_Pin_8);
- #define ADS1247_CS_CLR() GPIO_ResetBits(GPIOC,GPIO_Pin_9);
- #define ADS1247_CS_SET() GPIO_SetBits(GPIOC,GPIO_Pin_9);
- #define ADS1247_DOut_CLR() GPIO_ResetBits(GPIOA,GPIO_Pin_8);
- #define ADS1247_DOut_SET() GPIO_SetBits(GPIOA,GPIO_Pin_8);
- #define ADS1247_DOut_Get() GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8)
- // #define ADS1247_RESET_CLR() GPIO_ResetBits(GPIOC,GPIO_Pin_1);
- // #define ADS1247_RESET_SET() GPIO_SetBits(GPIOC,GPIO_Pin_1);
- #define ADS1247_START_CLR() GPIO_ResetBits(GPIOB,GPIO_Pin_15);
- #define ADS1247_START_SET() GPIO_SetBits(GPIOB,GPIO_Pin_15);
- void ADS1247_GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC, ENABLE);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_8 | GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
-
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- ADS1247_DIN_SET();
- ADS1247_SCLK_SET();
- }
- void ADS1247_Delays(unsigned int count)//6us
- {
- uint16_t i,j;
- for(i=count;i>0;i--)
- for(j=12;j>0;j--);
- }
- void WriteByteADS1247(unsigned char x)//8BIT
- {
- unsigned char ii;
- for (ii=0; ii<8; ii++)
- {
- ADS1247_SCLK_SET();
- ADS1247_Delays(20);
- if(x & 0x80) { ADS1247_DIN_SET(); }
- else { ADS1247_DIN_CLR(); }
- ADS1247_Delays(20);
- ADS1247_SCLK_CLR();
- ADS1247_Delays(20);
- x <<=1;
- }
- ADS1247_DIN_SET();//这里必须把DIN线设为1否则,在读取AD值的时候会出错
- }
- void WriteWordADS1247(unsigned int x)//16BIT
- {
- unsigned char ii;
- for (ii=0; ii<16; ii++)
- {
- ADS1247_SCLK_SET();
- ADS1247_Delays(20);
- if(x & 0x8000){ ADS1247_DIN_SET(); }
- else { ADS1247_DIN_CLR(); }
- ADS1247_Delays(20);
- ADS1247_SCLK_CLR();
- ADS1247_Delays(20);
- x <<=1;
- }
- ADS1247_DIN_SET();
- }
- void WriteDWordADS1247(unsigned long int x)//24BIT
- {
- unsigned char ii;
- for (ii=0; ii<24; ii++)
- {
- ADS1247_SCLK_SET();
- ADS1247_Delays(20);
- if(x & 0x800000){ ADS1247_DIN_SET(); }
- else { ADS1247_DIN_CLR(); }
- ADS1247_Delays(20);
- ADS1247_SCLK_CLR();
- ADS1247_Delays(20);
- x <<=1;
- }
- ADS1247_DIN_SET();
- }
- unsigned char ReadByteADS1247(void)//8BIT
- {
- unsigned char ii;
- unsigned char x ;
-
- while(ADS1247_DOut_Get());
- for (ii = 0,x=0 ; ii < 8 ; ii++)
- {
- ADS1247_SCLK_SET();
- ADS1247_Delays(20);
- ADS1247_SCLK_CLR();
- x<<=1;
- if(ADS1247_DOut_Get())
- x |= 0x01;
- ADS1247_Delays(20);
- }
- return x;
- }
- unsigned int ReadWordADS1247(void)//16BIT
- {
- unsigned char ii;
- unsigned int x ;
- while(ADS1247_DOut_Get());
- for (ii = 0,x=0 ; ii < 16 ; ii++)
- {
- ADS1247_SCLK_SET();
- ADS1247_Delays(20);
- ADS1247_SCLK_CLR();
- x<<=1;
- if (ADS1247_DOut_Get())
- x |= 0x01;
- ADS1247_Delays(20);
- }
- return x;
- }
- unsigned long int ReadDWordADS1247(void)//24BIT
- {
- unsigned char ii;
- unsigned long int x ;
- for (ii = 0,x = 0 ; ii < 24 ; ii++)
- {
- ADS1247_SCLK_SET();
- ADS1247_Delays(20);
- ADS1247_SCLK_CLR();
- x<<=1;
- if (ADS1247_DOut_Get())
- x |= 0x01;
- ADS1247_Delays(20);
- }
- return x;
- }
- void ResetADS1247(void)
- {
- unsigned char ii;
- for(ii=0;ii<35;ii++)
- {
- ADS1247_SCLK_CLR();
- ADS1247_Delays(20);
- ADS1247_DIN_SET();
- ADS1247_Delays(20);
- ADS1247_SCLK_SET();
- ADS1247_Delays(20);
- }
- }
- unsigned char k;
- void ADS1247_Configuration(void)
- {
- ADS1247_GPIO_Configuration();
-
- ADS1247_CS_CLR();
- // ADS1247_RESET_SET();
- ADS1247_START_CLR();
-
- ADS1247_Delays(20);
- WriteByteADS1247(Reset);
- ADS1247_START_SET();
- ADS1247_Delays(1000);//300ms
-
- WriteByteADS1247(WReg|Reg_MUX0);
- WriteByteADS1247(0x00);
- WriteByteADS1247(ADS1247_MUX0);
-
- WriteByteADS1247(WReg|Reg_VBias);
- WriteByteADS1247(0x00);
- WriteByteADS1247(ADS1247_VBias);
-
- WriteByteADS1247(WReg|Reg_MUX1);
- WriteByteADS1247(0x00);
- WriteByteADS1247(ADS1247_MUX1);
-
- WriteByteADS1247(WReg|Reg_SYS0);
- WriteByteADS1247(0x00);
- WriteByteADS1247(ADS1247_SYS0);
-
- WriteByteADS1247(WReg|Reg_IDAC0);
- WriteByteADS1247(0x00);
- WriteByteADS1247(ADS1247_IDAC0);
- // ADS1247WREG(Reg_IDAC0,ADS1247_IDAC0);
-
- WriteByteADS1247(WReg|Reg_IDAC1);
- WriteByteADS1247(0x00);
- WriteByteADS1247(ADS1247_IDAC1);
-
- WriteByteADS1247(RReg|Reg_IDAC0);
- WriteByteADS1247(0x00);
- k = ReadByteADS1247();
-
- // ADS1247WREG(Reg_IDAC1,ADS1247_IDAC1);
- // k = ADS1247RREG(Reg_IDAC1);
- // k = ADS1247RREG(Reg_IDAC0);
-
- // WriteByteADS1247(0x14);
- // ADS1247_CS_SET();
- // ADS1247_START_SET();
- // delays(0xFFFFF);
- }
- unsigned int temp1247;
- void GetADS1247Data(void)
- {
- unsigned char Temp[9];
- unsigned int Temp24;
- while(ADS1247_DOut_Get());
- ADS1247_CS_CLR();
- WriteByteADS1247(0x12);
- temp1247 = ReadDWordADS1247();
- ADS1247_CS_SET();
-
- Temp24 = temp1247;
- Temp[0] = Temp24/10000000%10+0x30;
- Temp[1] = Temp24/1000000%10+0x30;
- Temp[2] = Temp24/100000%10+0x30;
- Temp[3] = Temp24/10000%10+0x30;
- Temp[4] = Temp24/1000%10+0x30;
- Temp[5] = Temp24/100%10+0x30;
- Temp[6] = Temp24/10%10+0x30;
- Temp[7] = Temp24%10+0x30;
- Temp[8] = 0;
- printf ("%s\r\n",Temp);
- }
复制代码 |
|