13363|26

45

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

求助8051f340和AD7732 [复制链接]

哪位大虾用过8051f340和AD7732,我想用单片机控制AD,没弄明白啊,想用SPI
此帖出自51单片机论坛

最新回复

楼主怎么样问题解决了吗  详情 回复 发表于 2013-3-28 21:43
点赞 关注
 

回复
举报

2954

帖子

0

TA的资源

纯净的硅(初级)

沙发
 
不知道8051f340是否得SPI,如有直接接上按AD7732的datasheet操作就可以了;没有就软件模拟,好好看看AD7732的时序就可以了。
此帖出自51单片机论坛
 
个人签名不断地学习,才会有创新!
淘宝小店:手机、qq点卡、游戏点卡自动充值 http://shop63727265.taobao.com/
 
 

回复

45

帖子

0

TA的资源

一粒金砂(初级)

板凳
 

回复 沙发 lixiaohai8211 的帖子

8051F340有SPI,而且接法是标准3线式的,数据能发出去,从示波器上都能看到,但AD就是不动作,网上给的AD7734的例子应该也不对。AD7732的时序模拟的我感觉没啥问题,可能还是有什么地方没看明白吧!我一会把自己写的代码发下,请大家帮我看下,谢谢
此帖出自51单片机论坛
 
 
 

回复

45

帖子

0

TA的资源

一粒金砂(初级)

4
 
#include
#include                  // SFR declarations
//-----------------------------------------------------------------------------
unsigned char t;
unsigned char k;
unsigned char rr[];
unsigned char aa[];
sbit RDY=P0^3;
sbit ADCS=P0^7;
//-----------------------------------------------------------------------------
void OSCILLATOR_Init (void)
{
   OSCICN = 0x80;                           // Configure internal oscillator for
}
//-----------------------------------------------------------------------------
void delay(int n)
{
char j;
        for(j=0;j         {;
        }
}
void PORT_Init (void)
{
  XBR0     = 0x02;                    // sclk digital peripherals selected
  XBR1     = 0x40;                    // Enable crossbar and weak pull-ups
  P0MDOUT |= 0xFF;                      // Enable p0 as  push-pull output
  P1MDOUT |= 0xFF;                      // Enable p1 as  push-pull output
  P2MDOUT |= 0xFF;                      // Enable p2 as  push-pull output
  P3MDOUT |= 0xFF;                      // Enable p3 as  push-pull output
  P4MDOUT |= 0xFF;  
}
//-----------------------------------------------------------------------------
void SPI0_Init (void)
{
  SPI0CKR=0x07;
  NSSMD0=0;
  SPIEN=1;
  SPI0CFG|=0x70;
}
//-----------------------------------------------------------------------------
void write(unsigned char bb )
{
   ADCS=0;
   SPI0DAT=bb;
//    for(;SPI0CFG&0x80;)
//     {
//      }
   ADCS = 1;
   delay(5);
}
//-----------------------------------------------------------------------------
char read(void)
{
   char temp;
   ADCS=0;
   temp=SPI0DAT;
//   for(;SPI0CFG&0x01;)
//      {
//       }
   ADCS = 1;
   return temp;
}
//-----------------------------------------------------------------------------
void main (void)
{  
   PCA0MD &= ~0x40;                         // WDTE = 0 (clear watchdog timer  enable)
   OSCILLATOR_Init();                      // Initialize system clock
   PORT_Init();                           // Initialize crossbar and GPIO
   SPI0_Init();       
        EA=1;       
        ADCS = 1;
        write(0x38);
        if(WCOL)//写冲突处理,暂无处理
        WCOL=0;       
        write(0x48);
        if(WCOL)//写冲突处理,暂无处理
        WCOL=0;
        write(0x48);

/**/
for(;RDY==0;)
   {  
  
        P1=read();
    P2=read();
    P3=read();
//   }
   }
}
此帖出自51单片机论坛
 
 
 

回复

45

帖子

0

TA的资源

一粒金砂(初级)

5
 
:( 本来也有个自己仿时序的想法,仿完了还可以,不过AD7732有个时间限制很愁人SCLK上升沿时间和总线释放时间最大80ns,最小10ns。大家用AD的时候片选信号不用是不是也可以?CS直接接地。但是控制时序的时间要求中又有对CS下降沿到数据有效的时间要求,最小0ns,最大60ns,请用过的高手帮我看看,我的QQ号是249863865
此帖出自51单片机论坛
 
 
 

回复

45

帖子

0

TA的资源

一粒金砂(初级)

6
 
/*********************************************************************

Author        : ADI - Apps            www.analog.com/MicroConverter

Date          : September 2003

File          : AD7734.c

Hardware      :  ADUC832 is used to control ad7734.The core clock of ADUC832 is 2.097152MHZ.

Description   :

*********************************************************************/

#include
#include
/******************************************************************
DEFINE CONTROL PINS OF ADUC832 FOR THE PURPOSE OF AD7734 CONTROL.
Customers should define the pins according to their design.
If P0 is used as the control port, pull-up resistors should be added to each pin of P0.
******************************************************************/
sbit CS=0x0A4;
sbit DIN=0x0A5;
sbit DOUT=0x0B4;
sbit DRDY=0x0B3;
sbit RESET=0x0A6;
sbit SCLOCK=0x0A7;
int sig;
void int0_int() interrupt 0{
        sig=0;
        return;   }
void writetoreg(unsigned char);
void readfromreg(int);
void read(int);
void main()
{
int tim;

/* Set up UART */
T3CON = 0x082;
T3FD = 0x02D;
SCON   = 0x052;
tim=1000;
/* PRECONFIGURE...*/
RESET=0;
while(tim--);
RESET=1;
SCLOCK=1;
DIN=1;
DOUT=1;
CS=1;
DRDY=1;
printf("\n");
writetoreg(0x28); //write to communication register. The next step is writing to channel setup register
writetoreg(0x08); //enable the channel AIN0, the input voltage range is +5V
writetoreg(0x30); //write to communication register. The next step is writing to channel conversion time register
writetoreg(0x91); //chop enabled, and the update rate is 2534Hz
/*writetoreg(0x38);//write to communication register . The next step is writing to MODE register
writetoreg(0x82);//ADC zero-scale calibration, 24 bit mode

while(DRDY);
printf("self zero-scale calibration finished.\n");
IT0=1;
EA=1;
EX0=1;
sig=1;
while(sig);*/
/*writetoreg(0x38);//write to communication register . The next step is writing to MODE register
writetoreg(0x0C2);//channel zero-scale calibration,24 bit mode
while(DRDY);
printf("channel zeroscale calibration finished.\n");
sig=1;
while(sig);
writetoreg(0x38);//write to communication register. The next step is writing to MODE register
writetoreg(0x0D2);//system full-scale calibration
while(DRDY);
printf("channel full-scale calibration finished.\n");

sig=1;
while(sig);  */
writetoreg(0x44); //read from ADC status
readfromreg(8);
printf("\n");
writetoreg(0x60); //read from channel status
readfromreg(8);
printf("\n");
writetoreg(0x68); //read from channel setup
readfromreg(8);
printf("\n");
writetoreg(0x70); //read from channel conversion
readfromreg(8);
printf("\n");
writetoreg(0x78);//read from mode register
readfromreg(8);
printf("\n");
writetoreg(0x46);//read from adc zero-scale
readfromreg(24);
printf("\n");
writetoreg(0x50);//read from channel zero-scale
readfromreg(24);
printf("\n");
writetoreg(0x58);//read from channel full-scale
readfromreg(24);
printf("\n");

writetoreg(0x38);//writing to communication register, the next step is write to MODE register
writetoreg(0x22);//continuous conversion mode

read(200);
}


void writetoreg(byteword)
unsigned char byteword;

{
unsigned char temp;
int i;

CS=0;
temp=0x80;
for(i=0;i<8;i++)
        {
if((temp&byteword)==0)
      DIN=0;
else DIN=1;
      SCLOCK=0;
      SCLOCK=1;
temp=temp>>1;
        }
CS=1;
}

void readfromreg(bytenumber)
int bytenumber;
{
int j;
   unsigned char temp1;
   DIN=0;
   CS=0;
    temp1=0x00;
   for(j=0;j              {
             SCLOCK=0;
        

              if(DOUT==0)
              temp1=temp1<<1;
         else
         {temp1=temp1<<1;
         temp1=temp1+0x01;}
         if(j==7||j==15||j==23)
          { printf("%02BX",temp1);
           temp1=0x00;
           }
        SCLOCK=1;
          }
CS=1;

  }




void read(readtime)
int readtime;
{
unsigned char temp1;
int i,j;

temp1=0x00;
for(i=0;i         { while(DRDY);
        writetoreg(0x48);
           DIN=0;
           CS=0;
        for(j=0;j<24;j++)
             {SCLOCK=0;
         
              if(DOUT==0)
              temp1=temp1<<1;
         else
         {temp1=temp1<<1;
         temp1=temp1+0x01;}
         SCLOCK=1;
         if(j==7||j==15||j==23)
          { printf("%02BX",temp1);
           temp1=0x00;
           }
          }
          printf("\n");
         CS=1;

        }
        printf("\n\n\n");



}
此帖出自51单片机论坛
 
 
 

回复

45

帖子

0

TA的资源

一粒金砂(初级)

7
 
閺屻儳婀呴張顒€绗橀崗銊╁劥鐠併劏顔戦敍宀冾嚞閻ц缍�閹存牞鈧拷濞夈劌鍞�
此帖出自51单片机论坛
 
 
 

回复

1673

帖子

0

TA的资源

五彩晶圆(中级)

8
 
閺屻儳婀呴張顒€绗橀崗銊╁劥鐠併劏顔戦敍宀冾嚞閻ц缍�閹存牞鈧拷濞夈劌鍞�
此帖出自51单片机论坛
 
个人签名要把目标订的实现起来辛苦一点!
 
 

回复

45

帖子

0

TA的资源

一粒金砂(初级)

9
 
閺屻儳婀呴張顒€绗橀崗銊╁劥鐠併劏顔戦敍宀冾嚞閻ц缍�閹存牞鈧拷濞夈劌鍞�
此帖出自51单片机论坛
 
 
 

回复

45

帖子

0

TA的资源

一粒金砂(初级)

10
 
閺屻儳婀呴張顒€绗橀崗銊╁劥鐠併劏顔戦敍宀冾嚞閻ц缍�閹存牞鈧拷濞夈劌鍞�
此帖出自51单片机论坛
 
 
 

回复

255

帖子

0

TA的资源

五彩晶圆(初级)

11
 
閺屻儳婀呴張顒€绗橀崗銊╁劥鐠併劏顔戦敍宀冾嚞閻ц缍�閹存牞鈧拷濞夈劌鍞�
此帖出自51单片机论坛
 
个人签名每天进步一点点
 
 

回复

2131

帖子

0

TA的资源

至上芯片

12
 

回复 10楼 249863865 的帖子

閺屻儳婀呴張顒€绗橀崗銊╁劥鐠併劏顔戦敍宀冾嚞閻ц缍�閹存牞鈧拷濞夈劌鍞�
此帖出自51单片机论坛
 
个人签名处处留心皆学问!
 
 

回复

3332

帖子

0

TA的资源

五彩晶圆(中级)

13
 

有硬SPI,不行就软件模拟

閺屻儳婀呴張顒€绗橀崗銊╁劥鐠併劏顔戦敍宀冾嚞閻ц缍�閹存牞鈧拷濞夈劌鍞�
此帖出自51单片机论坛
 
 
 

回复

2131

帖子

0

TA的资源

至上芯片

14
 

回复 13楼 tagetage 的帖子

閺屻儳婀呴張顒€绗橀崗銊╁劥鐠併劏顔戦敍宀冾嚞閻ц缍�閹存牞鈧拷濞夈劌鍞�
此帖出自51单片机论坛
 
个人签名处处留心皆学问!
 
 

回复

45

帖子

0

TA的资源

一粒金砂(初级)

15
 

回复 11楼 hanker510 的帖子

閺屻儳婀呴張顒€绗橀崗銊╁劥鐠併劏顔戦敍宀冾嚞閻ц缍�閹存牞鈧拷濞夈劌鍞�
此帖出自51单片机论坛
 
 
 

回复

45

帖子

0

TA的资源

一粒金砂(初级)

16
 

回复 14楼 daicheng 的帖子

閺屻儳婀呴張顒€绗橀崗銊╁劥鐠併劏顔戦敍宀冾嚞閻ц缍�閹存牞鈧拷濞夈劌鍞�
此帖出自51单片机论坛
 
 
 

回复

45

帖子

0

TA的资源

一粒金砂(初级)

17
 

回复 14楼 daicheng 的帖子

閺屻儳婀呴張顒€绗橀崗銊╁劥鐠併劏顔戦敍宀冾嚞閻ц缍�閹存牞鈧拷濞夈劌鍞�
此帖出自51单片机论坛
 
 
 

回复

45

帖子

0

TA的资源

一粒金砂(初级)

18
 

回复 14楼 daicheng 的帖子

閺屻儳婀呴張顒€绗橀崗銊╁劥鐠併劏顔戦敍宀冾嚞閻ц缍�閹存牞鈧拷濞夈劌鍞�
此帖出自51单片机论坛
 
 
 

回复

45

帖子

0

TA的资源

一粒金砂(初级)

19
 
閺屻儳婀呴張顒€绗橀崗銊╁劥鐠併劏顔戦敍宀冾嚞閻ц缍�閹存牞鈧拷濞夈劌鍞�
此帖出自51单片机论坛
 
 
 

回复

45

帖子

0

TA的资源

一粒金砂(初级)

20
 
閺屻儳婀呴張顒€绗橀崗銊╁劥鐠併劏顔戦敍宀冾嚞閻ц缍�閹存牞鈧拷濞夈劌鍞�
此帖出自51单片机论坛
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

开源项目 更多>>
    随便看看
    查找数据手册?

    EEWorld Datasheet 技术支持

    相关文章 更多>>
    关闭
    站长推荐上一条 1/10 下一条
    报名赢【小米双肩包、contigo水杯】 | TI MSPM0 系列 MCU 再添新成员
    了解TI 前沿新品——高性能与高性价比的优秀组合 MSPM0G351x / MSPM0L111x,4月24日(周四)上午10:00直播~

    查看 »

     
    EEWorld订阅号

     
    EEWorld服务号

     
    汽车开发圈

     
    机器人开发圈

    About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

    站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网 15

    北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

    电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
    快速回复 返回顶部 返回列表