这个笔记本因为不小心的误操作清除了内容,但通过VScode的本地历史记录恢复了,故避免以后再次出现此类情况,现公开该笔记本(2024.10.24.03:53:41)
- intel/Altera
- AMD/Xilinx
- STMicroelectronics
- Texas Instruments
- Flash 512 kBytes
- RAM 64 kBytes
- IO 112
- Frequecy(Max) 72 MHz
Linker Settings default:
- Heap: 0x200
- Stack: 0x400
Cluster Communication Port
单工/半双工/全双工
Transistor-Transistor Logic 晶体管-晶体管逻辑
Time Limit Exceeded 时间超限
Not Recommended for New Design 不推荐用于新设计
- 器件已经计划停产,或者已经停产有少量库存.
- 有替代或升级的型号.
proportional-integral-differential 比例-积分-微分
Fast Fourier Transform 快速傅里叶变换
Pulse Width Modulation 脉冲宽度调制
Human Interface Device 人机接口设备
Hardware Abstraction Layer 硬件抽象层
board support package 板级支持包
Interrupt Request 中断请求
Direct Memory Access 直接内存访问
微软输入法繁简切换Ctrl
+Shift
+F
- Project ->
- Properties ->
- C/C++ Build ->
- Settings ->
- MCU/MPU Post build outputs ->
- Convert to Intel Hex file (-O ihex)
- Project ->
- Properties ->
- C/C++ Build ->
- Settings ->
- Tool Settings ->
- MCU Settings ->
- Use float with printf from newlib-nano (-u printf float)
- step into:进入子函数执行
- step over:不进入子函数执行
- step out:进入子函数后执行剩余部分返回上一层
- Project_name ->
- Properties->
- C/C++ General ->
- Paths and Symbols ->
- Includes
振幅相同,相位相反
- Universal Asynchronous Receiver Transmitter
- 通用异步串行接收发送器
- 位识别方式: 波特率
- 半双工
- Universal Synchronous Asynchronous Receiver Transmitter
- 通用同步异步串行接收发送器
- 位识别方式: 时钟
- Recommended Standard 232
- 位识别方式: 波特率
- Inter-Integrated Circuit
- 位识别方式: 时钟电平变化 高电平有效
- 半双工
- Serial Peripheral interface
- 位识别方式: 时钟电平变化 电平跳变时有效
- 全双工
- Recommended Standard 485
- 位识别方式: 差分信号 波特率
- Controller Area Network
- 控制器局域网
- 位识别方式: 差分信号 波特率
- Universal Serial Bus
- 位识别方式: 差分信号 波特率
type | size | range |
---|---|---|
unsigned char |
1 Byte | [0,255] |
signed char |
1 Byte | [-128,127] |
unsigned short |
2 Byte | [0,65535] |
signed short |
2 Byte | [-32768,32767] |
unsigned int |
4 Byte | [0,4294967295] |
signed int |
4 Byte | [-2147483648,2147483647] |
void HAL_GPIO_WritePin(GPIOx, GPIO_Pin_x, GPIO_PIN_SET);
//high: GPIO_PIN_SET
//low: GPIO_PIN_RESET
GPIO_PinState HAL_GPIO_ReadPin(GPIOx, GPIO_Pin_x);
void HAL_Delay(Delay);
// Delay: 延迟时间 ms
#### 未使用变量处理
```c
UNUSED(v);
__weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim);
定时器中断回调函数
// 开启PWM
HAL_StatusTypeDef HAL_TIM_PWM_Start(&htimx, TIM_CHANNEL_x);
// htimx: 定时器; TIM_CHANNEL_x: 通道
htimx.Instance->CCRx = CCR;
// CCRx: 占空比(该寄存器共4个,每个对应一个通道)
__HAL_TIM_SET_AUTORELOAD(&htimx, 1); // 设置自动重装载值 频率
__HAL_TIM_SET_COMPARE(&htimx, TIM_CHANNEL_x, 50); // 设置占空比
htimx.Instance->CNT
// 外部传入高电平计数
开启编码器
HAL_TIM_Encoder_Start(&htim, TIM_CHANNEL_ALL);
获取编码器值
__HAL_TIM_GET_COUNTER(&htim1);
USART1
: hostUSART2
: RS485USART3
: I2C2UART4
: SDIOUART5
: SDIO
HAL_UART_Receive(&huartx, Data, 40, 1000);
HAL_UART_Transmit(&huartx, Data, 40, 1000);
/*
huartx:uart端口;需要读写的数据缓冲区Data;缓冲区大小,超时时间
*/
char s[16];
uint8_t i = 0;
while (1) {
sprintf(s, "test=%i;", i);
HAL_UART_Transmit(&huart1, (uint8_t*) s, sizeof(s), 1000);
HAL_Delay(1000);
i++;
}
-
Sample text:
The Regents of the University of California.
(加州大学董事会)
temperature 温度
HAL_UART_Receive_IT(&huartx, Data, x);
HAL_UART_Transmit_IT(&huartx, Data, x);
/*
huartx:uart端口;需要读写的数据缓冲区Data;缓冲区大小
*/
位于stm32f1xx_hal_uart.h
中,该函数是__weak
弱定义可重写
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
内容自定义,记得清除中断位接收下一次
位于stm32f1xx_hal_uart.h
中,该函数是__weak
弱定义可重写
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size);
HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)
/*
hi2c i2c句柄指针
DevAddress 设备地址
MemAddress 寄存器地址
MemAddSize 寄存器地址之大小
pData 写入数据指针
Size 写入数据之大小
Timeout 超时时间
*/
if (HAL_I2C_Mem_Write(&hi2c, uint16_t DevAddress, MemAddress, MemAddSize, &pData, Size, Timeout) != HAL_OK)
{
HAL_UART_Transmit(&huart, (uint8_t*) "error!", 6, 10);
}
Thin film transistor liquid crystal display 薄膜晶体管液晶显示器
color = ((R << 11) | (G << 5) | B)
- 触控:
GT917S
- resolution:
800*480
x_max = 480 - 1;
y_max = 800 - 1;
- 触控: none
- resolution:
320*240
x_max = 320 - 1;
y_max = 240 - 1;
-
FSMC/Mode/NOR 1
-
Chip Select:
FSMC_NE4
; -
Memory type: "LCD Interface";
-
LCD Rigster Select:
FSMC_A10
(RS
pin); -
Data: "16 bits"
-
GPIO: "PB0->
LCD_BL
(GPIO_PIN_SET
); -
RESET: auto, 开发板电路已连接
-
NOR/PSRAM control Extended mode: Enabled
-
NOR/PSRAM timing address setup time in..: 0 Data setup time in HC..: 15 Bus turn around time ..: 15 Access mode: A
-
NOR/PSRAM timing for write accsses Extended address setup..: 0 Extended data setup time: 1 Extended bus turn around: 15 Extended access mode: A
初始化函数
// 定义
void lcd_init(void);
// 调用
lcd_init();
画线清除之前的点
while (1)
{
if (d <= 0)
d = 200;
line_y = sin((d - 1) * 1.8 * PI / 180) * (double) 101;
line_x = cos((d - 1) * 1.8 * PI / 180) * (double) 101;
lcd_draw_line(Ox, Oy, Ox - line_x, Oy - line_y, WHITE);
HAL_UART_Receive(&huart2, receive_buffer, sizeof(receive_buffer), 0xFF);
for (uint8_t i = 0; i < sizeof(receive_buffer); i++)
{
if (receive_buffer[i] == 'd' && receive_buffer[i + 1] == ':')
{
sprintf(s, "%c%c%c%c", receive_buffer[i + 2],
receive_buffer[i + 3], receive_buffer[i + 4],
receive_buffer[i + 5]);
length = atoi(s);
if (length > 2000)
length = 2000;
length = length / 20;
point_y = sin(d * 1.8 * PI / 180) * (double) length;
point_x = cos(d * 1.8 * PI / 180) * (double) length;
lcd_draw_point(Ox - point_x, Oy - point_y, GREEN);
d--;
lcd_draw_line(Ox, Oy, Ox - line_x, Oy - line_y, BLACK);
//sprintf(s0, "%d\r\n", length);
//HAL_UART_Transmit(&huart1, (uint8_t*) s0, sizeof(s0), 0xFF);
}
}
}
7 | 6 | 5 | 4 | 3 | 2 | 1 | R/W |
---|---|---|---|---|---|---|---|
1 | 1 | 0 | 1 | 0 | 0 | 0 | 1/0 |
視頻教程:
BV13N4y1y7Js
BV1z84y1R7JC
BV11w411z7o8
256 Byte
7 | 6 | 5 | 4 | A2 | A1 | A0 | R/W |
---|---|---|---|---|---|---|---|
1 | 0 | 1 | 0 | 0 | 0 | 0 | 1/0 |
A0
,A1
,A2
>>GND
512 kByte
512 kByte = 2 kByte * 256 page
start: 0x08000000
(B0, B1 >> GND)
stop: 0x0807FFFF
HAL_FLASH
系列函数
16 MByte
128 Mbit = 16 MByte = 256 Block 64 kByte
1 Block = 16 Sector 4 kByte
1 Sector = 4 kByte
最小擦除单位为一个扇区(Sector)
Device ID: 0x5217
When /CS is high the device is deselected
当
CS
为高电平时设备不选中
- Write Enable 写使能
0x06
- Write Enable for Volatile Status Register 易失性状态寄存器写使能
0x50
- Write Disable 写禁用
0x04
- Read Status Register-1, Status Register-2 & Status Register-3 读状态寄存器1,2,3
r1
0x05
;r20x35
;r30x15
- Write Status Register-1, Status Register-2 & Status Register-3 写状态寄存器1,2,3
r1
0x01
;r20x31
;r30x11
- Read Data 读数据
0x03
- Fast Read 快速读
0x0B
- Fast Read Dual Output 快读双输出
0x3B
- Fast Read Quad Output 快读四输出
0x6B
analog = analogue
STM32的DAC输出缓存做的有些不好,如果使能的话,虽然输出能力强一点,但是输出没法到0,这是个很严重的问题. 所以本章我们不使用输出缓存.即设置该位为1.
DACCHx_Config.DAC_Trigger=DAC_TRIGGER_NONE; // 不使用触发功能
DACCHx_Config.DAC_OutputBuffer=DAC_OUTPUTBUFFER_DISABLE; // 不使用输出缓存
使能DAC转换通道
HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel);
设置DAC的输出值
HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac,
uint32_t Channel, uint32_t Alignment, uint32_t Data);
Alignment:
DAC_ALIGN_8B_R
DAC_ALIGN_12B_L
DAC_ALIGN_12B_R
单DAC通道1,采用12位右对齐格式,用户将数据写入DAC_DHR12Rx[11:0]
位 (实际是存入DHRx[11:0]
位)
不要让ADC的时钟超过14M,否则将导致结果准确度下降
double adc_v;
char s[8];
while (1)
{
HAL_ADC_Start(&hadc);
if (HAL_ADC_PollForConversion(&hadc, 0xFF) == HAL_OK)
{
adc_v = HAL_ADC_GetValue(&hadc) * (3.3 / 4096);
}
sprintf(s, "%5.3f\r\n", adc_v);
HAL_UART_Transmit(&huart1, (uint8_t *)s, sizeof(s), 0xFF);
}
7 | 6 | 5 | 4 | 3 | 2 | 1 | R/W |
---|---|---|---|---|---|---|---|
0 | 1 | 0 | 1 | 0 | 0 | 1 | 1/0 |
- Categories ->
- Computing ->
- CRC ->
- Activated
uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength);
uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
HAL_CRC_Accumulate
不会复位,每次结果都不同
Crytal | frequency | (Hz) |
---|---|---|
Y1 |
32.768 kHz | 32768 |
Y2 |
8.000 MHz | 8000000 |
8 bit 128 8
1024 Byte
1Byte 对应像素的结构
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
7 | 6 | 5 | 4 | 3 | 2 | 1 | R/W |
---|---|---|---|---|---|---|---|
0 | 1 | 1 | 1 | 1 | 0 | 0 | 1/0 |
设置I2C快速模式 Master Features/ I2C Speed Mode: Fast Mode
(5 pixel 7 pixel ) 16 2 16 Byte 16 = 256 Byte
-
Display control command and data are written by an 8-bit serial transfer
显示控制命令和数据由8位串行传输写入. -
Setting the CS pin to "Low" level enables a data transfer.
将CS引脚设置为低电平可启用数据传输. -
Data is 8 bits and is sequentially input into the DA pin from LSB (LSB first).
数据为8位,从LSB顺序输入到DA引脚(LSB优先). -
(见图)时钟线空闲时间为高电平. 第二边沿(由低到高)
-
When data is written to RAM (DCRAM, ADRAM, CGRAM) continuously, addresses are internally incremented automatically.
当数据连续写入RAM(DCRAM,ADRAM,CGRAM)时,地址会在内部自动递增.
GND
: -VCC
: +5v: nonuse (不关注)EN
RST
: ResetCS
:NSS
空闲为高CP
:SCK
空闲为高DA
:MOSI
空闲为低
void MOSI_Byte(uint8_t byte)
{
for (uint8_t i = 0; i < 8; i++)
{
CLK_RESET;
if (byte & 0x01)
DATA_SET;
else
DATA_RESET;
byte = byte >> 1;
HAL_Delay(1);
CLK_SET;
HAL_Delay(1);
}
}
- Sample text:
Democratic Republic of North Japan
Шойгу! Герасимов! где сука боеприпасы?
Shoigu gerasimov gdie suka boiepripacy
SDIO的所有命令和响应都是通过SDIO_CMD
引脚传输的,任何命令的长度都是固定为48位.
SDIO command report:
bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
5 | start |
transmission |
command_index |
|||||
4 | arguments |
|||||||
3 | ||||||||
2 | ||||||||
1 | ||||||||
0 | CRC_7 |
stop |
所有的命令都是由STM32F1发出,其中开始位,传输位,CRC7和结束位由SDIO硬件控制,我们需要设置的就只有命令索引和参数部分
初始化:
hsd.Instance = SDIO;
hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_ENABLE;
hsd.Init.ClockDiv = 0x06;
-
hsd.Init.BusWide
在初始化时必须保持 1 位宽(SDIO_BUS_WIDE_1B
) 位宽可在初始化完成后修改/* USER CODE BEGIN SDIO_Init 2 */ if (HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B) != HAL_OK) { Error_Handler(); } /* USER CODE END SDIO_Init 2 */
-
hsd.Init.ClockDiv
公式:CLKDIV $$ SDIO_CK =\frac{SDIOCLK}{(2 + CLKDIV)} $$ SD卡基本信息:
LCD_ID: 5510
Card_ManufacturerID: 3
Card_RCA: 58916
ID: 3
Card_Capacity: 29 MB
Card_BlockSize: 512
7 | 6 | 5 | 4 | 3 | 2 | 1 | R/W |
---|---|---|---|---|---|---|---|
1 | 1 | 0 | 1 | 1 | 0 | 0 | 1/0 |
USART2
- 接收模式:
RS485_RE
= 0 - 发送模式:
RS485_RE
= 1
- Connectivity ->
- USB ->
- Mode ->
- Device (FS)
- Middleware and Software Packs ->
- USB_DEVICE ->
- Mode ->
- Class For FS IP ->
- Human Interface Device Class (HID) 包含中间件
#include "usbd_hid.h"
extern USBD_HandleTypeDef hUsbDeviceFS;
ADC + USB
Byte | function | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
---|---|---|---|---|---|---|---|---|---|
0 | button | left |
right |
central |
null |
||||
1 | X-axis movement | left[-127,+127]right |
|||||||
2 | Y-axis movement | up[-127,+127]down |
|||||||
3 | wheel movement | down[-127,+127]up |
-
第一个字节表示按键,bit0对应左键,bit1对应右键,bit3对应中键;0表示未按,1表示按下;
-
第二个字节表示x轴(即鼠标左右移动,0表示不动,正值表示往右移,负值表示往左移,范围-127-127,绝对值对应了移动量大小);
-
第三个字节表示y轴(即鼠标上下移动,0表示不动,正值表示往下移,负值表示往上移,范围-127-127,绝对值对应了移动量大小);
-
第四个字节表示鼠标滚轮(正值为往上滚动,负值为往下滚动,-127-127,绝对值对应了移动量大小).
-
设置完成后将报文发送
USBD_HID_SendReport(&hUsbDeviceFS, HID_buf, 4);
收发芯片: JTA1050
- Timers ->
- RTC ->
- Mode ->
- Active Clock Source,Active Calendar
- RTC OUT ->
- RTC Output on the Tamper pin
// 定义保存日期和时间的类
RTC_DateTypeDef date;
RTC_TimeTypeDef time;
// 获取时间和日期到类
HAL_RTC_GetDate(&hrtc, &date, RTC_FORMAT_BIN);
HAL_RTC_GetTime(&hrtc, &time, RTC_FORMAT_BIN);
格式化输出
sprintf(s_date, "20%02d.%02d.%02d", date.Year, date.Month, date.Date);
sprintf(s_time, "%02d:%02d:%02d", time.Hours, time.Minutes, time.Seconds);
- Year [0,99]
- Month [1,12]
- Date [1,31]
- Hour [0,23]
- Minutes [0,59]
- Seconds [0,59]
hex:
59
=0x3b
23
=0x17
31
=0x1F
99
=0x63
- resolution: 250*122
125 * 0x21 = 4125 1Byte 对应像素的结构
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
31 * 4 = 124 最后两行在屏幕外面
-
Sample text:
「昏睡レイプ!野獣と化した先輩」
-
CS
: low enable
HSB first
- resolution: 240*240 圆形屏幕
内存池:
内存管理表: 内存管理表的每一个项对应内存池的一块内存 内存管理表的项值:
- 当该项值为 0 的时候,代表对应的内存块未被占用
- 当该项值非零的时候,代表该项对应的内存块已经被占用,其数值则代表被连续占用的内存块数
/*
定义
memx:
SRAMIN 内部 SRAM (64 kB);
SRAMEX 外部扩展 SRAM (本开发板不支持);
*/
void my_mem_init(uint8_t memx);
// 调用
my_mem_init(SRAMIN);
oscillo-meter oscillo-graph oscillo-scope 示波器的本质: ADC(电压表)+屏幕
- Middleware and Software Packs /
- FATFS / Mode
- User-defined | SD Dard(只有SD卡可选SD)
USE_LABEL
:Enable
(支持卷标, 设置磁盘名称)CODE_PAGE
: (选择语言,支持简体中文)USE_LFN
:...HEAP
(支持长文件名)VOLUMES
:2
(支持多个磁盘)
- Project Manager
- Project
- Linker Setting
- Minimum Heap Size =
0x1000
SSE 600519 605337 Mis días contigo son los más felices que he tenido
2MD5050
驱动器
ENA
: 信号有效,输出关闭,电机线圈电流为零,电机处于无力矩状态,可自由转动DIR
: 信号有效,电机顺时针(clockwise)转动;信号无效,电机逆时针(anticlockwise)转动PUL
: 接收到信号后,按照设定方向转动(输入频率 <= 200 kHz)
超声波测距
Timers/TIMx/Mode/ Clock Source/Internal Clock Channex/Input Capture direct mode& Input Capture indirect mode
Internal Clock: 72 MHz Prescaler: 72 NVIC Settings/TIMx capture compare interrupt 开启定时器与通道捕获
HAL_TIM_Base_Start(&htimx);
HAL_TIM_IC_Start(&htimx, TIM_CHANNEL_x); // direct
HAL_TIM_IC_Start_IT(&htimx, TIM_CHANNEL_x); // indirect
触发模块启动
void SR04_Trigger()
{
HAL_GPIO_WritePin(SR04_TRIG_GPIO_Port, SR04_TRIG_Pin, GPIO_PIN_SET);
HAL_Delay(1);
HAL_GPIO_WritePin(SR04_TRIG_GPIO_Port, SR04_TRIG_Pin, GPIO_PIN_RESET);
__HAL_TIM_SET_COUNTER(&htimx, 0);
}
温度和音速的关系(近似): $$ V= 331 \times \sqrt {\frac {1+T} {273}} $$ T: 温度(temperature) V: 音速(speed of sound)
- QFP
Quad Flat Package
四侧引脚扁平封装
- LQFP
- TQFP
- BGA Ball Grid Array
- LGA Land Grid Array
- PGA Pin Grid Array
- | - | - |
---|---|---|
power | up | alientek |
left | play | right |
vol- | down | vol+ |
1 | 2 | 3 |
4 | 5 | 6 |
7 | 8 | 9 |
0 | delete |
- EL Electro-Luminescent 电致发光
- LCD Liquid Crystal Display 液晶显示
- OLED Organic Light-Emitting Diode 有机发光二极管
- LED Light Emitting Diode 发光二极管
- CRT Cathode Ray Tube 阴极射线管
- VFD Vacuum Fluorescent Display 真空荧光显示器
- NIXIE Nixie tube 辉光管
0b00
: Immediate 立即数0b01
: Compute 计算0b10
: Copy 复制0b11
: Condition 条件 Internet Software Infrastructure