uint32_t CS5532ReadData(void)//向CS5532读寄存器中的数据
{
uint8_t u8i;
uint32_t u32ReadValue = 0;
ClrBit_CSCLK();//时钟拉低
ClrBit_SDO();
ClrBit_SDI();
for(u8i = 0;u8i < 8;u8i++)//8个清串口时钟
{
DrvSYS_Delay(2);
SetBit_CSCLK();//时钟拉高
DrvSYS_Delay(2);
ClrBit_CSCLK();//时钟拉低
}
ClrBit_CSCLK();//时钟拉低
DrvSYS_Delay(2);
for(u8i = 0;u8i < 32; u8i++)
{
if(Get_SDO_Bit() == 1) //假如读取的是高电平
{
u32ReadValue|=0x00000001; //把高电平给了最低位,因为MSB优先
}
DrvSYS_Delay(2);
SetBit_CSCLK();//时钟拉高
DrvSYS_Delay(2);
ClrBit_CSCLK();//时钟拉低
if(u8i < 31)//最后一次应该不移位才对
{
u32ReadValue<<=1;//
}
}
ClrBit_CSCLK();//时钟拉低
SetBit_SDO();//
DrvSYS_Delay(2);
ClrBit_SDO();//
return u32ReadValue>>11;
}
|