登录
首页 单片机论坛
回帖 发帖
正文

主题:CS5532不能读出转换结果

点击:1615 回复:1

用的MSP430的单片机,cs5532能正常读写寄存器,复位也正常
就是读不出转换结果,不过32位结果后8位标志位可以显示通道号...
[QUOTE]
void CS5532_Init()  
{
   unsigned short i;
   
   P3OUT &= 0xFE;     CS使能
   Delay();
   //CS5532初始化
   for(i=0;i<15;i++)
   {
       cs5532_write(0xFF);
   }
   cs5532_write(0xFE);
   cs5532_write(0x03);
   cs5532_write(0x20);
   cs5532_write(0x00);
   cs5532_write(0x00);
   cs5532_write(0x00);
   //等待复位完成
   cs5532_write(0x0b);
   test=0;
   test|=cs5532_read();
   test<<=8;
   test|=cs5532_read();
   test<<=8;
   test|=cs5532_read();
   test<<=8;
   test|=cs5532_read();
 
   //CS5532写选择通道寄存器1
   cs5532_write(0x05);
   cs5532_write(0x02);       //选择物理通道1,增益1,7.5hz,双极性,setup1
   cs5532_write(0x08);
   cs5532_write(0x42);        //选择物理通道2,增益1,7.5hz,双极性, setup2
   cs5532_write(0x08);
     
   //CS5532写配置寄存器,初始化电压参考模型
   cs5532_write(0x03);
   cs5532_write(0x02);                         //参考电压 1V<=Vref<=VA+
   cs5532_write(0x00);
   cs5532_write(0x00);
   cs5532_write(0x00);
   
   //校准
   cs5532_write(0x81);                          //setup1(通道1)自偏移校准
   Delay1();
   cs5532_write(0x89);                          //setup2(通道2)自偏移校准
   Delay1();
}
void CS5532_AD()    
{
   unsigned short i;
   
   Delay();
   for(i=0;i<8;i++)
   {
       Ua_temp[i]=0;
   }
   //AD转换
   cs5532_write(0x80);
   Delay1();
   cs5532_write(0x0c);
   Delay();
   Ua_temp[0] |= cs5532_read();
   Delay();
   Ua_temp[1] |= cs5532_read();
   Delay();
   Ua_temp[2] |= cs5532_read();
   Delay();
   Ua_temp[3] |= cs5532_read();                   //状态字节(溢出位和通道指示)
   
   cs5532_write(0x88);                                 //通道2 setup2
   Delay1();
   cs5532_write(0x0c);
   Delay();
   Ua_temp[4] |= cs5532_read();
   Delay();
   Ua_temp[5] |= cs5532_read();
   Delay();
   Ua_temp[6] |= cs5532_read();
   Delay();
   Ua_temp[7] |= cs5532_read();                   //状态字节(溢出位和通道指示)
   Delay();
}
void cs5532_write(unsigned char data)
{
   unsigned char i;
   
   for(i=0;i<8;i++)
   {
       P3OUT &= 0xF7;                //SCLK=0
       if((data & 0x80) == 0x80)
       {
           P3OUT |= 0x02;            //SDI=1
       }
       else
       {
           P3OUT &= 0xFD;          //SDI=0
       }
       P3OUT |= 0x08;              //SCLK=1
       data<<=1;
       Delay2();
   }
}
unsigned short cs5532_read(void)
{
   unsigned char i;
   unsigned short data=0;
   
   for(i=0;i<8;i++)
   {
       P3OUT &= 0xF7;
       if((P3IN & 0x04) == 0x04)        //SDO读数
       {
           data |= 0x01;
       }
       else
       {
           data &= 0xFE;
       }
       if(i<7)
       {
           data<<=1;
       }
       P3OUT |= 0x08;
       Delay2();
   }
   return(data);
}
[/QUOTE]
08-07-02 11:04
解决了吗?我也遇到此问题了
08-07-17 12:00

工控新闻

更多新闻资讯