当前位置:网站首页>第五天训练
第五天训练
2022-07-17 09:00:00 【Andrewjianlei】
CUBEMX:
KEY:GPIO_EXTI0
LED:_GPIO_Output
两组USART
目的:使用开发板虚拟串口模式,实现两者的控制和数据传输
网络通信基础:IP地址+端口号
IP地址:公有地址 私有地址
TCP 有连接 一对一(可靠性) 可靠传输
UDP多对多()速度快) 实时性
搞明白AT指令框架:TCP连接流程
AT+RST 复位
AT+CWMODE_DEF=1模式设置
AT+CWJAP_DEF="ssid",“password“
AT+CIFSR查看ip
AT+CIPMUX=1 AT+CIPSERVER=1.9999创建TCP连接
AT+CIPSEND=32 {"data":"doorbell","status","1"}发送数据
IPD,0,26:{"dev":"led","status","0"}接收数据
main.c:
1.启动串口2接收(中断方式)
2.串口2发送AT指令
3.接收模块返回数据
uart.c
HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
串口2启动接收:
void USART2_StartRx(void)
{
HAL_UART_Receive_IT(&huart2, (uint8_t*)&rx_data, 1);
}
串口2中断回调函数(保存每次接收的数据,并启动下一次接收)
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
usart_rx_buf[rx_len%200] = rx_data;
rx_len++;
HAL_UART_Receive_IT(&huart2, (uint8_t*)&rx_data, 1);
}
串口2接收的数据
uint16_t USART2_Receive(uint8_t *pdata)
{
memcpy(pdata, (uint8_t*)usart_rx_buf, rx_len);
return rx_len;
}
串口2发送数据
void USART2_Transmit(uint8_t *pData, uint16_t Size, uint32_t Timeout)
{
HAL_UART_Transmit(&huart2, pData, Size, Timeout);
}
清理串口2接收的数据
void USART2_ClearBuf(void)
{
rx_len = 0;
memset((uint8_t*)usart_rx_buf, 0, 200);
}
gpio.c
static uint8_t key_flag = 0;
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin ==KEY_Pin)
{
key_flag = ~key_flag;
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, key_flag?GPIO_PIN_RESET:GPIO_PIN_SET);
}
}
边栏推荐
猜你喜欢
![[face recognition] face recognition based on histogram histogram with matlab code](/img/a6/ae776d084a207647501ca951e32000.png)
[face recognition] face recognition based on histogram histogram with matlab code

LeetCode 剑指 Offer II 041. 滑动窗口的平均值:低空间消耗解决

Sorting out of neural network basics exercises in the second week of in-depth study

Expanding hard disk in VMWare

2022t elevator repair examination question bank and answers

Nacos new configuration management

2022广东省安全员A证第三批(主要负责人)练习题及模拟考试

Error received from peer ipv4/connection reset by peer paddleserving

Bean的作用域和生命周期

Hcip - Comprehensive Experiment of OSPF
随机推荐
Dynamic memory management
QT串口通信
Hcip - Comprehensive Experiment of OSPF
Basic steps for creating a static library
instanceof的另类写法示例说明
(鬼火引擎)中多设备的支持
46. IO model
Programming in the novel [serial 14] the moon bends in the yuan universe
QT serial communication
scratch逆序输出 电子学会图形化编程scratch等级考试四级真题和答案解析2022年6月
[Hongke] Introduction to genicam protocol
数据湖(二十):Flink兼容Iceberg目前不足和Iceberg与Hudi对比
Paddleserving service deployment tensorrt reports an error, shape of TRT subgraph is [-1, -1768],
Baidu Apollo
用于语义分割的Hausdorff损失函数
LeetCode 0116.填充每个节点的下一个右侧节点指针
QR分解求矩阵逆--c工程实现
How to position the circle of friends? Three core steps to build a circle of friends selling popular products
深度学习第四周Key Concepts on Deep Neural Networks习题整理
QR decomposition for matrix inversion -- C engineering implementation