stm32F407之内部温度传感器
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; //独立模式
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;//分频为4,f(ADC)=21M
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; //失能DMA_MODE
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_20Cycles;//两次采样间隔20个周期
ADC_CommonInit(&ADC_CommonInitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_480Cycles);//规则通道配置,1表示规则组采样顺序
ADC_TempSensorVrefintCmd(ENABLE);//使能温度传感器的基准电源
ADC_Cmd(ADC1, ENABLE); //使能ADC1
ADC_DMACmd(ADC1, ENABLE); //使能ADC1的DMA
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE); //单通道模式下上次转换完成后DMA请求允许,也就是持续DMA
}
/*************************************************
Function: void USART_Config(void)
Description: USART配置函数
Input: 无
Output:无
Return:无
*************************************************/
void USART_Config(void)
{
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE); //开启USART6时钟
/* 配置USART6 */
USART_StructInit(&USART_InitStructure);
USART_InitStructure.USART_BaudRate =115200;
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(USART6, &USART_InitStructure);
USART_ClockStructInit(&USART_ClockInitStruct); //之前没有填入缺省值,是不行的
USART_ClockInit(USART6, &USART_ClockInitStruct);
USART_ITConfig(USART6, USART_IT_RXNE, ENABLE); //使能 USART6中断
USART_Cmd(USART6, ENABLE); //使能 USART6
}
void NVIC_Config()
{
/* USART6中断配置 */
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //嵌套优先级分组为 1
NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn; //嵌套通道为USART6_IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级为 0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //响应优先级为 0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //通道中断使能
NVIC_Init(&NVIC_InitStructure);
/* DMA中断配置 */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //嵌套优先级分组为 1
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn; //嵌套通道为DMA2_Stream0_IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //抢占优先级为 1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //响应优先级为 0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //通道中断使能
NVIC_Init(&NVIC_InitStructure);
/* ADC中断配置 */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //嵌套优先级分组为 1
NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn; //嵌套通道为ADC_IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //抢占优先级为 1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //响应优先级为 2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //通道中断使能
NVIC_Init(&NVIC_InitStructure);
}
/*************************************************
Function: void DMA_Config(void)
Description: DMA配置函数
Input: 延时的时间
Output:无
Return:无
*************************************************/
void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
/*首先开DMA2时钟,由407参考手册-RM0090-Reference manual
*165页可知,ADC与DMA2映射,而且DMA2挂载在AHB1时钟总线上*/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
DMA_DeInit(DMA2_Stream0);
DMA_StructInit( &DMA_InitStructure);
DMA_InitStructure.DMA_Channel = DMA_Channel_0; //选择Channel_0
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Addr; //数据传输的外设首地址,详解见上
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADCoverValue; //自己定义待发送数组的首地址,要强制转换为32位
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; //数据传输方向选择为内存->外设
DMA_InitStructure.DMA_BufferSize = 1; //传输数据大小为16,单位由以下确定,大小要配合定义的数组类型和外设数据类型
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //外设地址寄存器自动增加禁止,因为这里只用到了DR数据寄存器
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; //内存地址自增不允许,因为只存取一个数
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //外设的数据大小,因为USART6_DR数据寄存器为8为,故选Byte
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //这里也选Byte
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //DMA传输模式为Normal,如果为Circular,将会循环传输
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //优先级为VeryHigh
stm32F407内部温度传感 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)