Lora模块点对点通讯测试程序(源码+固件)
配合51单片机使用。
单片机源程序如下:
- /******************************************************************************/
- /* --安信可科技有限公司-- */
- /*
- // 函数说明:main.c
- // 说明:该程序用于测试lora模块
- // 编写人员: sky
- // 编写日期: 2016-11-24
- // 版本号:V1.0
- // 维护日志:
- //
- //
- */
- // 免责声明:该程序仅供参考学习,若自定义其他功能,请查看参考手册
- // (c) Anxinke Corporation. All rights reserved.
- /******************************************************************************/
- #include "typedef.h"
- #include "gpio.h"
- #include "string.h"
- #include "uart.h"
- #include "SX1278.h"
- //#include "delay.h"
- void main(void) {
- unsigned char RF_REC_RLEN_i = 0;
- int flag = 0;
- int led = 0;
- unsigned char recv[30];
- uartInit();
- //uartSendString("READY!\r\n");
- P1M1 = 0X03;
- P1M0 = 0XFC;
- P3M1 &= 0XFC;
- P3M0 |= 0X04;
- //uartSendString("HERE!\r\n");
- register_rf_func(&ctrlTypefunc);
- SX1276Reset();
- SX1276LORA_INT();
- uartSendString("READY!\r\n");
- P32 = 1;
- P17 = 1;
- while (1) {
- if (P30 == 0 || P31 == 0) {
- P17 = 1;
- P32 = 0;
- SX1276WriteBuffer( REG_LR_IRQFLAGS, 0xff);
- uartSendString("hello world!\r\n");
- FUN_RF_SENDPACKET("ai-thinker", 10);
- Delay1s(1000);
- SX1276WriteBuffer( REG_LR_IRQFLAGS, 0xff);
- } else {
- P32 = 1;
- RF_EX0_STATUS = SX1276ReadBuffer( REG_LR_IRQFLAGS);
- if (RF_EX0_STATUS > 0) {
- if ((RF_EX0_STATUS & 0x40) == 0x40) {
- //GPIO_OUTPUT_SET(GPIO_ID_PIN(2),0);
- CRC_Value = SX1276ReadBuffer( REG_LR_MODEMCONFIG2);
- if (CRC_Value & 0x04 == 0x04) {
- SX1276WriteBuffer(REG_LR_FIFOADDRPTR, 0x00);
- SX1278_RLEN = SX1276ReadBuffer(REG_LR_NBRXBYTES);
- //uartSendString("recvieve data num=%d\r\n",SX1278_RLEN);
- lpTypefunc.lpSwitchEnStatus(enOpen);
- lpTypefunc.lpByteWritefunc(0x00);
- for (RF_REC_RLEN_i = 0; RF_REC_RLEN_i < SX1278_RLEN;
- RF_REC_RLEN_i++) {
- recv[RF_REC_RLEN_i] = lpTypefunc.lpByteReadfunc();
- }
- lpTypefunc.lpSwitchEnStatus(enClose);
- recv[RF_REC_RLEN_i] = '\0';
- if(strncmp(recv,"ai-thinker",10))
- {
- uartSendString("recieve\r\n");
- P17 = 0;
- }
- }
- // lpTypefunc.lpRecvDataTousr(recv,SX1278_RLEN);
- SX1276LoRaSetOpMode(Stdby_mode);
- SX1276WriteBuffer(REG_LR_IRQFLAGSMASK, IRQN_RXD_Value); //打开发送中断
- SX1276WriteBuffer(REG_LR_HOPPERIOD, PACKET_MIAX_Value);
- SX1276WriteBuffer( REG_LR_DIOMAPPING1, 0X00);
- SX1276WriteBuffer( REG_LR_DIOMAPPING2, 0x00);
- SX1276LoRaSetOpMode(Receiver_mode);
- // lpTypefunc.paSwitchCmdfunc(rxOpen);
- } else if ((RF_EX0_STATUS & 0x08) == 0x08) {
- SX1276LoRaSetOpMode(Stdby_mode);
- SX1276WriteBuffer(REG_LR_IRQFLAGSMASK, IRQN_RXD_Value); //打开发送中断
- SX1276WriteBuffer(REG_LR_HOPPERIOD, PACKET_MIAX_Value);
- SX1276WriteBuffer( REG_LR_DIOMAPPING1, 0X00);
- SX1276WriteBuffer( REG_LR_DIOMAPPING2, 0x00);
- SX1276LoRaSetOpMode(Receiver_mode);
- // lpTypefunc.paSwitchCmdfunc(rxOpen);
- } else if ((RF_EX0_STATUS & 0x04) == 0x04) {
- if ((RF_EX0_STATUS & 0x01) == 0x01) { //表示CAD 检测到扩频信号 模块进入了接收状态来接收数据
- SX1276LoRaSetOpMode(Stdby_mode);
- SX1276WriteBuffer(REG_LR_IRQFLAGSMASK, IRQN_RXD_Value); //打开发送中断
- SX1276WriteBuffer(REG_LR_HOPPERIOD, PACKET_MIAX_Value);
- SX1276WriteBuffer( REG_LR_DIOMAPPING1, 0X02);
- SX1276WriteBuffer( REG_LR_DIOMAPPING2, 0x00);
- SX1276LoRaSetOpMode(Receiver_mode);
- // lpTypefunc.paSwitchCmdfunc(rxOpen);
- } else {
- SX1276LoRaSetOpMode(Stdby_mode);
- SX1276WriteBuffer(REG_LR_IRQFLAGSMASK,
- IRQN_SEELP_Value); //打开发送中断
- SX1276WriteBuffer( REG_LR_DIOMAPPING1, 0X00);
- SX1276WriteBuffer( REG_LR_DIOMAPPING2, 0X00);
- SX1276LoRaSetOpMode(Sleep_mode);
- //PA_SEELP_OUT();
- }
- } else {
- SX1276LoRaSetOpMode(Stdby_mode);
- SX1276WriteBuffer(REG_LR_IRQFLAGSMASK, IRQN_RXD_Value); //打开发送中断
- SX1276WriteBuffer(REG_LR_HOPPERIOD, PACKET_MIAX_Value);
- SX1276WriteBuffer( REG_LR_DIOMAPPING1, 0X02);
- SX1276WriteBuffer( REG_LR_DIOMAPPING2, 0x00);
- SX1276LoRaSetOpMode(Receiver_mode);
- // lpTypefunc.paSwitchCmdfunc(rxOpen);
- }
- RF_REC_RLEN_i = 0;
- SX1276WriteBuffer( REG_LR_IRQFLAGS, 0xff);
- Delay1s(300);
- } else {
- P17 = 1;
- }
- }
- }
- }
复制代码
所有资料51hei提供下载:
lora测试版固件.zip
(2.58 KB, 下载次数: 105)
源码.zip
(103.92 KB, 下载次数: 122)
|