如题,为什么无数据转换出来?请大家伴我看看哪里有问题?
void CS5532_ADC_init(void)
{
unsigned char i,temp[4];
/****系统复位*********/
reset:
CLR_SS;
for(i=15;i>0;i--)
{
SpiWriteByte(0xFF);
}
SpiWriteByte(0xFE);
SET_SS;
DDRB=0xFF;
PORTB=0x02;
delay(20);
CLR_SS;
SpiWriteByte(0x03);//写入CS5532复位命令
SpiWriteByte(0x20);
SpiWriteByte(0x00);
SpiWriteByte(0x00);
SpiWriteByte(0x00);
SET_SS;
CLR_SS;
SpiWriteByte(0x0B);//读取配置寄存器内容
temp[0]=SpiReadByte();
temp[1]=SpiReadByte();
temp[2]=SpiReadByte();
temp[3]=SpiReadByte();
if(!(temp[0]&0x10))
{
goto reset;
}
SET_SS;
CLR_SS;
SpiWriteByte(0x03);//写配置寄存器
SpiWriteByte(0x00);
SpiWriteByte(0x00);
SpiWriteByte(0x40);
SpiWriteByte(0x00);
SET_SS;
CLR_SS;
SpiWriteByte(0x05);//写通道设置寄存器
SpiWriteByte(0x31);
SpiWriteByte(0x80);
SpiWriteByte(0x31);
SpiWriteByte(0x80);
SET_SS;
CLR_SS;
SpiWriteByte(0xC0);//启动A/D连续转换
SET_SS;
}
void CS5532_read_data(void)
{
unsigned char i;
/******读数据*******/
CLR_SS;
SpiWriteByte(0x0C);
for(i=0;i<4;i++)
{
recv_adc_data=SpiReadByte();
}
SET_SS;
send_length=3;
send_buf_pointer=&recv_adc_data[1];
UDR0=recv_adc_data[0];
DDRD=0xFF;
PORTD=0x80;
} |