GD32F310K8芯片资源介绍
总体来说此款芯片存储空间较小,移植一些裸机程序的可玩性还是较高的。并且也能验证温度,ADC采集等性能。
开发准备
PC端:windows10
开发软件:keil4.60
开发板:GD32F310k\\\_start
GD32F310系列资料下载https://aijishu.com/a/1060000000306188
部分代码简要
ADC配置
/*!
\brief configure the ADC peripheral
\param[in] none
\param[out] none
\retval none
*/
void adc_config(void)
{
/* ADC contineous function enable */
adc_special_function_config(ADC_CONTINUOUS_MODE, ENABLE);
/* ADC trigger config */
adc_external_trigger_source_config(ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_NONE);
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* ADC channel length config */
adc_channel_length_config(ADC_REGULAR_CHANNEL, 1U);
/* ADC regular channel config */
adc_regular_channel_config(0U, BOARD_ADC_CHANNEL, ADC_SAMPLETIME_55POINT5);
adc_external_trigger_config(ADC_REGULAR_CHANNEL, ENABLE);
/* 16 times sample, 4 bits shift */
adc_oversample_mode_config(ADC_OVERSAMPLING_ALL_CONVERT, ADC_OVERSAMPLING_SHIFT_4B, ADC_OVERSAMPLING_RATIO_MUL16);
adc_oversample_mode_enable();
/* enable ADC interface */
adc_enable();
delay_1ms(1U);
/* ADC calibration and reset calibration */
adc_calibration_enable();
}
串口配置
/*!
\brief configure COM port
\param[in] com: COM on the board
only one parameter can be selected which is shown as below:
\arg EVAL_COM: COM on the board
\param[out] none
\retval none
*/
void gd_eval_com_init(uint32_t com)
{
uint32_t COM_ID = 0U;
if(EVAL_COM == com){
COM_ID = 0U;
}else{
}
/* enable COM GPIO clock */
rcu_periph_clock_enable(EVAL_COM_GPIO_CLK);
/* enable USART clock */
rcu_periph_clock_enable(COM_CLK[COM_ID]);
/* connect port to USARTx_Tx */
gpio_af_set(EVAL_COM_GPIO_PORT, EVAL_COM_AF, COM_TX_PIN[COM_ID]);
/* connect port to USARTx_Rx */
gpio_af_set(EVAL_COM_GPIO_PORT, EVAL_COM_AF, COM_RX_PIN[COM_ID]);
/* configure USART Tx as alternate function push-pull */
gpio_mode_set(EVAL_COM_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, COM_TX_PIN[COM_ID]);
gpio_output_options_set(EVAL_COM_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, COM_TX_PIN[COM_ID]);
/* configure USART Rx as alternate function push-pull */
gpio_mode_set(EVAL_COM_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, COM_RX_PIN[COM_ID]);
gpio_output_options_set(EVAL_COM_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, COM_RX_PIN[COM_ID]);
/* USART configure */
usart_deinit(com);
usart_baudrate_set(com, 115200U);
usart_word_length_set(USART0, USART_WL_8BIT);
usart_stop_bit_set(USART0, USART_STB_1BIT);
usart_parity_config(USART0, USART_PM_NONE);
usart_receive_config(com, USART_RECEIVE_ENABLE);
usart_transmit_config(com, USART_TRANSMIT_ENABLE);
usart_enable(com);
}
ADC精度测试
测试方式及接线
采用电位计分压直接接入ADIN1(PA1)。电压信号经过RC低通滤波器或者有源低通滤波器再输入ADC输入端可能会更好。
AD量化值显示
总结:此配置下,ADC采集只有一位的跳动。
电压值显示
总结:此配置下,ADC采集电压跳动量小于1mV。
使用总结
此次GD32F310试用的代码均为官方提供,不同芯片系列间的移植也很方便!对于12位ADC的性能也很满意。因此立马采购了GD32F407芯片替代STM32F407,初步使用情况为引脚兼容,代码几乎没做更改(正在比对参数,看是否需要修改原代码),并同步温度性能测试。