需求:用较多adc通道来采集多路(至少16路)电压。现看中F373系列有21个采样通道(尽可能全部利用),所以想利用SDADC1、SDADC2、SDADC3的尽可能多的通道+DMA来实现。目前尝试着利用DMA2的channel3、4、5分别来存储SDADC1(3P、8P)、2(0P、1P)、3(7P、8P)三路的各自两个通道采集的电压,并分别在DMA三个通道的中断函数中将采集的电压通过串口打印。问题1:在增加SDADC_InjectedSynchroSDADC1(SDADC2,ENABLE);
SDADC_InjectedSynchroSDADC1(SDADC3,ENABLE);
这两句代码后,最多只能打印出SDADC1、2两路或者SDADC1、3两路的各自4个通道的电压,不能实现6个通道全部打印。因为刚接触不久,了解有限,不清楚是否能够同时利用DMA实现三路SDADC的采集,希望大家能够给我这个菜鸟一点帮助?
问题2:由于后期需要对多路SDADC采集的数据处理,考虑在中断函数中只进行标志位的设置,在main函数中根据标志位分别将采集的电压打印,但是,采集电压打印代码在在中断函数中时,SDADC1、2两路四个通道的电压能够正常输出,但将代码移至main中,通过判断标志位来输出时,只能输出SDADC1两路通道的采集电压,这又是为什么呢?
代码如下:
/* Includes ------------------------------------------------------------------*/
#include "stm32f37x.h"
#include "stdio.h" //2017.01.09heìí¼ó
/* Private variables ---------------------------------------------------------*/
uint16_t flag=0;
uint32_t TimingDelay = 0;
/* Private define ------------------------------------------------------------*/
#define SDADC1_DR_Address 0x40016060 //2017.01.10 heìí¼ó SDADC1íaéèμÄ»ùμØÖ·(0x4001 6000)¼óéÏSDADC data register for injected group (SDADC_JDATAR)μÄμØÖ·Æ«òÆ(0x60)¼ÆËãμÃμ½
#define SDADC2_DR_Address 0x40016460 //2017.01.12 heìí¼ó
#define SDADC3_DR_Address 0x40016860 //2017.01.12 heìí¼ó
/* Private typedef --------------------------------2017.01.12 heìí¼ó--------------*/
typedef struct{ uint16_t SDADC_InjectedConvData[6];} SDADC_ALLDATA;
typedef struct{ uint16_t SDADC1_InjectedConvData[2];
uint16_t SDADC2_InjectedConvData[2];
uint16_t SDADC3_InjectedConvData[2];} SDADC_EACHDATA;
typedef union{ SDADC_ALLDATA SDADC_AllData;
SDADC_EACHDATA SDADC_EachData;} SDADC_DATA;
SDADC_DATA SDADC_Data;
//2017.01.09he begin
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
PUTCHAR_PROTOTYPE
{
USART_SendData(USART1, (uint8_t) ch); //·¢Ëíò»×Ö½úêy¾Y
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
{} //μè′y·¢Ëííê3é
return ch;
}
//2017.01.09he end
void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC|RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOE, ENABLE);
/* LEDS */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStructure);
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_11;
// GPIO_Init(GPIOC, &GPIO_InitStructure);
//
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
// GPIO_Init(GPIOA, &GPIO_InitStructure);
// GPIO_SetBits(GPIOA,GPIO_Pin_3); 2017.01.09 he×¢êí
}
void SysTick_Handler(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
void DDelay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
uint32_t SDADC_Config(void) //2017.01.11heDT¸Ä
{
SDADC_AINStructTypeDef SDADC_AINStructure;
GPIO_InitTypeDef GPIO_InitStructure;
uint32_t SDADCTimeout = 0;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDADC1|RCC_APB2Periph_SDADC2|RCC_APB2Periph_SDADC3, ENABLE);//2017.01.11heDT¸Ä
SDADC_DeInit(SDADC1);
SDADC_DeInit(SDADC2); //2017.01.11heìí¼ó
SDADC_DeInit(SDADC3); //2017.01.11heìí¼ó
/* PWR APB1 interface clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Enable SDADC analog interface */
PWR_SDADCAnalogCmd(PWR_SDADCAnalog_1|PWR_SDADCAnalog_2|PWR_SDADCAnalog_3, ENABLE);//2017.01.11heDT¸Ä
/* Set the SDADC divider: The SDADC should run @6MHz */
/* If Sysclk is 72MHz, SDADC divider should be 12 */
RCC_SDADCCLKConfig(RCC_SDADCCLK_SYSCLK_Div12);
/* GPIO Peripheral clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE|RCC_AHBPeriph_GPIOB, ENABLE); //2017.01.11heDT¸Ä
/* SDADC1 channel 3P 8P pin configuration: PE7 PE8*/ /* SDADC2 channel 4P 3P pin configuration: PE11 PE12*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_11|GPIO_Pin_12; //2017.01.11heDT¸Ä
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_14|GPIO_Pin_15; //2017.01.11heDT¸Ä
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* SDADC3 channel 8P 7P pin configuration: PB14 PB15*/ //2017.01.11heìí¼ó
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14|GPIO_Pin_15;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Select External reference: The reference voltage selection is available
only in SDADC1 and therefore to select the VREF for SDADC2/SDADC3, SDADC1
clock must be already enabled */
SDADC_VREFSelect(SDADC_VREF_VDDA);
/* Insert delay equal to ~5 ms */
DDelay(5);
SDADC_Cmd(SDADC1, ENABLE);
SDADC_Cmd(SDADC2, ENABLE); //2017.01.12heìí¼ó
SDADC_Cmd(SDADC3, ENABLE); //2017.01.12heìí¼ó
SDADC_InitModeCmd(SDADC1, ENABLE);
SDADC_InitModeCmd(SDADC2, ENABLE); //2017.01.12heìí¼ó
SDADC_InitModeCmd(SDADC3, ENABLE); //2017.01.12heìí¼ó
SDADCTimeout = 30;
/* wait for INITRDY flag to be set */
while((SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_INITRDY) == RESET) && ((SDADC_GetFlagStatus(SDADC2, SDADC_FLAG_INITRDY) == RESET))
&& ((SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_INITRDY) == RESET)) && (--SDADCTimeout != 0)); //2017.01.12heDT¸Ä
if(SDADCTimeout == 0)
{
/* INITRDY flag can not set */
return 1;
}
SDADC_AINStructure.SDADC_InputMode = SDADC_InputMode_SEOffset;
SDADC_AINStructure.SDADC_Gain = SDADC_Gain_1_2;//GAIN is 0.5
SDADC_AINStructure.SDADC_CommonMode = SDADC_CommonMode_VSSA;
SDADC_AINStructure.SDADC_Offset = 0;
SDADC_AINInit(SDADC1, SDADC_Conf_0, &SDADC_AINStructure);
SDADC_AINInit(SDADC2, SDADC_Conf_0, &SDADC_AINStructure); //2017.01.12heìí¼ó
SDADC_AINInit(SDADC3, SDADC_Conf_0, &SDADC_AINStructure); //2017.01.12heìí¼ó
SDADC_ChannelConfig(SDADC1, SDADC_Channel_3|SDADC_Channel_8, SDADC_Conf_0); //DT¸Ä
SDADC_ChannelConfig(SDADC2, SDADC_Channel_0|SDADC_Channel_1, SDADC_Conf_0); //2017.01.12heìí¼ó
SDADC_ChannelConfig(SDADC3, SDADC_Channel_7|SDADC_Channel_8, SDADC_Conf_0); //2017.01.12heìí¼ó
SDADC_InjectedChannelSelect(SDADC1,SDADC_Channel_3|SDADC_Channel_8); //2017.01.10 heìí¼ó ±ØDëÕaÑù2Å¿éòÔ£¬·Ö¿aÅäÖÃμÄ»°£¬oóÃæÅäÖÃμÄí¨μà»á¸2¸ÇÇ°ÃæμÄ
SDADC_InjectedChannelSelect(SDADC2,SDADC_Channel_0|SDADC_Channel_1); //2017.01.12heìí¼ó
SDADC_InjectedChannelSelect(SDADC3,SDADC_Channel_7|SDADC_Channel_8); //2017.01.12heìí¼ó
SDADC_InjectedContinuousModeCmd(SDADC1,ENABLE); //2017.01.10 heìí¼ó
SDADC_InjectedContinuousModeCmd(SDADC2,ENABLE); //2017.01.12 heìí¼ó
SDADC_InjectedContinuousModeCmd(SDADC3,ENABLE); //2017.01.12 heìí¼ó
/* Select an external trigger */
SDADC_ExternalTrigInjectedConvConfig(SDADC1, SDADC_ExternalTrigInjecConv_T19_CC2); //2017.01.12 heDT¸Ä Trigger source for SDADC1
SDADC_ExternalTrigInjectedConvConfig(SDADC1, SDADC_ExternalTrigInjecConv_T19_CC3); //2017.01.11 heìí¼ó Trigger source for SDADC2
SDADC_ExternalTrigInjectedConvConfig(SDADC1, SDADC_ExternalTrigInjecConv_T19_CC4); //2017.01.11 heìí¼ó Trigger source for SDADC3
/* Select rising edge */
SDADC_ExternalTrigInjectedConvEdgeConfig(SDADC1, SDADC_ExternalTrigInjecConvEdge_Rising); //2017.01.11 heìí¼ó
SDADC_ExternalTrigInjectedConvEdgeConfig(SDADC2, SDADC_ExternalTrigInjecConvEdge_Rising); //2017.01.12 heìí¼ó
SDADC_ExternalTrigInjectedConvEdgeConfig(SDADC3, SDADC_ExternalTrigInjecConvEdge_Rising); //2017.01.12 heìí¼ó
SDADC_DMAConfig(SDADC1,SDADC_DMATransfer_Injected,ENABLE); //2017.01.10 heìí¼ó
SDADC_DMAConfig(SDADC2,SDADC_DMATransfer_Injected,ENABLE); //2017.01.12 heìí¼ó
SDADC_DMAConfig(SDADC3,SDADC_DMATransfer_Injected,ENABLE); //2017.01.12 heìí¼ó
SDADC_InjectedSynchroSDADC1(SDADC3,ENABLE);
SDADC_InjectedSynchroSDADC1(SDADC2,ENABLE);
SDADC_InitModeCmd(SDADC1, DISABLE);
SDADC_InitModeCmd(SDADC2, DISABLE); //2017.01.12 heìí¼ó
SDADC_InitModeCmd(SDADC3, DISABLE); //2017.01.12 heìí¼ó
/* configure calibration to be performed on conf0 */
SDADC_CalibrationSequenceConfig(SDADC1, SDADC_CalibrationSequence_1);
SDADC_CalibrationSequenceConfig(SDADC2, SDADC_CalibrationSequence_1); //2017.01.12 heìí¼ó
SDADC_CalibrationSequenceConfig(SDADC3, SDADC_CalibrationSequence_1); //2017.01.12 heìí¼ó
/* start PT100_SDADC Calibration */
SDADC_StartCalibration(SDADC1);
SDADC_StartCalibration(SDADC2); //2017.01.12 heìí¼ó
SDADC_StartCalibration(SDADC3); //2017.01.12 heìí¼ó
/* Set calibration timeout: 5.12 ms at 6 MHz in a single calibration sequence */
SDADCTimeout = 4*30720 ;
/* wait for PT100_SDADC Calibration process to end */
while((SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_EOCAL) == RESET) && (SDADC_GetFlagStatus(SDADC2, SDADC_FLAG_EOCAL) == RESET)
&& (SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_EOCAL) == RESET) && (--SDADCTimeout != 0)); //2017.01.12heDT¸Ä
if(SDADCTimeout == 0)
{
/* EOCAL flag can not set */
return 2;
}
/* SDADC successfully configured */
return 0;
}
//2017.01.10he ìí¼óDMAÅäÖÃoˉêy
void DMA_Config(void) //2017.01.12 heDT¸Ä
{
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2,ENABLE);
DMA_DeInit(DMA2_Channel3); //»Ö¸′ĬèÏÖ죬Õa¸öêDZØòaμÄ SDADC1
DMA_DeInit(DMA2_Channel4); //2017.01.12 heìí¼ó SDADC2
DMA_DeInit(DMA2_Channel5); //2017.01.12 heìí¼ó SDADC3
/* DMA2 channel3 configuration ----------------------------------------------*/
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(SDADC_Data.SDADC_EachData.SDADC1_InjectedConvData); //DMAóëmemoryᬽóμıäá¿μÄμØÖ·£¬¶¨òå±äá¿
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //éèÖÃDMAμÄ′«êä·½Ïò£¬′Ë′|Îaμ¥Ïò′«ê䣻˫Ïò′«êä£oDMA_DIR_PeripheralDST
DMA_InitStructure.DMA_BufferSize = 2; //éèÖÃDMAÔú′«êäê±»o3åÇøμÄ3¤¶è
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //éèÖÃDMAμÄíaéèμYÔöģ꽣¬èôóD¶à¸öíaéèᬽó£¬ÔòDèòaê1óÃíaéèμYÔöģ꽣¬′Ë′|Ö»óëSDADC1½¨á¢áaÏμ
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //DMA_MemoryInc_Disable; DMA·ÃÎê¶à¸öÄú′æ2Îêyê±ê1óÃEnable,·ÃÎêò»¸öÄú′æ2Îêyê±ê1óÃDisable
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //éèÖÃDMAÔú·ÃÎêê±Ã¿′Î2ù×÷μÄêy¾Y3¤¶è óD3ÖÖêy¾YààDí£oByte¡¢HalfWord¡¢word
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //1¸öHalfwordÕ¼16λ
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //éèÖÃDMAμÄ′«êäģ꽣oá¬Dø2»¶ÏμÄÑ-»·Ä£ê½£¬èôÖ»Ïë·ÃÎêò»′λò°′Ö¸áî2ù×÷à′·ÃÎ꣬¿ééèÖÃ3éNormalÄ£ê½
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //éèÖÃDMAμÄóÅÏ輶±e VeryHigh,High,Medium,Low
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //éèÖÃDMAμÄ2¸ömemoryÖDμıäá¿»¥Ïà·ÃÎê
DMA_Init(DMA2_Channel3, &DMA_InitStructure);
/* DMA2 channel4 configuration -------------- 2017.01.12 heìí¼ó-----------------*/
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDADC2_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(SDADC_Data.SDADC_EachData.SDADC2_InjectedConvData); //DMAóëmemoryᬽóμıäá¿μÄμØÖ·£¬¶¨òå±äá¿
DMA_Init(DMA2_Channel4, &DMA_InitStructure);
/* DMA2 channel5 configuration ---------------2017.01.12 heìí¼ó--------------*/
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDADC3_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(SDADC_Data.SDADC_EachData.SDADC3_InjectedConvData); //DMAóëmemoryᬽóμıäá¿μÄμØÖ·£¬¶¨òå±äá¿
DMA_Init(DMA2_Channel5, &DMA_InitStructure);
/* NVIC Configuration */ //2017.01.10 heìí¼ó
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Channel3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* NVIC Configuration */ //2017.01.12 heìí¼ó
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Channel4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* NVIC Configuration */ //2017.01.12 heìí¼ó
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Channel5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable DMA2 Channel3 Transfer half interrupt */
DMA_ITConfig(DMA2_Channel3, DMA_IT_HT, ENABLE); //2017.01.11heDT¸Ä
DMA_ITConfig(DMA2_Channel4, DMA_IT_HT, ENABLE); //2017.01.12 heìí¼ó
DMA_ITConfig(DMA2_Channel5, DMA_IT_HT, ENABLE); //2017.01.12 heìí¼ó
/* Enable DMA2 channel3/4/5 */
DMA_Cmd(DMA2_Channel3, ENABLE);
DMA_Cmd(DMA2_Channel4, ENABLE);
DMA_Cmd(DMA2_Channel5, ENABLE);
}
//2017.01.09he ìí¼ó′®¿úÅäÖÃoˉêy
void USART_Config(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* Connect pin to Periph */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_7);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_7);
/* Configure pins as AF pushpull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* USARTx configured as follow:
- BaudRate = 19200 baud
- Word Length = 8 Bits
- Stop Bit = 1 Stop Bit
- Parity = No Parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_DeInit(USART1);
USART_InitStructure.USART_BaudRate = 19200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
/* USART enable */
USART_Cmd(USART1, ENABLE);
}
//2017.01.10he ìí¼ó¶¨ê±Æ÷ÅäÖÃoˉêy
void TIM19_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the TIM19 Interrupt for capture compare event */
NVIC_InitStructure.NVIC_IRQChannel = TIM19_IRQn; //2017.01.12heDT¸Ä
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable TIM19 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM19, ENABLE); //2017.01.12heDT¸Ä
/* TIM19 Configuration */
TIM_DeInit(TIM19); //2017.01.12heDT¸Ä
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 900000;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM19, &TIM_TimeBaseStructure); //2017.01.12heDT¸Ä
/* PWM Mode configuration: Channel2/3/4 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 4500 ;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC2Init(TIM19, &TIM_OCInitStructure); //2017.01.12heDT¸Ä channel2 TIM19 SDADC1
TIM_OC3Init(TIM19, &TIM_OCInitStructure); //2017.01.12 heìí¼ó channel3 SDADC2
TIM_OC4Init(TIM19, &TIM_OCInitStructure); //2017.01.12 heìí¼ó channel4 SDADC3
}
main()
{
double t;
unsigned int i;
RCC_ClocksTypeDef RCC_Clocks;
/* SysTick end of count event each 1ms */
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
GPIO_Config();
USART_Config(); //2017.01.09he ìí¼ó
DMA_Config(); //2017.01.10he ìí¼ó
if(SDADC_Config() != 0) //2017.01.11he DT¸Ä
{
printf("Fail to configure SigmaDelta Converter");
while(1);
}
/* Configure TIM19 as trigger for SDADC conversion */
TIM19_Config(); //2017.01.12he DT¸Ä
TIM_Cmd(TIM19, ENABLE); //2017.01.12he DT¸Ä
printf("
while begin.
");
while(1)
{
// if(flag==1)
// {
// flag=0;
// printf("
flag1..
");
// for(i=0;i<600000;i++);
// for(i=0;i<600000;i++);
// GPIO_ResetBits(GPIOC,GPIO_Pin_13);
//
// if(SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[0]<0)SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[0]=0;
// t=SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[0];
// t=t*3300/0.5/65536;//GAIN is 0.5
// printf("
SDADC1[3P]
E7--Voltage:0x%x. %fV.
",SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[0],t);
// if(SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[1]<0)SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[1]=0;
// t=SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[1];
// t=t*3300/0.5/65536;//GAIN is 0.5
// printf("
SDADC1[8P]
E8--Voltage:0x%x. %fV.
",SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[1],t);
//
// for(i=0;i<600000;i++);
// for(i=0;i<600000;i++);
// GPIO_SetBits(GPIOC,GPIO_Pin_13);
// }
// else if(flag==2)
// {
// flag=0;
// printf("
flag2..
");
// for(i=0;i<600000;i++);
// for(i=0;i<600000;i++);
// GPIO_ResetBits(GPIOC,GPIO_Pin_13);
//
// if(SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[2]<0)SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[2]=0;
// t=SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[2];
// t=t*3300/0.5/65536;//GAIN is 0.5
// printf("
SDADC2[0P]
E15--Voltage:0x%x. %fV.
",SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[2],t);
// if(SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[3]<0)SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[3]=0;
// t=SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[3];
// t=t*3300/0.5/65536;//GAIN is 0.5
// printf("
SDADC2[1P]
E14--Voltage:0x%x. %fV.
",SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[3],t);
//
// for(i=0;i<600000;i++);
// for(i=0;i<600000;i++);
// GPIO_SetBits(GPIOC,GPIO_Pin_13);
// }
// if(flag==3)
// {
// flag=0;
// printf("
flag3..
");
// for(i=0;i<600000;i++);
// for(i=0;i<600000;i++);
// GPIO_ResetBits(GPIOC,GPIO_Pin_13);
//
// if(SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[4]<0)SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[4]=0;
// t=SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[4];
// t=t*3300/0.5/65536;//GAIN is 0.5
// printf("
SDADC3[7P]
B15--Voltage:0x%x. %fV.
",SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[4],t);
// if(SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[5]<0)SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[5]=0;
// t=SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[5];
// t=t*3300/0.5/65536;//GAIN is 0.5
// printf("
SDADC3[8P]
B14--Voltage:0x%x. %fV.
",SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[5],t);
//
// for(i=0;i<600000;i++);
// for(i=0;i<600000;i++);
// GPIO_SetBits(GPIOC,GPIO_Pin_13);
// }
}
}
//2017.01.10he ìí¼ó DMA2 channel3 SDADC1ÖD¶Ï′|àíoˉêy
void DMA2_Channel3_IRQHandler(void)
{
double t;
unsigned int i;
// flag = 1;
// DMA_ClearFlag(DMA2_FLAG_HT3);
// printf("
DMA2-3 Interrupt.
");
if(DMA_GetFlagStatus(DMA2_FLAG_HT3) != RESET)
{
for(i=0;i<600000;i++);
for(i=0;i<600000;i++);
GPIO_ResetBits(GPIOC,GPIO_Pin_13);
if(SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[0]<0)SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[0]=0;
t=SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[0];
t=t*3300/0.5/65536;//GAIN is 0.5
printf("
SDADC1[3P]
E7--Voltage:0x%x. %fV.
",SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[0],t);
if(SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[1]<0)SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[1]=0;
t=SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[1];
t=t*3300/0.5/65536;//GAIN is 0.5
printf("
SDADC1[8P]
E8--Voltage:0x%x. %fV.
",SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[1],t);
for(i=0;i<600000;i++);
for(i=0;i<600000;i++);
GPIO_SetBits(GPIOC,GPIO_Pin_13);
}
}
//2017.01.12he ìí¼ó DMA2 channel4 SDADC2ÖD¶Ï′|àíoˉêy
void DMA2_Channel4_IRQHandler(void)
{
double t;
unsigned int i;
// flag = 2;
// DMA_ClearFlag(DMA2_FLAG_HT3);
// printf("
DMA2-4 Interrupt.
");
if(DMA_GetFlagStatus(DMA2_FLAG_HT3) != RESET)
{
for(i=0;i<600000;i++);
for(i=0;i<600000;i++);
GPIO_ResetBits(GPIOC,GPIO_Pin_13);
if(SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[2]<0)SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[2]=0;
t=SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[2];
t=t*3300/0.5/65536;//GAIN is 0.5
printf("
SDADC2[0P]
E15--Voltage:0x%x. %fV.
",SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[2],t);
if(SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[3]<0)SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[3]=0;
t=SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[3];
t=t*3300/0.5/65536;//GAIN is 0.5
printf("
SDADC2[1P]
E14--Voltage:0x%x. %fV.
",SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[3],t);
for(i=0;i<600000;i++);
for(i=0;i<600000;i++);
GPIO_SetBits(GPIOC,GPIO_Pin_13);
}
}
//2017.01.12he ìí¼ó DMA2 channel5 SDADC3ÖD¶Ï′|àíoˉêy
void DMA2_Channel5_IRQHandler(void)
{
double t;
unsigned int i;
// flag = 3;
// DMA_ClearFlag(DMA2_FLAG_HT3);
// printf("
DMA2-5 Interrupt.
");
if(DMA_GetFlagStatus(DMA2_FLAG_HT3) != RESET)
{
for(i=0;i<600000;i++);
for(i=0;i<600000;i++);
GPIO_ResetBits(GPIOC,GPIO_Pin_13);
if(SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[4]<0)SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[4]=0;
t=SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[4];
t=t*3300/0.5/65536;//GAIN is 0.5
printf("
SDADC3[7P]:PB15--Voltage:0x%x. %fV.
",SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[4],t);
if(SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[5]<0)SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[5]=0;
t=SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[5];
t=t*3300/0.5/65536;//GAIN is 0.5
printf("
SDADC3[8P]:PB14--Voltage:0x%x. %fV.
",SDADC_Data.SDADC_AllData.SDADC_InjectedConvData[5],t);
for(i=0;i<600000;i++);
for(i=0;i<600000;i++);
GPIO_SetBits(GPIOC,GPIO_Pin_13);
}
}
一周热门 更多>