第一范文网 - 专业文章范例文档资料分享平台

MINI-STM32 开发板入门教程.

来源:用户分享 时间:2025/7/11 20:04:20 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

(3) 移植 fputc

如果你使用仿真器在 Mini-STM32 上调试的话你还可以看到两个 LED 在跑跑马灯程序了. 到此我们这章节的教程就结束了, 相信大家也掌握了 System Tick 的用法了.

MINI-STM32 开发板入门教程 (六) 基于 DMA 的 ADC

(一) STM32 ADC 模块介绍

(二) 程序编写

(1) 设置 ADC 的地址

#define ADC1_DR_Address ((u32)0x4001244C)

(2) 初始化 DMA 和 ADC 模块与应用程序

/* DMA channel1 configuration ----------------------------------------------*/ DMA_DeInit(DMA1_Channel1);

DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; // 外设地址 DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue; // 内存地址 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; // DMA 传输方向单向 DMA_InitStructure.DMA_BufferSize = 1; // 设置DMA在传输时缓冲区的长度 word DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //设置DMA外设递增模式

DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; // 设置DMA内存递增模式 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; // 外设数据字长

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //内存数据字长 DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; // 设置传输模式连续不断的循环模式 DMA_InitStructure.DMA_Priority = DMA_Priority_High; // 设置DMA的优先级别

DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; // 设置DMA的2个memory中的变量互相访问

DMA_Init(DMA1_Channel1, &DMA_InitStructure);

/* Enable DMA channel1 */ DMA_Cmd(DMA1_Channel1, ENABLE);

/* ADC1 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; // 独立工作模式 ADC_InitStructure.ADC_ScanConvMode = ENABLE; // 扫描方式 ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; // 连续转换

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; // 外部触发禁止 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; // 数据右对齐

ADC_InitStructure.ADC_NbrOfChannel = 1; // 用于转换的通道数 ADC_Init(ADC1, &ADC_InitStructure);

/* ADC1 regular channel14 configuration */

ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 1, ADC_SampleTime_55Cycles5);

/* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE);

/* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE);

/* Enable ADC1 reset calibaration register */ ADC_ResetCalibration(ADC1);

/* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1));

/* Start ADC1 calibaration */ ADC_StartCalibration(ADC1);

/* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1));

/* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE);

while(1) {

AD_value = ADC_GetConversionValue(ADC1);

delay(); }

(三) 仿真调试

(1) 使用Keil uVision3 通过ULINK 2仿真器连接实验板,使用MINI-STM32 开发板附带的串口线,连接实验板上的 UART1 和 PC 机的串口,打开实验例程目录下的ADC.Uv2例程,编译链接工程;

(2) 在 PC 机上运行 windows 自带的超级终端串口通信程序(波特率115200、1位停止位、无校验位、无硬件流控制);或者使用其它串口通信程序;

(3) 点击MDK 的Debug菜单,点击Start/Stop Debug Session;

(4) 旋转电位器 R19,可以看到串口输出数值不断变化,正常显示结果如下所示。

usart1 print AD_value -------------------------- The current AD value = 0x0425 The current AD value = 0x0423 The current AD value = 0x0421 The current AD value = 0x0422 The current AD value = 0x0420 The current AD value = 0x0416 The current AD value = 0x03B6 The current AD value = 0x0841 The current AD value = 0x08C3 The current AD value = 0x08C0 The current AD value = 0x08BE The current AD value = 0x09E9 The current AD value = 0x0A12 The current AD value = 0x0ACA The current AD value = 0x0B0D The current AD value = 0x0B10 The current AD value = 0x0B0E .... ....

(5) 若无开发板,读者也可以使用软件仿真模式来完成程序运行。

搜索更多关于: MINI-STM32 开发板入门教程. 的文档
MINI-STM32 开发板入门教程..doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c0gfr65e78o5o77k30e8m0fvqu4yw2700pdv_6.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top