OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 6552|回复: 4

stm32f407控制的ad7606模块,并行传输,数据采集不准确,有没有大佬帮忙给看一下!!!

[复制链接]

1

主题

4

帖子

0

精华

新手上路

积分
43
金钱
43
注册时间
2021-7-28
在线时间
9 小时
发表于 2021-8-4 18:23:52 | 显示全部楼层 |阅读模式
5金钱
#include "ad7606.h"
#include "exti.h"
#include "lcd.h"


u8 finish_flag=0;
u16        ad7606_num;        //AD第几次数据
float ad7606_data[8][1024];        //存储AD读取数据


void AD7606_GPIO_Init(void)
{
        GPIO_InitTypeDef GPIO_InitStructure ;
       
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG, ENABLE);        //使能PB,PF,PG时钟
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;       


        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
        GPIO_Init(GPIOF, &GPIO_InitStructure);  
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
        GPIO_Init(GPIOF, &GPIO_InitStructure);         
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
        GPIO_Init(GPIOF, &GPIO_InitStructure);  
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
        GPIO_Init(GPIOF, &GPIO_InitStructure);           
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
        GPIO_Init(GPIOF, &GPIO_InitStructure);  
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
        GPIO_Init(GPIOF, &GPIO_InitStructure);  
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
        GPIO_Init(GPIOF, &GPIO_InitStructure);  
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
        GPIO_Init(GPIOF, &GPIO_InitStructure);                                          //F口 低8位d0~d7
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
        GPIO_Init(GPIOG, &GPIO_InitStructure);  
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
        GPIO_Init(GPIOG, &GPIO_InitStructure);          
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
        GPIO_Init(GPIOG, &GPIO_InitStructure);   
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
        GPIO_Init(GPIOG, &GPIO_InitStructure);           
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
        GPIO_Init(GPIOG, &GPIO_InitStructure);  
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
        GPIO_Init(GPIOG, &GPIO_InitStructure);  
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
        GPIO_Init(GPIOG, &GPIO_InitStructure);  
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
        GPIO_Init(GPIOG, &GPIO_InitStructure);                                          //G口 高8位d8~d15
       
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;         //normal GPIO_PuPd_NOPULL;       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
        GPIO_Init(GPIOB, &GPIO_InitStructure);                                                 //PB6 BUSY 状态线 读
       
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;                        //上拉
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;                                 //PB7 CS信号线 写
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;                                 //PB8 RD信号线 写
        GPIO_Init(GPIOB, &GPIO_InitStructure);        
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;                                 //PB9 CONVSTAB信号线 写
        GPIO_Init(GPIOB, &GPIO_InitStructure);  
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;                                 //PB10 OS0信号线 写
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;                                 //PB11 OS1信号线 写
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;                                 //PB12 OS2信号线 写
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;                                 //PB13 RST信号线 写
        GPIO_Init(GPIOB, &GPIO_InitStructure);




}


void AD7606_Init(void)
{
        AD7606_GPIO_Init();
        OS2 = 0;
        OS1 = 0;
        OS0 = 0;                                //OSC[2:0]=001为2倍过采样
        COV = 1;                                //转换开始输入AB
        CS = 1;                                        //片选,输出总线失能
        RST = 0;                                //初始复位低电平
        RST = 0;                                //延时
        RST = 1;                                //复位
        RST = 0;                                //初始化
        EXTIX_Init();
}


void AD7606_Read(void)
{
        char i=0;                                //通道1 数组0
       
        CS = 0;                                //数据帧传输使能
       
        for(i = 0; i < 8; i++)
        {       
                RD = 0;        //下降沿
                RD = 0;        //延时
                RD = 0;        //延时
                RD = 0;        //延时
                RD = 1;        //上升沿
                //读取数据
                ad7606_data[ad7606_num] = (GPIOF->IDR&0x00ff) | ((GPIOG->IDR&0x00ff)<<8);       
       
                if(ad7606_data[ad7606_num]>32767)
                        {
                                ad7606_data[ad7606_num] = ad7606_data[ad7606_num] - 65536;
                        }        
        }
                CS = 1;                       


}


void AD7606_Start(void)
{
                                COV = 0;
                                COV = 0;        //延时一条指令的时间
                                COV = 1;
                                COV = 1;
}




//外部中断4服务程序
void EXTI9_5_IRQHandler(void)
{       
        if(EXTI_GetFlagStatus(EXTI_Line6) == SET)
                {                                  
                                //读取数据
                                AD7606_Read();                         
                }
         EXTI_ClearITPendingBit(EXTI_Line6);//清除LINE4上的中断标志位           
}




//定时器3中断服务函数
void TIM3_IRQHandler(void)
{
        if(TIM_GetITStatus(TIM3,TIM_IT_Update)==SET) //溢出中断
        {
                AD7606_Start();                //启动AD
                ad7606_num++;                       
                if(ad7606_num==1024)
                {
                        ad7606_num=0;
                        TIM_Cmd(TIM3,DISABLE); //关闭定时器3
                        finish_flag=1;
                }
        }
        TIM_ClearITPendingBit(TIM3,TIM_IT_Update);  //清除中断标志位
}






#ifndef __AD7606_H
#define __AD7606_H


#include "sys.h"


#define        BUSY        PBin(6)                                                //AD转换完成
#define        CS                PBout(7)                                        //片选
#define RD                PBout(8)                                        //读取数据
#define        COV                PBout(9)                                        //启动AD
#define        OS2                PBout(10)                                        //配置过采样
#define        OS1                PBout(11)                                        //配置过采样
#define        OS0                PBout(12)                                        //配置过采样
#define        RST                PBout(13)                                        //复位




extern u16        ad_num;        //AD读取个数计数
extern u8 finish_flag;
extern float ad7606_data[8][1024];        //存储AD读取数据




void AD7606_GPIO_Init(void);
void AD7606_Init(void);
void AD7606_Read(void);
void AD7606_Start(void);



#endif



正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

1

主题

4

帖子

0

精华

新手上路

积分
43
金钱
43
注册时间
2021-7-28
在线时间
9 小时
 楼主| 发表于 2021-8-4 18:24:28 | 显示全部楼层
回复

使用道具 举报

1

主题

4

帖子

0

精华

新手入门

积分
11
金钱
11
注册时间
2021-8-9
在线时间
3 小时
发表于 2021-8-9 16:31:32 | 显示全部楼层

楼主问题解决了吗
回复

使用道具 举报

7

主题

37

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
445
金钱
445
注册时间
2018-2-16
在线时间
27 小时
发表于 2022-2-26 15:06:31 | 显示全部楼层
请问解决了吗?
回复

使用道具 举报

0

主题

6

帖子

0

精华

新手上路

积分
36
金钱
36
注册时间
2022-3-2
在线时间
8 小时
发表于 2022-5-2 10:48:47 | 显示全部楼层
大佬,我也出现了同样问题,您解决了吗,可以留个联系方式吗
回复

使用道具 举报

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

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-2-25 18:10

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表