极海的这款芯片,在ADC1也有温度传感器。
而且例程中使能了DMA功能:
void DMA_Init(uint32_t* Buf)
{
/* DMA Configure */
DMA_Config_T dmaConfig;
/* Enable DMA clock */
RCM_EnableAHB1PeriphClock(RCM_AHB1_PERIPH_DMA2);
/* size of buffer*/
dmaConfig.bufferSize = 1;
/* set memory Data Size*/
dmaConfig.memoryDataSize = DMA_MEMORY_DATA_SIZE_HALFWORD;
/* Set peripheral Data Size*/
dmaConfig.peripheralDataSize = DMA_PERIPHERAL_DATA_SIZE_HALFWORD;
/* Enable Memory Address increase*/
dmaConfig.memoryInc = DMA_MEMORY_INC_DISABLE;
/* Disable Peripheral Address increase*/
dmaConfig.peripheralInc = DMA_PERIPHERAL_INC_DISABLE;
/* Reset Circular Mode*/
dmaConfig.loopMode = DMA_MODE_CIRCULAR;
/* set priority*/
dmaConfig.priority = DMA_PRIORITY_HIGH;
/* read from peripheral*/
dmaConfig.dir = DMA_DIR_PERIPHERALTOMEMORY;
/* Set memory Address*/
dmaConfig.memoryBaseAddr = (uint32_t)Buf;
/* Set Peripheral Address*/
dmaConfig.peripheralBaseAddr = (uint32_t)&ADC1->REGDATA;
dmaConfig.channel = DMA_CHANNEL_0;
dmaConfig.fifoMode = DMA_FIFOMODE_DISABLE;
dmaConfig.fifoThreshold = DMA_FIFOTHRESHOLD_FULL;
dmaConfig.peripheralBurst = DMA_PERIPHERALBURST_SINGLE;
dmaConfig.memoryBurst = DMA_MEMORYBURST_SINGLE;
DMA_Config(DMA2_Stream0, &dmaConfig);
/* Clear DMA TF flag*/
DMA_ClearIntFlag(DMA2_Stream0, DMA_INT_TCIFLG0);
/* Enable DMA Interrupt*/
DMA_EnableInterrupt(DMA2_Stream0, DMA_INT_TCIFLG);
DMA_Enable(DMA2_Stream0);
}
那么在主循环中就判断DMA有没有数据就行了,有就执行串口打印功能:
while (1)
{
if (DMA_ReadStatusFlag(DMA2_Stream0, DMA_FLAG_TCIFLG0))
{
DataBuf = DMA_ConvertedValue;
VSensorValue = (float)DataBuf/4095*3.3;
/*!
* According to actual test data of multiple bathes of chips,
* V28 is adopted instead of V25 for this example. And 0.7782v is the voltage for 28¡æ
*/
TSensorValue = (VSensorValue - 0.7782f)/0.0024f + 28;
printf("\r\n");
printf("ADC REGDATA = 0x%04X \r\n", DataBuf);
printf("Volatage = %f V \r\n", VSensorValue);
printf("Temperature = %f ¡æ \r\n", TSensorValue);
Delay(0xFFFFFF);
DMA_ClearStatusFlag(DMA2_Stream0, DMA_FLAG_TCIFLG0);
}
}
}
以下是运行结果,由于没有串口线引出,只有打断点来观察。