ads1256的诸多问题,大家做过的麻烦帮忙看一下

2019-07-20 06:05发布

本帖最后由 简单的旅行 于 2018-5-11 11:19 编辑

1、ADS1256上电初始化,先设置status,mux,adcon,drate几个寄存器值,分别设置成0x04,0x08,0x00,0x03(drate为2.5sps),但是读寄存器的值全部为0(代码详见问题3)2、每次读取的电压值总是0,读取ADS1256转换值,操作时序如下:void ReadASingleData(u8 AINP,u8 AINN)
{
double ReadVoltage;
u32 Data;
u16 i;

ADS1255_write_reg(0x01,(AINP<<4) | AINN );//设置通道
ADS1255_write_reg(0x03,0x00);//数据采集速度2.5
ADS1255_SELFCAL();
ads1255_delayus(5);
ADS1255_SYNC();
ads1255_delayms(20);
ADS1255_WAKEUP();
ads1255_delayus(5);

for(i=0;i<8;i++) //采集8次数据
{
ADS1255_RDATA(); //读单次数据命令
ads1255_delayus(20); //至少50个延时周期
Data = ADS1255_Read_a_Data();//读取AD采集的二进制值
ReadVoltage = ADS1255_DataFormatting( Data , 2.5 , 1);//参考电压2.5V,内置增益为1
DataUart(ReadVoltage); //将电压发送到上位机
}
}
3.以下是我的ads1256初始化函数,DRDY的电平一直为低电平,不转化,不知道初始化对不对u8 ADS1256_Init(void)
{

GPIO_InitTypeDef GPIO_Initure;
/****************************************
ADS1256_Read_MISO PBin(4)
ADS1256_Read_DRDY PEin(0)
ADS1256_CS PAout(15)
ADS1256_RESET PEout(1)
ADS1256_DRDY PAout(15)
ADS1256_MISO PBout(4)
ADS1256_MOSI PBout(5)
ADS1256_SCK PAout(5)
*****************************************/

__HAL_RCC_GPIOA_CLK_ENABLE(); //
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE(); //

//PA15 CS,PA5 SCK
GPIO_Initure.Pin=GPIO_PIN_15|GPIO_PIN_5;
GPIO_Initure.Mode=GPIO_MODE_OUTPUT_PP; /
GPIO_Initure.Pull=GPIO_NOPULL; //-
GPIO_Initure.Speed=GPIO_SPEED_MEDIUM; //
HAL_GPIO_Init(GPIOA,&GPIO_Initure); //3&#245;ê&#188;&#187;ˉ
//PB5 MOSI
GPIO_Initure.Pin=GPIO_PIN_5;
HAL_GPIO_Init(GPIOB,&GPIO_Initure); //3&#245;ê&#188;&#187;ˉ

//PE1 RESET
GPIO_Initure.Pin=GPIO_PIN_1;
HAL_GPIO_Init(GPIOE,&GPIO_Initure); //3&#245;ê&#188;&#187;ˉ

//PB4 MISO
GPIO_Initure.Pin=GPIO_PIN_4;
GPIO_Initure.Mode=GPIO_MODE_INPUT; //í&#198;íìê&#228;3&#246;
GPIO_Initure.Pull=GPIO_NOPULL; //é&#207;à-
GPIO_Initure.Speed=GPIO_SPEED_FAST; //&#191;ì&#203;ù
HAL_GPIO_Init(GPIOB,&GPIO_Initure); //3&#245;ê&#188;&#187;ˉ

//PE0 DRDY
GPIO_Initure.Pin=GPIO_PIN_0;
HAL_GPIO_Init(GPIOE,&GPIO_Initure); //3&#245;ê&#188;&#187;ˉ


u8 ReturnData = 0;
u8 ADS1256_reg_Init[4]={
0x04,   //STATUS
0x08,   //mux
0x00,   //ADCON
0x03,   //DRATA
// 0x00,
};    //寄存器初始化的值
/*
ADS1256_RESET=1;
ADS1256_CS=1;
ADS1256_SCK=0;
ADS1256_MOSI=1;
*/

ADS1256_CS=0;
ADS1256_SCK=0;
ADS1256_RESET=0;
delay_us(100);
ADS1255_RESET();   //复位
delay_ms(10);

while(ADS1256_Read_DRDY) ;

ADS1256_SYNC();      //同步
ADS1256_WAKEUP();   //唤醒

ADS1256_write_bit((0x00& 0x0F) | 0x50);   //写寄存器命令
ADS1256_write_bit(0x03);             //写4个寄存器
ADS1256_write_bit(0x04);
ADS1256_write_bit(0x08);
ADS1256_write_bit(0x00);
ADS1256_write_bit(0x03);
delay_us(100);


if(ADS1256_reg_Init[0] != ADS1256_read_reg(0x00))   //检测第一个寄存器是否正确
ReturnData = 1;

if(ADS1256_reg_Init[1] != ADS1256_read_reg(0x01))   //第二个
ReturnData = 1;

delay_us(1);

if(ADS1256_reg_Init[2] != ADS1256_read_reg(0x02))    //第三
ReturnData = 1;

delay_us(1);

if(ADS1256_reg_Init[3] != ADS1256_read_reg(0x03))    //第四个
ReturnData = 1;

delay_us(1);

while(ADS1256_Read_DRDY)
ADS1256_SELFCAL();                     //自我校验
delay_us(5);
ADS1256_SYNC();             //同步
delay_ms(20);
ADS1256_WAKEUP();      //唤醒
delay_us(5);return(ReturnData);

}
真不知道到底是芯片有问题还是我操作上哪里不对了;
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。