CH592ADC中断函数切换通道代码参考:
#include "CH59x_common.h"
#define adctest 1
volatile uint8_t adclen;
volatile uint8_t DMA_end = 0;
uint16_t adcBuff[40];
uint8_t adcindex = 0;
uint8_t adcchannel = 0;
enum channel{
channel_0,
channel_1,
channel_2,
channel_3,
};
void DebugInit(void){
GPIOB_SetBits(bTXD2);
GPIOB_ModeCfg(bRXD2, GPIO_ModeIN_PU);
GPIOB_ModeCfg(bTXD2, GPIO_ModeOut_PP_5mA);
UART2_DefInit();
}
int main(){
uint8_t i;
signed short RoughCalib_Value = 0; // ADC粗调偏差值
SetSysClock(CLK_SOURCE_PLL_60MHz);
/* 配置串口调试 */
DebugInit();
UART2_BaudRateCfg(1500000);
PRINT("Start @ChipID=%02X\n", R8_CHIP_ID);
/* 单通道采样:中断方式,选择adc通道1做采样,对应 PA5引脚, 不带数据校准功能 */
PRINT("\n6.Single channel sampling in interrupt mode...\n");
GPIOA_ModeCfg(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13, GPIO_ModeIN_Floating);
ADC_ExtSingleChSampInit(SampleFreq_3_2, ADC_PGA_0);
ADC_ChannelCfg(adcchannel);
ADC_ClearITFlag();
PFIC_EnableIRQ(ADC_IRQn);
ADC_StartUp();
while(1){
mDelaymS(100);
printf("%d %d %d %d\n",adcBuff[0],adcBuff[1],adcBuff[2],adcBuff[3] );
memset(adcBuff, 0, 4);
ADC_ClearITFlag();
ADC_ChannelCfg(adcchannel);
PFIC_EnableIRQ(ADC_IRQn);
ADC_StartUp();
}
}
__INTERRUPT
__HIGH_CODE
void ADC_IRQHandler(void) //adc中断服务程序
{
if(ADC_GetITStatus())
{
ADC_ClearITFlag();
switch(adcchannel)
{
case channel_0:
adcBuff[adcindex] = ADC_ReadConverValue();
adcindex++;
adcchannel = channel_1;
ADC_ChannelCfg(adcchannel); //先选择通道,再开启新一轮采样
ADC_StartUp();// 作用清除中断标志并开启新一轮采样
break;
case channel_1:
adcBuff[adcindex] = ADC_ReadConverValue();
adcindex++;
adcchannel = channel_2;
ADC_ChannelCfg(adcchannel);
ADC_StartUp();
break;
case channel_2:
adcBuff[adcindex] = ADC_ReadConverValue();
adcindex++;
adcchannel = channel_3;
ADC_ChannelCfg(adcchannel);
ADC_StartUp();
break;
case channel_3:
adcBuff[adcindex] = ADC_ReadConverValue();
adcindex++;
adcindex = 0;
adcchannel = channel_0;
PFIC_DisableIRQ(ADC_IRQn);
break;
default:
break;
}
}
}
标签:adcindex,中断,adcBuff,ADC,GPIO,adcchannel,channel,切换 From: https://www.cnblogs.com/gscw/p/18396714