您现在所在的是:

单片机论坛

回帖:1个,阅读:1540 [上一页] [1] [下一页]
905
aoyoutian
文章数:1
年度积分:50
历史总积分:905
注册时间:2008/7/2
发站内信
发表于:2008/7/2 11:04:00
#0楼
用的MSP430的单片机,cs5532能正常读写寄存器,复位也正常
就是读不出转换结果,不过32位结果后8位标志位可以显示通道号...


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);
}
905
siwei888
文章数:1
年度积分:50
历史总积分:905
注册时间:2008/7/17
发站内信
发表于:2008/7/17 12:00:00
#1楼
解决了吗?我也遇到此问题了

关于我们 | 联系我们 | 广告服务 | 本站动态 | 友情链接 | 法律声明 | 非法和不良信息举报

工控网客服热线:0755-86369299
版权所有 工控网 Copyright©2024 Gkong.com, All Rights Reserved

62.4004