本文主要是通过迁移的思维,记录本人初次使用NXP MCUXpresso SDK API进行BSP开发
前面调通了SDRAM Flash GPIO EEPROM之后,接下来调试ADC功能,硬件设计如下所示
1. 首先阅读原理图
针对ADC调试,在RT1052上面ADC的参考电压是3.3V,如下所示:
但是在RT1170上面,ADC的参考电压是1.8V,如下所示:
这是硬件设计需要注意的地方。
2. 调试过程
2. 1 时钟初始化
void bsp_adc_clock_init(){
/* Configure ADC1 using OSC_24M */
rootCfg.mux = kCLOCK_ADC1_ClockRoot_MuxOsc24MOut;
rootCfg.div = 1;
CLOCK_SetRootClock(kCLOCK_Root_Adc1, &rootCfg);
}
2. 2 引脚初始化
/**
* @brief adc pin mux init
*
* @param [in] None
* @param [out] None
*
* @return
*
* @history
* 1.Date : 2021-5-27 14:43:9
* Author : panzidong
* Modification : Created function
*/
void bsp_adc_pin_init(){
IOMUXC_SetPinMux(
IOMUXC_GPIO_AD_13_GPIO_MUX3_IO12, /* GPIO_AD_13 is configured as GPIO_MUX3_IO12 */
0U); /* Software Input On Field: Input Path is determined by functionality */
IOMUXC_SetPinConfig(
IOMUXC_GPIO_AD_13_GPIO_MUX3_IO12,
IOMUXC_SW_PAD_CTL_PAD_PUE(0x0)); /*Forbidden Pull Down Pull Up*/
}
2.3 解决ADC参考电压设计问题
ADC_VREFH = 1.8V *(64/30) = 3.84V
开了ADC的cscale功能之后,可以这么理解就是假设采样位数12位, ADC引脚的电压 = 采样值 * 3.84 * 1000 / 4096 mV.
/**
* @brief adc controller enable cscale func, reference : IMXRT1170RM.pdf page:6162 87.7.13..2
*
* @param [in] None
* @param [out] None
*
* @return
*
* @history
* 1.Date : 2021-7-1 14:43:9
* Author : panzidong
* Modification : Created function
*/
void bsp_adc_controller_enable_cscale_func(){
int i=0;
uint32_t data;
uint32_t *address;
for(i = 1; i<15; i++){
PRINTF("%x
", *(volatile uint32_t *)(0x40050000 + 0xf8 + i * 0x8) );
data = *(volatile uint32_t *)(0x40050000 + 0xf8 + i * 0x8);
address = (uint32_t *)(0x40050000 + 0xf8 + i * 0x8);
data = data & (~(1<<13));
*address = data;
PRINTF("%x
", *(volatile uint32_t *)(0x40050000 + 0xf8 + i * 0x8) );
}
for(i = 1; i<15; i++){
PRINTF("%x
", *(volatile uint32_t *)(0x40054000 + 0xf8 + i * 0x8) );
data = *(volatile uint32_t *)(0x40054000 + 0xf8 + i * 0x8);
address = (uint32_t *)(0x40054000 + 0xf8 + i * 0x8);
data = data & (~(1<<13));
*address = data;
PRINTF("%x
", *(volatile uint32_t *)(0x40054000 + 0xf8 + i * 0x8) );
}
}
3. 总结
ADC的硬件设计最关键的就是ADC的参考电压以及电路设计引入的误差要小,才能满足设计的要求。