1、ADS1256上电初始化,先设置status,mux,adcon,drate几个寄存器值,分别设置成0x04,0x08,0x00,0x03(drate为2.5sps),但是读寄存器的值全部为0(代码详见问题3) 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õê¼»ˉ
//PB5 MOSI
GPIO_Initure.Pin=GPIO_PIN_5;
HAL_GPIO_Init(GPIOB,&GPIO_Initure); //3õê¼»ˉ
//PE1 RESET
GPIO_Initure.Pin=GPIO_PIN_1;
HAL_GPIO_Init(GPIOE,&GPIO_Initure); //3õê¼»ˉ
//PB4 MISO
GPIO_Initure.Pin=GPIO_PIN_4;
GPIO_Initure.Mode=GPIO_MODE_INPUT; //íÆíìêä3ö
GPIO_Initure.Pull=GPIO_NOPULL; //éÏà-
GPIO_Initure.Speed=GPIO_SPEED_FAST; //¿ìËù
HAL_GPIO_Init(GPIOB,&GPIO_Initure); //3õê¼»ˉ
//PE0 DRDY
GPIO_Initure.Pin=GPIO_PIN_0;
HAL_GPIO_Init(GPIOE,&GPIO_Initure); //3õê¼»ˉ
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);
} 真不知道到底是芯片有问题还是我操作上哪里不对了; |