我用TMS28335 控制ads1256 , 采集2V的电压,每次读出来的数都不一样,相差很大。 然后我就读初始化后的寄存器,发现读出来的寄存器的值和初始化的值不一样,这是为什么??
下面是ADS1256的初始化程序:
void ADS1256_Init(void)
{ ADS_CS = 0;
ADS_REST = 0;
// Delay(DELAY_10ms);
DELAY_US(10000);
ADS_REST = 1;
while(ADS_DRDY);
spiwr(ADS1256_CMD_SELFCAL);// 自校准
while(!ADS_DRDY);
while(ADS_DRDY); //ADS_DRDY=0时表示自校准结束
ADS1256WREG(ADS1256_STATUS,0x04); // 高位在前、校准、不使用缓冲
DELAY_US(50);
ADS1256WREG(ADS1256_MUX,0x08); // A0+ AINCOM?" –
DELAY_US(50);
ADS1256WREG(ADS1256_ADCON,0x00); // ·
DELAY_US(50);
ADS1256WREG(ADS1256_DRATE,ADS1256_DRATE_500SPS); // 500sps
DELAY_US(50);
ADS1256WREG(ADS1256_IO,0x00); //
while(ADS_DRDY);
spiwr(ADS1256_CMD_SELFCAL);// 自校准
while(!ADS_DRDY);
while(ADS_DRDY);
ADS_CS = 1;
}
读寄存器程序:
unsigned long register_read(void){
unsigned char i=0;
unsigned long sum1=0;
unsigned long r1=0;
ADS_CS = 0;
while(ADS_DRDY); //?±ADS1256_DRDY?????±???????????÷ spiwr(ADS1256_CMD_SYNC);
DELAY_US(50);
spiwr(ADS1256_CMD_WAKEUP); DELAY_US(50); spiwr(ADS1256_CMD_RREG | (ADS1256_STATUS & 0xF));
spiwr(2);
DELAY_US(50);
for(i=0;i<3;i++)
{
sum1 = sum1<<8;
spiwr(0);
DELAY_US(300);
// while(SpiaRegs.SPIFFRX.bit.RXFFST !=1);
r1 = SpiaRegs.SPIRXBUF; r1 = r1 & 0xFF;
sum1 |= r1;
} ADS_CS = 1; return sum1;
}
本来应该为STATUS: 0x04, MUX: 0x08 ADCON: 0x00
结果却是: STATUS: 0x80, MUX: 0x31 ADCON: 0x01
user151383853:
是不是先验证一下, SPI 的通信时序是否匹配了
xin peng3:
回复 user151383853:
时序方面我其实不太懂,这是我初始化的一个时序图,我感觉是没问题的,麻烦您帮我看下有问题吗?