各位工程师你们好,最近在调试ad2s1210,利用spi通讯,硬件的励磁输出已经没有问题,且写入ad2s1210更改励磁频率也能实现,但是读取时却无法读出数值,始终为0,同时LOT和DOS寄存器始终为低电平,按照数据手册复位无法清除,程序是根据例程移植而来,硬件上cs始终置低,所以去除了对cs的操作部分,芯片主频为40mhz,下面附上程序,麻烦各位帮忙解答,谢谢。
void AD2S1210Ini
tiate()
{
gpio_set(RESET, 0);
gpio_set(SAMPLE, 1);
delay_ad(50000);
gpio_set(RESET, 1);
delay_ad(5000000);
gpio_set(SAMPLE, 0);
delay_ad(1);
gpio_set(SAMPLE, 1);
}
void SPIRead(unsigned char count, unsigned char *buf)
{
unsigned char i = 0;
unsigned char j = 0;
unsigned int iTemp = 0;
unsigned char RotateData = 0;
for(j=count; j>0; j--)
{
for(i=0; i<8; i++)
{
gpio_set(SCLK, 1);
RotateData <<= 1; //Rotate data
delay_ad(1);
iTemp =(((GPIOB_BASE_PTR->PDIR) >> (0)) & 1) ;//(MISO); //Read SDO of AD2S
gpio_set(SCLK, 0);
if(iTemp>=1)
{
RotateData |= 1;
}
delay_ad(1);
}
*(buf + j - 1)= RotateData;
}
}
void ReadFromAD2S1210(unsigned char mode, unsigned char address, unsigned char * buf)
{
if (mode==CONFIG)
{
//write control register address
buf[0] = address;
gpio_set(SCLK, 1);
delay_ad(4);
gpio_set(WR, 1);
delay_ad(1);
gpio_set(WR, 0);
delay_ad(1);
SPIWrite(1,buf);
gpio_set(WR, 1);
delay_ad(1);
//write control register address
//read 1-byte register
gpio_set(SCLK, 1);
delay_ad(1);
gpio_set(WR, 1);
delay_ad(2);
gpio_set(SCLK, 0);
delay_ad(1);
gpio_set(WR, 0);
delay_ad(1);
SPIRead(1,buf);
gpio_set(WR, 1);
delay_ad(2);
//read 1-byte register
}
else if (mode==POSITION||mode==VELOCITY)
{
gpio_set(SAMPLE, 1);
delay_ad(1);
gpio_set(SAMPLE, 0);
delay_ad(5);
//read 3-byte register
gpio_set(SCLK, 1);
delay_ad(1);
gpio_set(WR, 1);
delay_ad(3);
gpio_set(SCLK, 0);
delay_ad(1);
gpio_set(WR, 0);
delay_ad(1);
SPIRead(3,buf); //read data register
gpio_set(WR, 1);
delay_ad(2);
//read 3-byte register
}
}