Nikolay801_ (30.11.2015 13:25 - 13:27, просмотров: 294) ответил SciFi на ST - самки собаки. STM32F2, если ПДП запускается от АЦП, то его клинит. А если от таймера, от которого запускается АЦП, то не клинит. Где логика? Зачем эти грабли? дблблд...
я в четверке вот так делаю, у двушки по моему будет также.
#define ADC_DR_ADDRESS ((uint32_t) & (ADC1->DR))
/*******************************************************************************
*/
void adc1Init(void){
ADC_InitTypeDef ADC_InitStructure = {0};
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC regular channel configuration */
//ADC_RegularChannelConfig(ADC1, ADC_Channel_TempSensor, 2, ADC_SampleTime_480Cycles);
//ADC_RegularChannelConfig(ADC1, ADC_Channel_Vrefint, 1, ADC_SampleTime_480Cycles);
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_15Cycles);
ADC_Cmd(ADC1, ENABLE);
}
void Applicaton_tag::init(void){
DMA_InitTypeDef DMA_InitStructure = {0};
/* Enable ADC3, DMA2 and GPIO clocks ****************************************/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
DMA_DoubleBufferModeConfig(DMA2_Stream0, (uint32_t)dmaBuf[1], DMA_Memory_1);
DMA_DoubleBufferModeCmd(DMA2_Stream0, ENABLE);
/* DMA2 Stream0 channel2 configuration **************************************/
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC_DR_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)dmaBuf[0];
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = DMA_BUF_SIZE;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream0, &DMA_InitStructure);
DMA_Cmd(DMA2_Stream0, ENABLE);
adcCmnInit();
adc1Init();
adc2Init();
//adc3Init();
/* Enable DMA request after last transfer (Single-ADC mode) */
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
/* Enable ADC3 DMA */
ADC_DMACmd(ADC1, ENABLE);
ADC_AnalogWatchdogThresholdsConfig(ADC2, limitVal[SI_I2].max, limitVal[SI_I2].min);
/* Configure channel14 as the single analog watchdog guarded channel */
ADC_AnalogWatchdogSingleChannelConfig(ADC2, ADC_Channel_13);
/* Enable analog watchdog on one regular channel */
ADC_AnalogWatchdogCmd(ADC2, ADC_AnalogWatchdog_AllRegEnable);
//DACconfig();
//TIM_Config();
ADC2->CR1 &= ~(uint32_t)ADC_CR1_AWDIE;
ADC1->CR2 |= (uint32_t)ADC_CR2_SWSTART;
ADC2->CR2 |= (uint32_t)ADC_CR2_SWSTART;
//ADC3->CR2 |= (uint32_t)ADC_CR2_SWSTART;
NVIC_InitTypeDef NVIC_InitStructure = {0};
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
DMA_ITConfig(DMA2_Stream0 ,DMA_IT_TC , ENABLE);
}
/*******************************************************************************
*/
extern "C" void DMA2_Stream0_IRQHandler(void){
if (DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0) != RESET){
register uint16_t *pt;
register uint32_t dataL = 0;
#pragma data_alignment=4
//static uint32_t dataSum = 0;
static uint32_t cnt = 0;
X1_ON();
DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);
if (DMA_GetCurrentMemoryTarget(DMA2_Stream0) != 0){
pt = (uint16_t *) dmaBuf[0];
}else
pt = (uint16_t *) dmaBuf[1];
cnt++;
for(int i = 0; i < (DMA_BUF_SIZE / 8); i++){
dataL += pt[0];
dataL += pt[1];
dataL += pt[2];
dataL += pt[3];
dataL += pt[4];
dataL += pt[5];
dataL += pt[6];
dataL += pt[7];
pt += 8;
}
dataL = dataL / DMA_BUF_SIZE;
X1_OFF();
}
дма работет в режиме двойной буферизации.
ну и блюмбатека, не кошерно. Звиняйте.
Будь ты проклят, Перри-Утконос!