MSP432学习笔记2——GPIO输入输出

这篇博客介绍了MSP432单片机的GPIO输入输出功能,通过实践操作连接矩阵键盘和5050全彩RGB七彩LED流水灯模块,探讨了GPIO配置函数、引脚功能,并提供了硬件连接和KEIL编程的详细过程。在实践中遇到LED模块无法启用的问题,分析可能的原因并提出解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今日继续更新我的MSP432速通笔记

新的硬件芯片到手,脑子是空白的,板子是漆黑的,诺想要缓解这份尴尬,便来点灯吧!

今日主要速通MSP432的GPIO输入输出功能,目标是连接矩阵键盘与LED流水灯模块

到MSP432P401R开发板上进行练习。

文章附上原理图与代码

目录

​编辑

基础知识学习:

1.模块介绍以及原理

1.矩阵键盘

2.5050全彩RGB七彩LED流水灯模块

2.MSP432基础GPIO输入输出配置函数

3.MSP432引脚功能分类与学习

一、端口P1、P2、P3、P4、P5、P6

二、端口P7、P8、P9、P10、PJ

实践操作练习:

硬件电路连接: 

矩阵键盘接法:

LED接法:

连接后的效果图:

3.KEIL编程:

后来下载后测量引脚示波与电压发现LED流水灯模块没法启用:


基础知识学习:

1.模块介绍以及原理

1.矩阵键盘

<
MSP432 低功耗高性能并存10.1 Digital I/O Introduction The digital I/O features include: • Independently programmable individual I/Os • Any combination of input or output • Individually configurable interrupts for ports (available for certain ports only) • Independent input and output data registers • Individually configurable pullup or pulldown resistors • Wake-up capability from ultra-low power modes (available for certain ports only) • Individually configurable high drive I/Os (available for certain I/Os only) Devices within the family may have up to eleven digital I/O ports implemented (P1 to P10 and PJ). Most ports contain eight I/O lines; however, some ports may contain less (see the device-specific data sheet for ports available). Each I/O line is individually configurable for input or output direction, and each can be individually read or written. Each I/O line is individually configurable for pullup or pulldown resistors. Certain ports have interrupt and wake-up capability from ultra-low power modes (see device specific data sheet for ports with interrupt and wake-up capability). Each interrupt can be individually enabled and configured to provide an interrupt on a rising or falling edge of an input signal. All interrupts are fed into an encoded Interrupt Vector register, allowing the application to determine which sub-pin of a port has generated the event. Individual ports can be accessed as byte-wide ports or can be combined into half-word-wide ports. Port pairs P1 and P2, P3 and P4, P5 and P6, P7 and P8, and so on, are associated with the names PA, PB, PC, PD, and so on, respectively. All port registers are handled in this manner with this naming convention. The main exception are the interrupt vector registers, for example, interrupts for ports P1 and P2 must be handled through P1IV and P2IV, PAIV does not exist. When writing to port PA with half-word operations, all 16 bits are written to the port. When writing to the lower byte of port PA using byte operations, the upper byte remains unchanged. Similarly, writing to the upper byte of port PA using byte instructions leaves the lower byte unchanged. When writing to a port that contains less than the maximum number of bits possible, the unused bits are don't care. Ports PB, PC, PD, PE, and PF behave similarly.
### MSP微控制器中四相编码器QEI的工作原理 四相编码器接口(Quadrature Encoder Interface, QEI)用于处理来自增量式旋转编码器的信号。该接口能够解析正交编码脉冲并将其转换成位置数据,从而实现精确的位置测量。 在MSP微控制器上,当配置为四相模式时,QEI模块会监控两个通道A和B上的输入波形。这两个通道提供相互之间有90度相位差的方波信号。通过监测这些信号的变化情况,可以确定电机轴或其他机械部件转动的方向以及移动的距离[^1]。 如果发生任何异常事件,比如丢失步进或非法状态转移,则触发QEIERR中断来报告这些问题,在这种情况下,计数器不会更新其数值以保持当前记录的状态不变。 ### 应用实例:基于MSP432P401R控制直流电机的速度反馈系统 为了展示如何利用QEI功能构建实际项目,下面给出一个简单的例子——使用TI公司的MSP432P401R开发板连接到带有内置霍尔效应传感器阵列的直流无刷马达上来创建速度控制系统: #### 硬件设置 - 连接编码器输出线至MCU相应引脚(P7.6/P7.7),确保电源供电正常; #### 软件编程要点 初始化QEIModule函数设定工作参数如下: ```c void QEIModule_init(void){ // 配置GPIO端口作为QEI输入 GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P7, GPIO_PIN6 | GPIO_PIN7); // 设置QEI模块分频系数及时钟源 QEIVelocityConfigure(QEIA_BASE, QEIClockSource_SystemClock, 8); // 启用错误检测机制 QEIEnableInterrupts(QEIA_BASE,QEI_INT_ERROR); } ``` 编写定时器ISR读取当前位置信息并与目标值比较调整PWM占空比达到闭环调节目的: ```c // 定义全局变量存储期望角度 volatile uint32_t desired_position; // 定时器周期性调用此回调函数 void Timer_A_periodic_callback(){ int current_pos=QEIPositionGet(QEIA_BASE); if(current_pos<desired_position){ PWM_duty_cycle_increase(); }else{ PWM_duty_cycle_decrease(); } } ```
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NULL指向我

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值