Part Number:ADS1255Other Parts Discussed in Thread: ADS1256
我的初始化代码如下
void ADS1255_Init(void)
{ uint8_t buff;
/*****************自校准的过程*******************/
while(DRDY1) {}
;
CS1_L;
/****************设置ADS1256的ADC工作模式*****************/
ADS1255WREG(0x50,0x06);
ADS1255WREG(0x51,0x01);
ADS1255WREG(0x52,0x20);
ADS1255WREG(0x53,0x03);
ADS1255WREG(0x54,0x00);
delay_us(100);
/*******************再一次自校准***************************/
while(DRDY1)
{};
buff = 0xF0;
HAL_SPI_Transmit(&hspi1,&buff,1,1000); //补偿和增益自我校准命令
// delay_us(5);
HAL_Delay(2000); //自校准时间需要1200ms
buff = 0xfc;
HAL_SPI_Transmit(&hspi1,&buff,1,1000); //sync
HAL_Delay(20);
buff = 0xFF;
HAL_SPI_Transmit(&hspi1,&buff,1,1000); //wake
delay_us(5);
CS1_H;
}
我的读取函数如下
double ReadAnAdc()
{
uint8_t buff;
uint32_t Data1 = 0;
double ReadVoltage;
CS1_L;
while(DRDY1)
{};
ADS1255_SPI1_ReadWriteByte(0x51);
ADS1255_SPI1_ReadWriteByte(0x00); //不是唤醒待机和同步命令,写进字节数为0+1
ADS1255_SPI1_ReadWriteByte(0x01); //要写进寄存器的数据
ADS1255_SPI1_ReadWriteByte(0x53);
ADS1255_SPI1_ReadWriteByte(0x00); //不是唤醒待机和同步命令,写进字节数为0+1
ADS1255_SPI1_ReadWriteByte(0x03);//要写进寄存器的数据
buff = 0xF0;
HAL_SPI_Transmit(&hspi1,&buff,1,1000); //补偿和增益自我校准命令
delay_us(5);
buff = 0xfc;
HAL_SPI_Transmit(&hspi1,&buff,1,1000); //sync
buff = 0x00;
HAL_SPI_Transmit(&hspi1,&buff,1,1000); //wake
delay_us(5);
buff = 0x01;
HAL_SPI_Transmit(&hspi1,&buff,1,1000); //rdata
delay_us(10);
HAL_SPI_Receive(&hspi1,&data[0],1,1000);
HAL_SPI_Receive(&hspi1,&data[1],1,1000);
HAL_SPI_Receive(&hspi1,&data[2],1,1000);
CS1_H;
Data1 = (data[0]<<16) + (data[1]<<8) + data[2];
if(Data1>0x7fffff)
{
Data1 -=0x1000000;
}
if(Data1&0x800000)
{
Data1 =~(unsigned long)Data1;
Data1 &=0x7fffff;
Data1 +=1;
}
return Data1;
}
附件中可以看到drdy信号的频率
jian yin:
有人在吗
,
Alice:
您好,
寄存器应该没写入成功,使用的是默认的设置。
您可以在初始化后,回读此寄存器的值来检查SPI通讯时序。
另外,工作过程中更改寄存器配置,需等待芯片同步(监测DRDY状态)后再进行数据读取。
,
jian yin:
请问在0x50配置为0x06的时候,即acal和bufen使能,当我切换其他A/D data rate的时候,需不需要再次进行0xf0,SELFCAL的操作
,
Alice:
您好,
不需要。