GPIO结构图
结构解释
Pull-Up Resistance
- 将一个输入端连接到高电平,以确保输入端在没有外部信号的情况下保持高电平。当外部信号拉低输入端时,输入端的电平会变为低电平.
Pull-Down Resistance
- 将一个输入端连接到低电平,以确保输入端在没有外部信号的情况下保持低电平。当外部信号拉高输入端时,输入端的电平会变为高电平.
Schmitt Trigger
-
Converts an input signal into a digital output signal.
-
Remove noise and provide hysteresis, which helps in stabilizing the output when the input signal is near the threshold level.
-
It has two threshold voltage levels. When the input voltage crosses these threshold levels, it triggers a change in the output state.
-
Applications: level shifting, noise filtering, waveform shaping.
工作模式
输入模式
Floating Input
- 将GPIO引脚不连接到任何信号上,需要外部信号输入才能确定GPIO引脚的电平。
Pull-Up
- 将GPIO引脚连接到一个高电平信号上,通过内部上拉电阻将GPIO引脚拉高,当外部信号低于GPIO引脚电平时,GPIO引脚为低电平。
Pull-Down
- 将GPIO引脚连接到一个低电平信号上,通过内部下拉电阻将GPIO引脚拉低,当外部信号高于GPIO引脚电平时,GPIO引脚为高电平。
Analog Mode
- 双向输入模式,将GPIO引脚连接到双向信号上,可以通过软件控制来选择GPIO引脚是输入还是输出
输出模式
General purpose output Open-drain
- 只能输出低电平(Sink Current)
Alternate function output Open-drain
- 复用输出,被用于其他模式
General purpose output push-pull
- 输出稳定,可高可低
Alternate function output push-pull
PWM
函数
PwmOut | 创建PWM的接口 |
---|---|
write | 写入duty cycle(0.0-1.0) |
read | 读取duty cycle(0.0-1.0) |
period,period_ms,period_us | 设置周期 |
pulsewidth,pulsewidth_ms,pulsewidth_us | 设置脉冲宽度 |
operator = | 设置duty cycle |
其他函数与对象
tone
- 定义
- 一个驱动扬声器发生的函数
- 语法
|
|
pc
- C++中的Serial类对象
UART
工作原理
- Baud Rate: 每秒钟传输的二进制位数
- 发送和接受的Baud Rate必须相同
- 发送Start Bit
- 逻辑为0的一位信号
- 发送Data Frame
- 5-8位不等,通常是8位
- 一个可选的Parity bit
- 根数据帧中的1的个数,奇数为0,偶数为1
- 发送Stop Bit
- 逻辑为1而1、1.5或2位信号
- idle State
- 闲置状态为1
优缺点
优点 | 缺点 |
---|---|
简单易操作 | 慢 |
有奇偶校验位检查错误 | 不支持多主从系统 |
不需要时钟 | 速度变化要稳定在10%以内,都则会造成数据丢失 |
Quiz
为什么过大的数会导致程序无法运行
- 超出类型范围和内存大小
3 Bus
-
Data Bus (Bidirectional)
-
Address Bus
-
Control Bus
What parameters should be agreed on between TX and RX for UART protocol?
Baud Rate | Data Bits | Stop Bit | Start Bits | (Parity Bit) |
---|---|---|---|---|
传输速率 | 一次传几位(5,6,7,8) | 什么时候结束一次传开始位 | 可选 |