1.概述
本文主要基于LoRa调制功能的无线串口模块的树莓派扩展板,讲述在M4核LoRa的调试过程。
2.硬件资源
ØTypec Debug线1根
ØMicro usb线1根
ØMYD-15XC-T开发板
Ø树莓派接口SX1262 868M LoRa HAT模块2个
3.软件资源
ØLinux 5.4.31
ØSTM32CubeIDE 1.5.0
ØLInux虚拟机
Ø米尔提供的SDK
4.环境准备
预先安装好CubeIDE等开发软件并搭建好Linux虚拟机环境,具体环境搭建请参考米尔的软件开发手册《MYD-YA15XC-T_Linux软件开发指南》。
5.操作步骤
5.1.硬件介绍与设置
1)硬件介绍
关于树莓派接口SX1262 868M LoRa HAT模块的硬件介绍与设置请参考微雪官网:
https://www.waveshare.net/wiki/SX1262_868M_LoRa_HAT
2)接线与设置
需要两个LoRa模块,一个LoRa模块通过Micro USB连接至PC,跳帽置于A,M1和M0连接GND,打开SSCOM串口软件连接LoRa模块。另外一个LoRa模块跳帽连接B,M0、M1跳帽移除改用MYD-YA15XC-T开发板的GPIO使用,如下图所示:
图5-1. 连接与配置
5.2.CubeMX配置
设置时钟为209M,如下图只需要在红色框输入209M,按“Enter”,会自动设置时钟参数:
图 5-1.时钟设置
由于该模块通讯接口使用的是串口,所以还需要设置usart外设,并使能中断:
图 5-2.串口设置
接着勾选串口中断,通过中断收发:
图5-3.串口中断
5.3.软件设计
由5.2节生成代码之后,在工程目录新建“LoRa”目录,用来存放LoRa的配置代码(微雪官网有该模块设置源码,用户可以直接移植):
设置寄存器配置模式,这里首先需要设置模式2进行寄存器配置:
void cfg_sx126x_io(uint8_t status)
{
if(CFG_REGISTER == status){
M0_RESET();
M1_SET();
HAL_Delay(5);
}else if(NORMAL_STATUS == status){
M0_RESET();
M1_RESET();
HAL_Delay(5);
}else if(WOR_STATUS == status){
M0_SET();
M1_RESET();
HAL_Delay(5);
}else if(SLEEP_STATUS == status){
M0_SET();
M1_SET();
HAL_Delay(5);
}
}
配置寄存器,设置波特率9600,广播监听地址:
/******************************************************************************
sx126x mode :broadcast & monitor mode
parameter:
address_high:0xff
address_low:0xff
net_id: 0x00
serial:0x62
power: 0x00
channel: 0x12
transmission_mode: 0x03
crypt_high: 0x00
crypt_low: 0x00
******************************************************************************/
lora_para_t transparent_mode = {
.address_high = BROADCAST_ADDH_VALUE,
.address_low = BROADCAST_ADDL_VALUE,
.net_id = BROADCAST_NETID_VALUE,
.serial = BROADCAST_SERIAL_VALUE,
.power = BROADCAST_POWER_VALUE,
.channel = BROADCAST_CHANNEL_VALUE,
.transmission_mode = BROADCAST_TRANSIMISSION_VALUE,
.crypt_high = BROADCAST_CRYPTH_VALUE,
.crypt_low = BROADCAST_CRYPTL_VALUE
};
设置寄存器:
uint8_t sx126x_write_register(lora_para_t para)
{
int8_t i;
buffer[0] = CFG_HEADER;
buffer[1] = REG_START;
buffer[2] = REG_NUMBER;
for(i=3;i<12;i++){
buffer[i] = *(¶.address_high + i - 3);
}
HAL_UART_Transmit_IT(&huart3,(uint8_t *)buffer,12);
HAL_UART_Receive_IT(&huart3,(uint8_t *)buffer,12);
HAL_Delay(500);
if(CFG_RETURN == buffer[0]){
buffer[0] = 0;
init_cplt_flag = SUCCESS;
return SUCCESS;
}
return ERROR;
}
定义发送的信息:
/* USER CODE BEGIN 1 */
uint8_t transparent_string[] = "Helloworld";//"This is a transparent message\r\n";
uint32_t delay;
/* USER CODE END 1 */
主函数里,使用串口中断进行发送和接收处理:
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if(delay++>18000000){
HAL_UART_Transmit_IT(&huart3,transparent_string,strlen((const char *)transparent_string));
delay = 0;
}
if(SUCCESS == over_flag){
HAL_UART_Transmit_IT(&huart3,buffer,strlen((const char *)buffer));
over_flag = ERROR;
rece_count = 0;
HAL_UART_Receive_IT(&huart3,(uint8_t *)&rece_buff,1);
}
}
5.4.测试
1)量产模式启动m4固件
启动开发板,并启动m4固件,如下:
root@myir-ya151c-t-4e512d:~# cp LoRa_CM4.elf /lib/firmware/
root@myir-ya151c-t-4e512d:~# echo LoRa_CM4.elf > /sys/class/remoteproc/remotepro
c0/firmware
root@myir-ya151c-t-4e512d:~# echo start > /sys/class/remoteproc/remoteproc0/stat
e
[ 82.845983] remoteproc remoteproc0: powering up m4
[ 82.859219] remoteproc remoteproc0: Booting fw image LoRa_CM4.elf, size 2532532
[ 82.865319] remoteproc remoteproc0: header-less resource table
[ 82.870883] remoteproc remoteproc0: no resource table found for this firmware
[ 82.884297] remoteproc remoteproc0: header-less resource table
[ 82.888689] remoteproc remoteproc0: remote processor m4 is now up
2)信息接收
打开sscom,可以看到usb控制的LoRa模块能接收到数据,如下图所示:
图 5-2.数据接收
-
开发板
+关注
关注
25文章
5025浏览量
97356
发布评论请先 登录
相关推荐
评论