蓝牙用的是rdtss例程,然后ADC部分参考的是\ADC\ADC_DMA例程。
描述:在“APP_BLE_OS_READY”之后初始化ADC,然后循环ns_timer_create一个20ms的任务,在里面打印ADC的值,发现打印的一直是0x0026,不会变化。
void RCC_Configuration_ADC(void)
{
/* Enable peripheral clocks */
/* Enable peripheral clocks */
RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE);
/* Enable GPIOB clocks */
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
/* Enable ADC clocks */
RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_ADC, ENABLE);
RCC_ConfigAdcClk(RCC_ADCCLK_SRC_HSE_DIV8);
}
/**
* @brief Configures the different GPIO ports.
*/
void GPIO_Configuration_ADC(void)
{
GPIO_InitType GPIO_InitStructure;
GPIO_InitStruct(&GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_8;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG;
GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);
}
/**
* @brief DMA channel1 configuration
*/
void DMA_Configuration_ADC(void)
{
/* DMA channel1 configuration ----------------------------------------------*/
DMA_DeInit(DMA_CH1);
DMA_InitStructure.PeriphAddr = (uint32_t)&ADC->DAT;
DMA_InitStructure.MemAddr = (uint32_t)&ADCConvertedValue;
DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC;
DMA_InitStructure.BufSize = 1;
DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE;
DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_DISABLE;
DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_HALFWORD;
DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR;
DMA_InitStructure.Priority = DMA_PRIORITY_HIGH;
DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE;
DMA_Init(DMA_CH1, &DMA_InitStructure);
DMA_RequestRemap(DMA_REMAP_ADC, DMA, DMA_CH1, ENABLE);
/* Enable DMA channel1 */
DMA_EnableChannel(DMA_CH1, ENABLE);
ADC_EnableBypassFilter(ADC, ENABLE);
ADC_ConfigChannel(ADC, ADC_CTRL_CH_3);
ADC_ConfigContinuousMode(ADC, ENABLE);
ADC_EnableDMA(ADC, ENABLE);
ADC_Enable(ADC, ENABLE);
}
void ADC_Configuration(void)
{
RCC_Configuration_ADC();
GPIO_Configuration_ADC();
DMA_Configuration_ADC();
}
//20ms任务:采集一次ADC值、电量检测也一起放在这里
void APP_20MS_ADC_callback(void)
{
uint8_t sdata[4];
if(BLE_Connect_status == 1)
{
sdata[0] = (uint8_t)(ADCConvertedValue[0]>>8);
sdata[1] = (uint8_t)ADCConvertedValue[0];
sdata[2] = 0x0d;
sdata[3] = 0x0a;
usart_tx_dma_send(sdata,4);
}
ns_timer_create(20,APP_20MS_ADC_callback); //反复调用
}
|