当前位置:网站首页>STM32 development | ad7606 parallel multi-channel data acquisition
STM32 development | ad7606 parallel multi-channel data acquisition
2022-07-26 04:39:00 【W\Y.】
Catalog
1、 Schematic design reference

2、 Pin description
| Pin | explain |
|---|---|
| AVCC | Analog power supply voltage 4.75 V to 5.25 V |
| AGND | Simulate |
| OS0/OS1/OS2 | Oversampling mode selection |
| PAR/SER/BYTE | parallel / Serial / Parallel byte interface selection |
| STBY | Standby mode |
| RANGE | Analog input range selection (±10V or ±5V) |
| CONVST-A / CONVST-B | Start conversion pin , Generally, it is connected in parallel with PWM Function pin |
| RESET | Reset pin |
| RD/SCLK | The parallel interface mode is to read the control pin (RD) / Clock input in serial interface mode (SCLK) |
| CS | Chip selection , Low level active |
| BUSY | Output busy , Data can be read at low level |
| FRSTDATA | Digital output , Indicates when to read back data |
| REF | Reference voltage selection |
| DB0~DB15 | 16 Bit read data output |
3、 Reference code
#include <stdio.h>
#include <string.h>
#include "stm32f10x.h"
#include "ad7606.h"
//AD7606 Pin configuration
void AD7606_GPIOConfig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
// Allow modification of RTC And backup registers
PWR_BackupAccessCmd(ENABLE);
// Turn off the external low-speed clock ,PC14+PC15 Can be used as ordinary IO
RCC_LSEConfig(RCC_LSE_OFF);
// Turn off intrusion detection ,PC13 As ordinary IO
BKP_TamperPinCmd(DISABLE);
//----------------------------- AD7606 DATA GPIO ------------------------------
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
// No modification RTC And backup registers
PWR_BackupAccessCmd(DISABLE);
//------------------------------------ End ------------------------------------
//ADCS->PB3, OS0->PB7, OS1->PB6, OS2->PB5
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//ADREAD->PD2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
// COVA->PA8, COVB->PA11, ADRESET->PA13
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//ADFIRST->PA14
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
// Oversampling rate setting
void AD7606_SetOS(AD7606_OS_E ucOS)
{
switch (ucOS)
{
case AD_OS_NO: OS2_0(); OS1_0(); OS0_0(); break;
case AD_OS_X2: OS2_0(); OS1_0(); OS0_1(); break;
case AD_OS_X4: OS2_0(); OS1_1(); OS0_0(); break;
case AD_OS_X8: OS2_0(); OS1_1(); OS0_1(); break;
case AD_OS_X16: OS2_1(); OS1_0(); OS0_0(); break;
case AD_OS_X32: OS2_1(); OS1_0(); OS0_1(); break;
case AD_OS_X64: OS2_1(); OS1_1(); OS0_0(); break;
default: OS2_0(); OS1_0(); OS0_0(); break;
}
}
//AD7606 initialization
void AD7606Initialization(void)
{
delay_ms(1);
AD7606_RESET_0
AD7606_SetOS(AD_OS_NO);
AD7606_CS_0
AD7606_RD_1
delay_ms(1);
AD7606Reset();
}
//AD7606 Reset
void AD7606Reset(void)
{
AD7606_RESET_1;
delay_us(1);
AD7606_RESET_0;
delay_us(1);
}
// Reading data
void AD7606ReadSample(void)
{
uint8_t i;
char ad_buffer[20] = {
0};
short ad_value[4] = {
0};
for(i = 0; i < 4; i++)
{
AD7606_RD_0
__NOP();
ad_buffer[i] = READ_AD_DATA;
AD7606_RD_1;
__NOP();
}
sprintf(ad_buffer, "%d %d %d %d ", ad_buffer[0], ad_buffer[1], ad_buffer[2], ad_buffer[3]);
USART2_SendStr(ad_buffer);
}
// Frequency settings
void PWM_ModeConfig(uint32_t frequency)
{
uint32_t arr_value, psc_value;
// Initialize structure
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
// Turn on the port clock and reset the clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
// Turn on the timer clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
// Pin configuration
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* * PWM(Hz) = 72MHz / ((ARR + 1) * (PSC + 1)) * ARR(arr_value) -> TIM_Period * PSC(psc_value) -> TIM_Prescaler */
psc_value = 72 - 1;
arr_value = SystemCoreClock / (psc_value + 1) / frequency - 1;
// Count value ,TIM_Period + 1
TIM_TimeBaseStructure.TIM_Period = arr_value;
// Prescaled value ,TIM_Perscaler + 1
TIM_TimeBaseStructure.TIM_Prescaler = psc_value;
// Clock division factor
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
// Counter counting mode , Count up
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
// Initialize the timer
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
//PWM Pattern
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
// Output enable
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
// Output channel level polarity configuration
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
// Output comparison channel 1
TIM_OCInitStructure.TIM_Pulse = 4;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
// Output comparison channel 4
TIM_OCInitStructure.TIM_Pulse = 4;
TIM_OC4Init(TIM1, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(TIM1, TIM_OCPreload_Enable);
// Allow or prohibit the timer to work when ARR Write a new value to the buffer of
TIM_ARRPreloadConfig(TIM1, ENABLE);
// Enable timer
TIM_Cmd(TIM1, ENABLE);
// Main output enable , Only valid when using advanced timer
TIM_CtrlPWMOutputs(TIM1, ENABLE);
}
//busy Interrupt configuration
void AD7606_Busy_IRQ(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable GPIOA clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
// Disable debugging interface
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource15);
EXTI_InitStructure.EXTI_Line = EXTI_Line15;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
4、 The header file
#ifndef _AD7606_H_
#define _AD7606_H_
#include "stm32f01x.h"
#define READ_AD_DATA GPIO_ReadInputData(GPIOC)
#define OS0_1() GPIO_SetBits(GPIOB, GPIO_Pin_6);
#define OS0_0() GPIO_ResetBits(GPIOB, GPIO_Pin_6);
#define OS1_1() GPIO_SetBits(GPIOB, GPIO_Pin_5);
#define OS1_0() GPIO_ResetBits(GPIOB, GPIO_Pin_5);
#define OS2_1() GPIO_SetBits(GPIOB, GPIO_Pin_4);
#define OS2_0() GPIO_ResetBits(GPIOB, GPIO_Pin_4);
#define AD7606_CS_1 GPIO_SetBits(GPIOB, GPIO_Pin_3);
#define AD7606_CS_0 GPIO_ResetBits(GPIOB, GPIO_Pin_3);
#define AD7606_RD_1 GPIO_SetBits(GPIOD, GPIO_Pin_2);
#define AD7606_RD_0 GPIO_ResetBits(GPIOD, GPIO_Pin_2);
#define AD7606_RESET_1 GPIO_SetBits(GPIOA, GPIO_Pin_13);
#define AD7606_RESET_0 GPIO_ResetBits(GPIOA, GPIO_Pin_13);
#define AD7606_CONVST_1 GPIO_SetBits(GPIOA, GPIO_Pin_8 | GPIO_Pin_11);
#define AD7606_CONVST_0 GPIO_ResetBits(GPIOA, GPIO_Pin_8 | GPIO_Pin_11);
#define AD7606_BUSY_STATE GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_15)
#define AD7606_FRSTDATA_STATE GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_14)
typedef enum
{
AD_OS_NO = 0,
AD_OS_X2 = 1,
AD_OS_X4 = 2,
AD_OS_X8 = 3,
AD_OS_X16 = 4,
AD_OS_X32 = 5,
AD_OS_X64 = 6
}AD7606_OS_E;
void AD7606Initialization(void);
void AD7606Reset(void);
void AD7606ReadSample(void);
void AD7606_GPIOConfig(void);
void AD7606_PWM_ModeConfig(uint32_t frequency);
void AD7606_SetOS(uint8_t _ucOS);
void AD7606_Busy_IRQ(void);
void AD7606_IRQ_Disable(void);
void AD7606_IRQ_Enable(void);
#endif /*_AD7606_H*/
Serial transmission can be found in this article
5、 application
#include "stm32f10x.h"
#include "ad7606.h"
int main(void)
{
AD7606Initialization();
// Frequency settings 20k
AD7606_PWM_ModeConfig(20000);
// Set and enter interrupt
AD7606_Busy_IRQ();
while(1)
{
}
}
// Interrupt service function
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line15) != RESET)
{
AD7606ReadSample();
EXTI_ClearITPendingBit(EXTI_Line15);
}
}
6、 Download Chinese resources
link :https://pan.baidu.com/s/1l4AseVGhHjZcd0mLW5btLQ
Extraction code :a0ko
边栏推荐
- 软考回顾及计划
- 五、域对象共享数据
- ES6 modularization +commonjs
- Embedded practice -- CPU utilization statistics based on rt1170 FreeRTOS (24)
- [semantic segmentation] 2018-deeplabv3+ ECCV
- 数据库启动报:ORA-29702: error occurred in Cluster Group Service
- Is this my vs not connected to the database
- 九、文件上传和下载
- Use Baidu PaddlePaddle easydl to complete garbage classification
- 2022河南萌新联赛第(三)场:河南大学 J - 神奇数字
猜你喜欢

7、 Restful

What is the difference between asynchronous and synchronous transmission signals (electronic hardware)

User defined type details

2022河南萌新联赛第(三)场:河南大学 L - 合成游戏

egg-ts-sequelize-CLI

UE4 displays text when it is close to the object, and disappears when it is far away

SQL加解密注入详解

七、RESTful

快恢复二极管工作原理及使用

UE4 靠近物体时显示文字,远离时文字消失
随机推荐
MySQL 执行失败的sql是否会计入慢查询?
5、 Domain objects share data
Spark Structured Streaming HelloWorld
An SQL server queries the latest records as of a certain date
Embedded practice -- CPU utilization statistics based on rt1170 FreeRTOS (24)
九、文件上传和下载
vector详解和迭代器失效问题
2022 Henan Mengxin League game (3): Henan University J - magic number
[semantic segmentation] 2018-deeplabv3+ ECCV
How to build an automated testing framework?
一、基础入门
数据库连接数查看和修改
The difference between positive samples, negative samples, simple samples and difficult samples in deep learning (simple and easy to understand)
MySQL usage
[enterprise micro procedure]
Throttling anti shake function of JS handwritten function
Postman imports curl, exports curl, and exports corresponding language codes
7、 Restful
建设面向青少年的创客教育实验室
Weights & Biases (二)