当前位置:网站首页>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
边栏推荐
- How does win11 set the theme color of the status bar? Win11 method of setting theme color of status bar
- QT compilation error sorting and remote module Download
- egg-ts-sequelize-CLI
- 七、RESTful
- 嵌入式实操----基于RT1170 FreeRTOS实现CPU使用率统计(二十四)
- Yuansaka Lin wallpaper
- SQL加解密注入详解
- Rotate array minimum number
- Why is mongodb fast
- 常函数const的学习
猜你喜欢

七、RESTful

UE4 通过按键控制物体的旋转
![[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (VIII)](/img/a0/b2b0f5fb63301f5b7dd14302aa39e2.png)
[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (VIII)

二、国际知名项目-HelloWorld

Offline installation of idea plug-in (continuous update)

Bsdiff and bspatch incremental updates

Build a maker Education Laboratory for teenagers

How does win11 22h2 skip networking and Microsoft account login?

Wsl2 best practices, eliminate difficult xshell and finalshell

Keil v5安装和使用
随机推荐
Chapter 3 how to use sourcetree to submit code
egg-ts-sequelize-CLI
滑动窗口——leetcode题解
What are the consequences and problems of computer system restoration
Network Security Learning - permission promotion 2
autocomplete禁止表单自动填充
idea插件离线安装(持续更新)
Rotate array minimum number
Weights & biases (II)
How to build an automated testing framework?
How does win11 22h2 skip networking and Microsoft account login?
Spark Structured Streaming HelloWorld
Keil v5安装和使用
【语义分割】2018-DeeplabV3+ ECCV
Phaser (I): platform jumping collection game
Authentication Encyclopedia (cookies, sessions, tokens, JWT, single sign on), in-depth understanding and understanding of authentication
What if win11 cannot wake up from sleep? Solution of win11 unable to wake up during sleep
Array sort 1
1、 Basic introduction
快恢复二极管工作原理及使用