本帖最后由 marshallemon 于 2016-7-22 16:11 编辑
评估ADS1262,使用SPI 4线接口(CS,ADI,ADO,SCK)与STM32F103进行通讯,采用软件模拟时序,ADS1262的START pin通过一个3.9k电阻接地,RST/PWDN引脚通过一上拉电阻接电源。通过软件发送Start 命令来启动ADC的转换,
现遇到以下问题:1,发送start命令有时可以正常的启动转换,有时则不能?
2,本怀疑时序问题,经尝试将初始化值读出与写入值进行比较,貌似没问题
现把驱动程序贴出来,等待达人指点,虽然搞这行时间不短了,之前这类驱动都是直接拿网上的代码down下来直接用,但这次这个片子用的人貌似很少,对于这种问题仍然是摸不着头脑,麻烦各位达人各抒己见说下自己遇到这种问题通常是如何应对,先谢谢各位了
#define COMM_RESET 0X06 //????
#define COMM_START 0X08 //??????
#define COMM_STOP 0X0A //??????
#define COMM_READ_DATA 0X12 //?????
#define COMM_SFOCAL1 0X19 //?????
#define COMM_READ_REG 0X20 //??????
#define COMM_WRITE_REG 0X40 //??????
uchar bReady=0;
uchar read_reg_buffer[20];
signed long ad_sample_dat;
void SPI_read_clock()
{
ADS1262_SCLK=1;
delay_us(15);
ADS1262_SCLK=0;
delay_us(15);
}
void SPI_write_clock()
{
ADS1262_SCLK=0;
delay_us(15);
ADS1262_SCLK=1;
delay_us(15);
}
/*===========================================================================================*/
//ADC????
uchar ad_read_byte()
{
uchar i;
uchar dat=0;
ADS1262_DIN = 0;
for(i=0; i<8; i++)
{
dat <<= 1;
SPI_read_clock(); //???????????????,???????
if(ADS1262_DOUT)
dat++;
}
return dat;
}
/*===========================================================================================*/
//adc????
void ad_write_byte(uchar dat)
{
uchar i;
for(i=0; i<8; i++)
{
if(dat & 0x80)
ADS1262_DIN=1;
else
ADS1262_DIN=0;
dat <<= 1;
SPI_write_clock();
}
}
/*===========================================================================================*/
//adc????
void ADS126x_Write_Register(uchar StartAddress, uchar NumRegs, uchar * pData)
{
uchar i;
ADS1262_CS = 0;
//delay_us(1);
ad_write_byte(COMM_WRITE_REG + StartAddress);
ad_write_byte(NumRegs-1);
delay_ms(10);
for(i=0; i< NumRegs; i++)
{
ad_write_byte(*pData++);
}
ADS1262_CS = 1;
}
/*===========================================================================================*/
/*??????????????*/
void ADS126x_Read_Register(uchar StartAddress,uchar NumRegs,uchar *tab)
{
uchar i;
ADS1262_CS = 0;
//delay_us(1);
ad_write_byte(COMM_READ_REG+StartAddress);
ad_write_byte(NumRegs-1); /*?????????*/
delay_ms(10);
for(i=0; i< NumRegs; i++)
{
tab = ad_read_byte();
}
ADS1262_CS = 1;
}
/*===========================================================================================*/
unsigned long ADS126x_ReadAdData()
{
uchar i;
uchar byte[4];
ulong return_val;
ADS1262_CS = 0; /*????*/
//delay_us(1);
//ad_write_byte(COMM_READ_DATA); /*???????*/
for(i=0; i<4; i++)
{
byte = ad_read_byte();
}
return_val = 0;
if(byte[0] & 0x80)
{
return_val = 0xff;
return_val = (return_val << 8) | byte[0];
return_val = (return_val << 8) | byte[1];
return_val = (return_val << 8) | byte[2];
}
else
{
return_val = 0x00;
return_val = (return_val << 8) | byte[0];
return_val = (return_val << 8) | byte[1];
return_val = (return_val << 8) | byte[2];
}
ADS1262_SCLK = 0;
ADS1262_CS = 1;
ADS1262_DIN = 0;
ADS1262_DOUT = 0;
return(return_val);
}
void ADS126x_SendResetCommand(void)
{
ADS1262_CS = 0;
ad_write_byte(COMM_RESET);
ADS1262_CS = 1;
}
void ADS126x_SendStartCommand(void)
{
ADS1262_CS = 0;
ad_write_byte(COMM_START);
ADS1262_CS = 1;
}
void ADS126x_SendStopCommand(void)
{
ADS1262_CS = 0;
ad_write_byte(COMM_STOP);
ADS1262_CS = 1;
}
void ADS126x_Init(void)
{
uchar tmp;
tmp = 0x10; //复位,偏置关闭,内部参考关闭
ADS126x_Write_Register(0x01,1,&tmp);
tmp = 0x00; //关闭串口超时,关闭状态字节,关闭校验
ADS126x_Write_Register(0x02,1,&tmp);
tmp = 0x10; //正常的参考电压极性,连续转换模式,斩波使能,转换0延时
ADS126x_Write_Register(0x03,1,&tmp);
tmp = 0x60; //sinC4模式
ADS126x_Write_Register(0x04,1,&tmp);
tmp = 0x52; //PGA=32,10SPS
ADS126x_Write_Register(0x05,1,&tmp);
tmp = 0x45; //AIN4输入+AIN5输入-
ADS126x_Write_Register(0x06,1,&tmp);
tmp = 0x09; //外部基准接AIN0,AIN1
ADS126x_Write_Register(0x0F,1,&tmp);
}
void ADS126x_Reset(void)
{
ADS126x_SendResetCommand();
ADS126x_Init();
}
void ad_init(void)
{
ADS126x_Reset();
ADS126x_SendStartCommand();
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>