当前位置:网站首页>stm32mp1 Cortex M4开发篇11:扩展板蜂鸣器控制
stm32mp1 Cortex M4开发篇11:扩展板蜂鸣器控制
2022-06-21 09:09:00 【华清远见IT开放实验室】
写在前面:
本文章为《ARM Cortex-M4裸机开发篇》系列中的一篇,,全系列总计14篇。笔者使用的开发平台为华清远见FS-MP1A开发板(STM32MP157开发板),Cortex-M4裸机开发篇除了讲M4裸机开发外,还会讲解通过M4控制资源扩展板上的各种传感器执行器模块(包括空气温湿度传感器、LED灯、数码管、蜂鸣器、震动马达、按键中断、风扇等),本篇是M4控制资源扩展板中的一篇。
资源扩展板是FS-MP1A开发板的扩展模块,主要包含了10余种助主流传感器、执行器件、总线控制器件,非常方便项目扩展用。可拓展开发智慧家庭、智能医疗、智能安防、工业控制、图像识别、环境检测等方向的10个左右综合项目,华清远见开发板也将配套提供所有项目的说明文档、实验源码、应用程序等资料。
针对FS-MP1A开发板,除了Cortex-M4裸机开发篇外,还包括其他多系列教程,包括Cortex-A7开发篇、FreeRTOS篇、Linux基础及应用开发篇、Linux系统移植篇、Linux驱动开发篇、硬件设计篇、人工智能机器视觉篇、Qt应用编程篇、Qt综合项目实战篇等。欢迎关注,更多stm32mp157开发教程及视频,可加技术交流Q群459754978,感谢关注。
FS-MP1A开发板详情介绍:淘宝网 - 淘!我喜欢
目录
1. 资源扩展板介绍
1.1. 硬件介绍

1.1. 资源扩展板可开发项目

2.扩展板蜂鸣器控制
2.1实验原理
打开扩展板原理图对照扩展板可以看到扩展板有1个蜂鸣器SP1,如下图:

由上图可见通过TIM4_CH1电平改变控制电路的通断从而驱动蜂鸣器。

扩展板与底板接口对照图
查看原理图可知TIM4_CH1对应PB6,查看芯片手册可知PB6可以作为PWM TIMER4的通道1使用,本文实现如何通过PWM驱动蜂鸣器:
| 原理图网络编号 | 对应管脚 | 管脚功能 | 管脚功能码 |
| TIM4_CH1 | PB6 | TIM4_CH1 | AF2 |
2.2.实验目的
了解蜂鸣器工作原理
学习TIM中PWM的使用方法,掌握如何利用STM32MP157A芯片输出PWM波控制蜂鸣器
2.3.实验环境
FS-MP1A开发平台
ST-Link仿真器
STM32CubeIDE开发软件
PC机 XP、Window7/10 (32/64bit)
2.4.实验步骤
MX配置
根据原理图,配置PB6引脚设置为TIM4_CH1。切换到TIM4标签,勾选给“M4”,“Channel1”选择“PWM Generation CH1”,所有配置如下图所示。


上述为新建工程配置过程,可参考12.3.2章节进行导入已有工程,工程存放路径【华清远见-FS-MP1A开发资料\02-程序源码\ARM体系结构与接口技术\Cortex-M4\10_EX_PWM_BEEP】
代码设计
找到创建的工程,打开main.c,完善定时器中断回调函数,在该函数里,使用“__HAL_TIM_SET_COMPARE()” 可以修改寄存器CCR,实现不同的占空比。
将定时器中断启动函数“HAL_TIM_Base_Start_IT()”和定时器PWM输出开始函数“HAL_TIM_PWM_Start()”封装在一起。

最后主函数调用“TIM_PWM_Start()”即可启动TIM中断,通过改变pulse的数值可以输出不同占空比的PWM,可以控制蜂鸣器发出不同频率的声音。
硬件平台:华清远见FS-MP1A开发板(STM32MP157)
部分开发教程下载:加QQ群459754978,群文件里有。
部分视频课程收看:华清远见研发中心的个人空间_哔哩哔哩_Bilibili
淘宝购买链接:华清远见stm32mp157 linux开发板stm32单片机arm开发嵌入式学习板
手机淘宝分享码:复制本行文字打开手淘₤T4FPXn3YYJ2₤
边栏推荐
- source Insight 快捷键 对照
- 应用配置管理,基础原理分析
- Character function and string function
- Base de données de sauvegarde DumpLiNg
- STL tutorial 3- type conversion static_ cast、dynamic_ cast、const_ cast、reinterpret_ Cast method
- Unity写多线程注意事项
- It is only seven days since the commencement of construction in 2022. I left the outsourcing company
- ADO. Net - invalid size for size property, 0 - ado NET - The Size property has an invalid size of 0
- 客户端建设及调优实践
- It is said that this year gold three silver four has become gold one silver two.
猜你喜欢
![[vs], [usage problem], [solution] when VS2010 is opened, it stays in the startup interface](/img/04/a7455760caa4fc0480a034de1e24b8.png)
[vs], [usage problem], [solution] when VS2010 is opened, it stays in the startup interface

ADO. Net - invalid size for size property, 0 - ado NET - The Size property has an invalid size of 0

Tidb3.0- 4.0 memory control / modification log saving days / maximum index length

Gql+nodejs+mysql database

优化食品生产行业库存管理的6种方法

Pingcap was selected as the "voice of customers" of Gartner cloud database in 2022, and won the highest score of "outstanding performer"

STL教程3-类型转换static_cast、dynamic_cast、const_cast、reinterpret_cast方法

Lei niukesi --- basis of embedded AI

Detailed analysis of ThreadPoolExecutor source code of thread pool

Abstractqueuedsynchronizer (AQS) source code detailed analysis - semaphore source code analysis
随机推荐
finally block can not complete normally
Source insight shortcut key cross reference
Client construction and Optimization Practice
[Mgt] model Mgt for code interpretation
在64位机器使用CMake编译32位程序
MySQL installation process under linux environment
【C】 [time operation] time operation in C language
Abstractqueuedsynchronizer (AQS) source code detailed analysis - semaphore source code analysis
How to generate QR code
The R language uses the sink function to export the dataframe data and save it as a CSV file in the specified directory. In practice, if no directory is specified, it will be output to the current wor
window10局域网共享文件夹流程
TiDB3.0- 4.0 内存控制/修改日志保存天数/最大索引长度
AQS source code exploration_ 01 handwriting a simplified reentrantlock reentrant lock
sql查看数据库/表磁盘占用情况,杀死进程终止tidb中的连接
适配华为机型中出现的那些坑
Abstractqueuedsynchronizer (AQS) source code detailed analysis - countdownlatch source code analysis
How to connect the Internet - FTTH
Binary search (integer binary)
Common basic functions of R language: call the data editor with edit function to manually customize and edit the data object without changing the content of the original data object, and call the data
[vs], [usage problem], [solution] when VS2010 is opened, it stays in the startup interface