STM8L探索套件学习笔记-ADC_DMA(十五)
时间:11-24
来源:互联网
点击:
使用ADC的DMA功能,每次连续转换8个数据,然后平均显示到LCD上。
主要代码如下:
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)
{
}
}
主要代码如下:
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)
{
}
}
STM8L学习笔记ADCDM 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)