ADS112驱动问题,延时较长

2019-07-20 01:21发布

源码如下:


.C文件:


#include "ADS112.h"
#include "myiic.h"
#include "sys.h"
#include "stdio.h"
#include "stm32f4xx.h"
#include "usart.h"
#include "delay.h"
#define ADS112_ST_IO GPIOE
#define ADS112_ST_PIN GPIO_Pin_0


#define ADS112_ST_UP GPIO_SetBits(ADS112_ST_IO,ADS112_ST_PIN)
#define ADS112_ST_DOWN GPIO_SetBits(ADS112_ST_IO,ADS112_ST_PIN)

void ADS112_GPIO_Init(void);
void ADS112_Start_Convertion(void);
u16 ADS112_Get_Convertion_Data(void);
void ADS112_Write_REG1(u8 rate,u8 IF_turbo,u8 Convertion_mode);
void ADS112_Write_REG0(void);
u8 ADS112_Read_Reg(u8 address);
void ADS112_Init(void);
void ADS112_Reset(void);
u8 ADS112_IF_New_Data(void);

void ADS112_GPIO_Init(void)
{
    GPIO_InitTypeDef  GPIO_InitStructure;
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);//ʹÄÜGPIOBʱÖÓ

  //GPIOB8,B9³õʼ»¯ÉèÖÃ
  GPIO_InitStructure.GPIO_Pin = ADS112_ST_PIN;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//??????
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//??
    GPIO_Init(GPIOE, &GPIO_InitStructure);
    GPIO_SetBits(GPIOE,GPIO_Pin_0);
}




u16 ADS112_Get_Convertion_Data(void)
{
    u16 data_1=0;
    u8 data_2=0;
    IIC_Start();
    IIC_Send_Byte(0x80);
    IIC_Wait_Ack();
    IIC_Send_Byte(0x10);
    IIC_Wait_Ack();
   
    IIC_Start();
    IIC_Send_Byte(0x81);
    IIC_Wait_Ack();
    data_1=IIC_Read_Byte(0);
    IIC_Ack();
    data_2=IIC_Read_Byte(0);
    IIC_Stop();
    data_1<<=8;
    return data_1+data_2;
}

void ADS112_Write_Reg(u8 address,u8 data)
{
    u8 address_temp=0x40;
    address<<=2;
    address_temp|=address;
    IIC_Start();
    IIC_Send_Byte(0x80);
    IIC_Wait_Ack();
    IIC_Send_Byte(address_temp);
   
    IIC_Wait_Ack();
    IIC_Send_Byte(data);
    IIC_Wait_Ack();
   
    IIC_Stop();
}

u8 ADS112_Read_Reg(u8 address)
{
    u8 data=0;
    u8 address_temp=0x20;
    address<<=2;
    address_temp|=address;
   
    IIC_Start();
    IIC_Send_Byte(0x80);
   
    IIC_Wait_Ack();
    //usart4.printf("ack!");
    IIC_Send_Byte(address_temp);
   
    IIC_Wait_Ack();
   
    IIC_Start();
   
    IIC_Send_Byte(0x81);
   
    IIC_Wait_Ack();
   
    data=IIC_Read_Byte(0);
   
    IIC_Stop();
   
    return data;
}

u8 ADS112_IF_New_Data(void)//0  :&#208;&#194;&#202;&#253;&#190;&#221;  1&#163;&#186;&#190;&#201;&#202;&#253;&#190;&#221;
{
    u8 data=1;
    data=GPIO_ReadInputDataBit(ADS112_ST_IO,ADS112_ST_PIN);
    return data;
}

void ADS112_Write_REG0()
{
    u8 data=0xB1;
    ADS112_Write_Reg(0,data);
}


/**********************************
&#201;è&#214;&#195;ADS112&#181;&#196;×&#170;&#187;&#187;&#203;&#217;&#194;&#202;&#163;&#172;&#202;&#199;·&#241;turbo&#163;&#172;×&#170;&#187;&#187;&#196;&#163;&#202;&#189;
&#201;è&#214;&#195;×&#170;&#187;&#187;&#203;&#217;&#194;&#202;&#208;è&#210;&#170;&#184;&#248;rate&#184;&#179;&#214;&#181;&#210;&#212;&#207;&#194;&#191;&#201;&#209;&#161;&#202;&#253;&#214;&#181;&#163;&#186;
000 = 20 SPS
001 = 45 SPS     
010 = 90 SPS     
011 = 175 SPS
100 = 330 SPS
101 = 600 SPS     
110 = 1000 SPS
&#201;è&#214;&#195;turbo&#208;è&#210;&#170;&#184;&#248; IF_turbo &#184;&#179;&#214;&#181;&#163;&#186;
0&#163;&#186;&#213;&#253;&#179;&#163;&#196;&#163;&#202;&#189;
1&#163;&#186;turbo&#196;&#163;&#202;&#189;

&#201;è&#214;&#195;&#202;&#199;·&#241;&#193;&#172;&#208;&#248;×&#170;&#187;&#187;&#208;è&#210;&#170;&#184;&#248;Convertion_mode &#184;&#179;&#214;&#181;
0&#163;&#186;&#181;&#165;&#180;&#206;×&#170;&#187;&#187;&#196;&#163;&#202;&#189;
1&#163;&#186;&#193;&#172;&#208;&#248;×&#170;&#187;&#187;&#196;&#163;&#202;&#189;
***********************************/
void ADS112_Write_REG1(u8 rate,u8 IF_turbo,u8 Convertion_mode)
{
    u8 data=0x00;
    rate<<=5;
    data|=rate;
    IF_turbo<<=4;
    data|=IF_turbo;
    Convertion_mode<<=3;
    data|=Convertion_mode;
   
    usart4.printf("data write ro REG1 is %d ",data);
    ADS112_Write_Reg(1,data);
}
//0000 100x

void ADS112_Start_Convertion(void)
{
    IIC_Start();
    IIC_Send_Byte(0x80);
    IIC_Wait_Ack();
    IIC_Send_Byte(0x08);
    IIC_Stop();
}
void ADS112_Reset(void)
{
    IIC_Start();
    IIC_Send_Byte(0x80);
    IIC_Wait_Ack();
    IIC_Send_Byte(0x07);
    IIC_Stop();
}
void ADS112_Set_mdoe(u8 mode)
{
        ADS112_Write_REG0();
        ADS112_Write_REG1(0x06,1,mode);
}



u16 ADS112_Get_Once_data(void)
{  
    ADS112_Start_Convertion();
    delay_ms(60);
    return ADS112_Get_Convertion_Data();
}

u16 ADS112_Get_Continous_data(void)
{
    static u8 First_Flag=0;
    static u16 data;
    if(First_Flag==0)
    {
        First_Flag=1;
        ADS112_Start_Convertion();
        data=ADS112_Get_Convertion_Data();
        return data;
    }
    else
    {
        data=ADS112_Get_Convertion_Data();
        return data;
    }
}


.h文件:


#ifndef ADS112_H
#define ADS112_H
#include "sys.h"

void ADS112_GPIO_Init(void);

u16 ADS112_Get_Convertion_Data(void);

u16 ADS112_Get_Once_data(void);

u16 ADS112_Get_Continous_data(void);
   
u8 ADS112_Read_Reg(u8 address);

void ADS112_Set_mdoe(u8 mode);

void ADS112_Start_Convertion(void);
#endif


现在有一个问题,就是单次转换模式,必须要有60ms以上的延时,否则无法正常工作,请问各位大神,有没有办法改善,或者说,ADS112本身就是这个速度?


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。