开源一个 ADS8365 高精度 ADC 检测方案,转载请联系博主,翻版必究。
1、硬件原理图(最多 6 路输入)
2、数据手册
数据手册在这里下载
https://www.alldatasheetcn.com/
3、软件
整体实现思路:
1、开机初始化时钟。
2、初始化 timer4 做 clock 给 ADS8365 使用(PWM)。
3、初始化 ADS8365 用到的 GPIO。
4、初始化 timer3,以 50hz 频率产生定时器中断,在中断处理函数中复位 ADS8365。
5、初始化 ADS8365 的中断,在 GPIO 中断处理函数中,读取 ADS8365 数据。
6、校准。
7、读取数据。
ADS8365.c
#include "ads8365.h"
static void ADS8365_NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* ÅäÖÃP[A|B|C|D|E]0ΪÖжÏÔ´ */
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
static void ADS8365_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
/* config the NVIC(PA9) */
ADS8365_NVIC_Configuration();
/* EXTI line gpio config(PA9) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //EOC
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* EXTI line(PA9) mode config */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource9);
EXTI_InitStructure.EXTI_Line = EXTI_Line9;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_10| GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | \
GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | \
GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | \
GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
EXTI->IMR &= ~(1<<9);
}
void ADS8365_Init(void)
{
ADS8365_GPIO_Config();
GPIO_SetBits(GPIOB, GPIO_Pin_15);//CS
GPIO_ResetBits(GPIOB, GPIO_Pin_15);//CS
}
ADS8365.h
#ifndef __ADS8365_H__
#define __ADS8365_H__
#include "comm.h"
#include <stm32f10x.h>
#define Set_ADS8365_HOLD PAout(10)=1
#define Reset_ADS8365_HOLD PAout(10)=0
#define Set_ADS8365_nRST PAout(11)=1
#define Reset_ADS8365_nRST PAout(11)=0
#define Set_ADS8365_nOE PAout(8)=1
#define Reset_ADS8365_nOE PAout(8)=0
#define Set_ADS8365_CS PBout(15)=1
#define Reset_ADS8365_CS PBout(15)=0
void ADS8365_Init(void);
#endif
main.c
ADS8365_Init();
Set_ADS8365_nOE;
Reset_ADS8365_nOE;
testtmp = GPIOE->IDR;
Set_ADS8365_nOE;
如需源码请联系博主