物联网Lora模块从入门到精通(七)串口通讯_lora串口通信

本文的任务是当取到的数据通过串口以ASCII格式向外发送,并通过串口调试助手接受来着上位机的指令做出对应的操作。

具体任务如下:

单片机间隔一秒向上位机发送光照数据,并记录发送次数,当收到来自上位机的复位指令FA 00 FB时,清空发送次数。

通过分析usart1-board.c库,我们常会使用下列方法:

void USART1_Init(uint32_t bound);
//初始化串口 bound为波特率
void USART1_SendStr(uint8_t *Data, uint16_t length);
//发送uint8_t类型数据数组 length为发送的长度
uint16_t USART1_ReadRxBuffer( uint8_t *payload);
//接受来自串口的内容并存入传入的数据数组内 返回接受到的数据长度

代码示例:

#include <string.h>
#include "board.h"
#include "hal_key.h"
#include "tim-board.h"
#include "timer_handles.h"
#include "led_light.h"
#include "adc_reader.h"
#include <math.h>          //library 
#include <stdio.h>
#include "stm32l1xx_hal.h" // controller register definitions 
#include "sht1x.h"         // controller register definitions 
#include "sht3x.h"
#include "usart1-board.h"

void Init() {
    BoardInitMcu();
    BoardInitPeriph();
    keys_init();//按键初始化
    setTimer2Callback(Time2Handler);
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值