?1.概述
本文主要基于LoRa調制功能的無線串口模塊的樹莓派擴展板,講述在M4核LoRa的調試過程。
2.硬件資源
?Typec Debug線1根
?Micro usb線1根
?MYD-15XC-T開發(fā)板
?樹莓派接口SX1262 868M LoRa HAT模塊2個
3.軟件資源
?Linux 5.4.31
?STM32CubeIDE 1.5.0
?LInux虛擬機
?米爾提供的SDK
4.環(huán)境準備
預先安裝好CubeIDE等開發(fā)軟件并搭建好Linux虛擬機環(huán)境,具體環(huán)境搭建請參考米爾的軟件開發(fā)手冊《MYD-YA15XC-T_Linux軟件開發(fā)指南》。
5.操作步驟
5.1.硬件介紹與設置
1)硬件介紹
關于樹莓派接口SX1262 868M LoRa HAT模塊的硬件介紹與設置請參考微雪官網(wǎng):
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開發(fā)板的GPIO使用,如下圖所示:
圖5-1. 連接與配置
5.2.CubeMX配置
設置時鐘為209M,如下圖只需要在紅色框輸入209M,按“Enter”,會自動設置時鐘參數(shù):
圖 5-1.時鐘設置
由于該模塊通訊接口使用的是串口,所以還需要設置usart外設,并使能中斷:
圖 5-2.串口設置
接著勾選串口中斷,通過中斷收發(fā):
圖5-3.串口中斷
5.3.軟件設計
由5.2節(jié)生成代碼之后,在工程目錄新建“LoRa”目錄,用來存放LoRa的配置代碼(微雪官網(wǎng)有該模塊設置源碼,用戶可以直接移植):
設置寄存器配置模式,這里首先需要設置模式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,廣播監(jiān)聽地址:
/******************************************************************************
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;
}
定義發(fā)送的信息:
/* USER CODE BEGIN 1 */
uint8_t transparent_string[] = "Helloworld";//"This is a transparent message\r\n";
uint32_t delay;
/* USER CODE END 1 */
主函數(shù)里,使用串口中斷進行發(fā)送和接收處理:
/* 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)量產(chǎn)模式啟動m4固件
啟動開發(fā)板,并啟動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模塊能接收到數(shù)據(jù),如下圖所示:
圖 5-2.數(shù)據(jù)接收
-
開發(fā)板
+關注
關注
25文章
5032瀏覽量
97372
發(fā)布評論請先 登錄
相關推薦
評論