原创 AD7794 AD7795 AD7793 AD7792 程序 驱动代码 驱动程序 单片机代码

2015-2-5 15:42 5794 28 29 分类: MCU/ 嵌入式

本驱动代码适用于ADI公司的AD779X系列ADC芯片,所有与硬件平台相关的代码都最大化的提取了出来,达到了最优化的移植性,本文档及代码旨在分享个人的开发工作,减少工程师们的开发周期,提高大家的工作效率。

测试时硬件平台我使用的是一块cortex-M3的单片机来和AD779X通信,具体型号为NXP公司的LPC1752单片机,原理图如下:

qq截图20150205154105.jpg

由上图可以看到AD779X的基准芯片采用ADI公司的ADR34XX系列芯片,AD779X与单片机的管脚连接有SCLK/CS/DI/DOUT共四个管脚,即AD779X的数字串行通信引脚。

A779X芯片的驱动代码整理后已经高度模块化,移植起来非常方便,整个移植过程只需要修改三个非常简单的地方即可使用,加快开发进度:

  1. 管脚定义及功能设置(与单片机相连的管脚定义,输入输出设置)

/***********PIN define**************************/

#define      AD779x_DIN    (1<<6)

#define      AD779x_CS      (1<<7)

#define      AD779x_SCLK  (1<<8)

#define      AD779x_DOUTRDY (1<<10)

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

*FUNCTION:Set pin function on MCU

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

void McuGpioSet(void)

  1. 管脚写1或写0功能函数

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

*FUNCTION:     AD779X PIN state set

*PARAMETER:  PIN---serial pin on AD779X,may nex value:

*                                    AD779X_DIN/AD779X_CS/AD779X_SCLK/AD779X_DOUTRDY

*                           Data---set value:0/1

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

void AD779x_PIN_SET(unsigned int PIN, unsigned char Data)

{

                  if(Data)

                            LPC_GPIO2->FIOSET |= PIN;

                  else

                            LPC_GPIO2->FIOCLR |=PIN;

}

  1. 管脚电平状态读取函数

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

*FUNCITON:AD779X PIN STATE READ

*PARAMETER:PIN---serial pin,may next value:

*                                    AD779X_DOUTRDY

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

unsigned char   AD779X_PIN_READ(unsigned int PIN)

{

unsigned char VarDat;

 

if(LPC_GPIO2->FIOPIN & PIN)

           VarDat=1;

else

           VarDat=0;

 

return VarDat;

}

从上面描述可以看出,芯片AD779X的移植非常简单高效,为项目开发节约时间,提高工作效率,一下为高度模块化的子模块函数,与平台无关,移植时不用修改:

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

*FUNCTION:    AD779X serial pin initial

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

void AD779xInitialization(void)

 

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

*FUNCTION:    Serial interface reset                

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

void AD779xSoftwareReset(void)

 

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

*FUNCTION: write data in registers

*PARAMETER:RegisterAddress---register address,may next value:

*                                            COMMUNICATIONS,

*                                            IO,

*                                            MODE,

*                                            CONFIGURATION,

*                                            OFFSET,

*                                            FULLSCALE

*                          RegisterBuffer---register data buffer point

*                          CHIP---chip choose,may next value:

*                                            AD7794

*                                            AD7795

*                                            AD7796

*                                            AD7797

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

void AD779xWriteRegister(unsigned char RegisterAddress, unsigned long int *RegisterBuffer,unsigned char CHIP)

 

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

*FUNCTION:read data from register

*PARAMETER:RegisterAddress---register address , may next value:

*                                            STATUS,

*                                            ID,

*                                            MODE,

*                                            CONFIGURATION,

*                                            OFFSET,

*                                            FULLSCALE,

*                                            DATA

*                          RegisterBuffer---data buffer point

*                          CHIP---chip choose,may next value:

*                                            AD7794

*                                            AD7795

*                                            AD7796

*                                            AD7797

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

void AD779xReadRegister(unsigned char RegisterAddress, unsigned long int *RegisterBuffer,unsigned char CHIP)

 

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

*FUNCTION:Read result for single conversion mode

*PARAMETER: DataIndex---the sotre place in DataBuffer

*                         DataBuffer---data store buffer

*                          CHIP---which type,may next value:

*                                   AD7792/AD7793/AD7794/AD7795/AD7796/AD7797

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

void AD779xReadResultForSingleConversion(unsigned char DataIndex, unsigned long int *DataBuffer,unsigned char CHIP)

 

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

*FUNCTION:Read result for continuous conversion mode

*PARAMETER: StartIndex---the first store place in DataBuffer

*                          NumberOfData---data numbers

*                          DataBuffer---data store buffer

*                          CHIP---which type,may next value:

*                                   AD7792/AD7793/AD7794/AD7795/AD7796/AD7797

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

void AD779xReadResultForContinuousConversion(unsigned char StartIndex, unsigned char NumberOfData, unsigned long int *DataBuffer,unsigned char CHIP)

 

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

*FUNCTION:Read result for continuous read mode

*PARAMETER: StartIndex---the first store place in DataBuffer

*                          NumberOfData---data numbers

*                          DataBuffer---data store buffer

*                          CHIP---which type,may next value:

*                                   AD7792/AD7793/AD7794/AD7795/AD7796/AD7797

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

void AD779xReadResultForContinuousRead(unsigned char StartIndex, unsigned char NumberOfData, unsigned long int *DataBuffer,unsigned char CHIP)

 

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

*FUNCITON:Exit continous read mode

*PARAMETER: CHIP---which type,may next value:

*                                   AD7792/AD7793/AD7794/AD7795/AD7796/AD7797

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

void AD779xExitContinuousRead(unsigned char CHIP)

 

         以上为该芯片驱动代码所有的子模块函数,在主函数中就可以调用这些子函数配置寄存器和读取ADC的值,下面代码即使用连续转换方式(Continuous Conversion)读取通道2的数据,然后将读取的数据通过UART接口打印输出,该代码在实际的硬件平台调试通过:

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

** Function name:       main

** Descriptions:      

 

** input parameters:    无

** output parameters:   无

** Returned value:      无

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

int  main (void)

{

 

         SystemInit();                                                       /*MCU system initial*/

         uart0Init ();                                                                                 /*uart initial*/

 

         printf("General Platform v1.0!\n");

 

         myDelay(1000);

 

         AD779xInitialization();

         AD779xSoftwareReset();

         NopDely(100*50);

 

// read ID register

         AD779xRegisters[COMMUNICATIONS]=WRITE_ENABLE|READ|RS_ID|CREAD_DISABLE;

         AD779xWriteRegister(COMMUNICATIONS, AD779xRegisters,AD7794);

         AD779xReadRegister(ID, AD779xRegisters,AD7794);

 

         printf("RESET ID REGISTER=0x%04X\n",AD779xRegisters[ID]);

 

// read STATUS register

         AD779xRegisters[COMMUNICATIONS]=WRITE_ENABLE|READ|RS_STATUS|CREAD_DISABLE;

         AD779xWriteRegister(COMMUNICATIONS, AD779xRegisters,AD7794);

         AD779xReadRegister(STATUS, AD779xRegisters,AD7794);

 

         printf("RESET STATUS REGISTER=0x%04X\n",AD779xRegisters[STATUS]);

 

 

//WRITE MODE REGISTER

         AD779xRegisters[COMMUNICATIONS]=WRITE_ENABLE|WRITE|RS_MODE|CREAD_DISABLE;

         AD779xWriteRegister(COMMUNICATIONS, AD779xRegisters,AD7794);

AD779xRegisters[MODE]=MD_CONTINUOUS_CONVERSION|PSW_ENABLE|AMP_CM_ENABLE|CLK_INTERNAL_OUTPUT_ENABLE|CHOP_DISABLE|FILTER_UPDATE_RATE_242;

         AD779xWriteRegister(MODE, AD779xRegisters,AD7794);

 

//WRITE CONFIGURATION     

         AD779xRegisters[COMMUNICATIONS]=WRITE_ENABLE|WRITE|RS_CONFIGURATION|CREAD_DISABLE;

         AD779xWriteRegister(COMMUNICATIONS, AD779xRegisters,AD7794);

AD779xRegisters[CONFIGURATION]=VBIAS_DISABLE|BO_DISABLE|BIPOLAR|BOOST_DISABLE|GAIN_1|REFSEL_EXTERNAL_REF1|REF_DETECT_DIASBLE|BUF_ENABLE|CHANNEL_AIN2;

         AD779xWriteRegister(CONFIGURATION, AD779xRegisters,AD7794);

 

 

     while(1)

         {

 

                   AD779xReadResultForContinuousConversion(0, 1, AD779xData,AD7794);

        

                   printf("convertion data1:0x%03X,data2:0x%03X\n",AD779xData[0],AD779xData[1]);

                   myDelay(1000);

         }

}

http://item.taobao.com/item.htm?id=43307575672;

文章评论1条评论)

登录后参与讨论

用户370614 2015-1-23 15:12

原创测试通过,很好用,移植方便

相关推荐阅读
用户370614 2012-10-29 11:33
linux proc/stat文件信息
proc/stat包含了所有CPU活动的信息,该文件中的所有值都是从系统启动开始累计到当前时刻。 [work@builder ~]$ cat /proc/stat cpu 432661 132...
用户370614 2012-10-18 14:55
platform_get_resource函数实现细节
platform_get_resource函数源码如下: struct resource *platform_get_resource(struct platform_device ...
用户370614 2012-10-18 14:50
MII和RMII
项目名称:基于FPGA的以太网MII数据和RMII数据的协议转换  关键词:以太网 MII RMII 协议转换   项目信息:   应用领域:网络与通...
用户370614 2012-10-18 14:49
linux中断之中断注册
专业的linux驱动开发离不开中断处理,在处理中断,首先要注册中断,在linux下通过request_irq来注册中断的,不同内核版本,注册中断所需要的参数也不同,本文以linux-2.6....
用户370614 2012-10-18 14:47
linux下查看和添加PATH环境变量
$PATH:决定了shell将到哪些目录中寻找命令或程序,PATH的值是一系列目录,当您运行一个程序时,Linux在这些目录下进行搜寻编译链接。<?xml:namespace prefix =...
我要评论
1
28
关闭 站长推荐上一条 /2 下一条