STM8L探索套件學(xué)習(xí)筆記-ADC_DMA(十五)
主要代碼如下:
void main(void)
{
/* Enable ADC1 clock */
CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
/* Enable DMA1 clock */
CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE);
LCD_GLASS_Init();
/* Initialize and configure ADC1 */
ADC_Init(ADC1, ADC_ConversionMode_Continuous, ADC_Resolution_12Bit, ADC_Prescaler_2);
ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 Channels 24 */
ADC_ChannelCmd(ADC1, ADC_Channel_24, ENABLE);
/* Connect ADC to DMA channel 0 */
SYSCFG_REMAPDMAChannelConfig(REMAP_DMA1Channel_ADC1ToChannel0);
DMA_Init(DMA1_Channel0, BUFFER_ADDRESS,
ADC1_DR_ADDRESS,
BUFFER_SIZE,
DMA_DIR_PeripheralToMemory,
DMA_Mode_Circular,
DMA_MemoryIncMode_Inc,
DMA_Priority_High,
DMA_MemoryDataSize_HalfWord);
/* DMA Channel0 enable */
DMA_Cmd(DMA1_Channel0, ENABLE);
/* Enable DMA1 channel0 Transfer complete interrupt */
DMA_ITConfig(DMA1_Channel0, DMA_ITx_TC, ENABLE);
/* DMA enable */
DMA_GlobalCmd(ENABLE);
/* Enable ADC1 DMA requests*/
ADC_DMACmd(ADC1, ENABLE);
/* Start ADC1 Conversion*/
ADC_SoftwareStartConv(ADC1);
enableInterrupts();
/* Infinite loop */
while (1)
{
}
}
評(píng)論