AS32-100 LoRa Wireless Communication Module
Module Source
Purchase link: https://item.taobao.com/item.htm?spm=a1z09.2.0.0.a2882e8dnsJF7e&id=623781851754&_u=72t4uge5cec9
Materials download: http://www.ashining.com/product_view1.aspx?t=93&cid=118#pro
Host computer (PC tool) download address: http://www.ashining.com.cn/relatedsoftware/soft_asds.zip
Specifications
Operating voltage: 2.0V-5.5V Operating current: 52mA~104mA Default frequency: 433MHz Transmission power: 20dBm Reference communication distance: 3km Control method: UART
View Materials
Set the working mode through MD0 and MD1.
If multiple modules need to exchange data with each other, the configuration parameters between the modules must be consistent. The parameters include: air speed, module address, and communication channel. Parameters are modified through the host computer (PC tool). For specific steps, please refer to the Quick Operation Guide. After configuration is complete, just set the mode to general working mode to perform transparent transmission.
Porting Process
Pin Selection
Use UART1 (UART1-TX=PA2, UART1-RX=PA3) The AUX pin is used for wireless transceiver buffer indication and self-test indication. It indicates whether the module has data that has not yet been sent out wirelessly, or whether all received data has been sent out through the UART, or whether the module is in the initialization self-test process. AUX timing changes during working state switching: Before switching working states, the AUX pin state should be checked. When AUX is low, it indicates the module is busy; when AUX outputs high for about 2ms, it indicates the module is now idle and the module can start working state switching. After the low-latency working state pins MD0 and MD1 start to change levels, AUX continues to output high for about 3ms, then the module performs state switching. When AUX outputs low, it indicates state switching is in progress; when AUX outputs high and holds for about 2ms, it indicates state switching is complete. This case does not require working mode switching; instead it uses the general working mode (MD0=0, MD1=0) fixed, so AUX can be left floating.
Port to Project
Our goal is to port the example to the ESP32-S3 dev board. Complete driver code has been provided for you. Follow the steps below to complete the porting.
For detailed instructions on creating folders and new .c and .h files, refer to section 1.4.2 in the [DHT11 Temperature and Humidity Sensor] chapter; we will not repeat it here.
However, here we replace the file names bsp_dht11.c and bsp_dht11.h with bsp_lora.c and bsp_lora.h, and change the folder name to LORA.
Write Code
In the file bsp_lora.c, write the following code.
/*
* LCSC-Openkits (LCKFB) software and hardware materials and related expansion board software and hardware materials are all open source on the official website.
* Dev board official website: www.lckfb.com
* Technical support resides on the forum; any technical questions are welcome for exchange and learning at any time.
* LCKFB Forum: club.szlcsc.com
* Follow our Bilibili account: [LCSC-Openkits (LCKFB)] to keep up with our latest updates!
* We do not make money by selling boards; we take cultivating engineers as our mission.
* Change Logs:
* Date Author Notes
* 2024-01-12 LCKFB-lp first version
*/
#include "bsp_lora.h"
#include "stdio.h"
#include "string.h"
unsigned char LOAR_RX_BUFF[LOAR_RX_LEN_MAX];
unsigned char LOAR_RX_FLAG = 0;
unsigned char LOAR_RX_LEN = 0;
static void delay_ms(unsigned int ms)
{
vTaskDelay(ms / portTICK_PERIOD_MS);
}
static void delay_us(unsigned int us)
{
ets_delay_us(us);
}
static void delay_1ms(unsigned int ms)
{
vTaskDelay(ms / portTICK_PERIOD_MS);
}
static void delay_1us(unsigned int us)
{
ets_delay_us(us);
}
/************************************************************
* Function Name: LOAR_USART_Init
* Function Description: Initialization for connecting to LOAR
* Parameters: bund=UART baud rate
* Return Value: None
* Notes: Baud rate is determined by your settings (default baud rate 9600)
*************************************************************/
void LOAR_USART_Init(unsigned int bund)
{
//Define UART configuration structure, must be initialized, otherwise it cannot work
uart_config_t uart_config={0};
uart_config.baud_rate = bund; //Configure baud rate
uart_config.data_bits = UART_DATA_8_BITS; //Configure data bits to 8
uart_config.parity = UART_PARITY_DISABLE; //Configure parity to none
uart_config.stop_bits = UART_STOP_BITS_1; //Configure stop bits to 1
uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE; //Disable hardware flow control
//Load the above parameters into the UART1 registers
uart_param_config(LOAR_USART, &uart_config);
//Bind pins TX=tx_pin RX=rx_pin RTS=Not used CTS=Not used
uart_set_pin(LOAR_USART, GPIO_LOAR_TX, GPIO_LOAR_RX, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
//Install UART driver
uart_driver_install(LOAR_USART, LOAR_RX_LEN_MAX, LOAR_TX_LEN_MAX, 0, NULL, 0);
//Create UART2 receive task
xTaskCreate(LOAR_USART_Handler, "LOAR_USART_Handler", 1024*2, NULL, configMAX_PRIORITIES, NULL);
}
/******************************************************************
* Function Name: LOAR_USART_Send_Bit
* Function Description: Send a single character to the LOAR module
* Function Parameters: ch=character
* Function Return: None
* Author: LC
* Notes: None
******************************************************************/
void LOAR_USART_Send_Bit(unsigned char ch)
{
uart_write_bytes(LOAR_USART, (const char*)&ch, 1);
}
/******************************************************************
* Function Name: LOAR_USART_send_String
* Function Description: Send a string to the LOAR module
* Function Parameters: str=string to send
* Function Return: None
* Author: LC
* Notes: None
******************************************************************/
void LOAR_USART_send_String(unsigned char *str)
{
uart_write_bytes(LOAR_USART, (const char*)str, strlen( (const char*)str ));
}
/******************************************************************
* Function Name: LOAR_USART_send_String
* Function Description: Send a string to the LOAR module
* Function Parameters: str=hex data to send len=data length to send
* Function Return: None
* Author: LC
* Notes: None
******************************************************************/
void LOAR_USART_send_HEX(unsigned char *str, unsigned int len)
{
while( len-- ) // Exit if address is empty or value is empty
{
LOAR_USART_Send_Bit(*str++);
}
}
/******************************************************************
* Function Name: Clear_LOAR_RX_BUFF
* Function Description: Clear data sent from LOAR
* Function Parameters: None
* Function Return: None
* Author: LC
* Notes: None
******************************************************************/
void Clear_LOAR_RX_BUFF(void)
{
uart_flush(LOAR_USART);
LOAR_RX_LEN = 0;
LOAR_RX_FLAG = 0;
}
/**********************************************************
* Function Name: Anakysis_Data
* Function: Receive data sent from LoRa
* Parameters: None
* Function Return: 1=received data once 0=no data received currently
* Author: LC
* Notes:
**********************************************************/
unsigned char Anakysis_Data(void)
{
#if DEBUG
printf("Anakysis_Data = %d\r\n",LOAR_RX_FLAG);
#endif
if( LOAR_RX_FLAG == 1 )//If UART data was received
{
printf("data = %s\r\n",LOAR_RX_BUFF);
Clear_LOAR_RX_BUFF();
return 1;
}
return 0;
}
/******************************************************************
* Function Name: LOAR_USART_Handler
* Function Description:
* Function Parameters: None
* Function Return: None
* Author: LC
* Notes: None
******************************************************************/
void LOAR_USART_Handler(void)
{
while(1)
{
//Receive data
LOAR_RX_LEN = uart_read_bytes(LOAR_USART, LOAR_RX_BUFF, LOAR_RX_LEN_MAX-1, 20 / portTICK_PERIOD_MS);
if( LOAR_RX_LEN > 0 && LOAR_RX_FLAG == 0 ) // Receive buffer is not empty
{
LOAR_RX_BUFF[LOAR_RX_LEN] = '\0'; //Append '\0' to the end of the string
LOAR_RX_FLAG = 1; // Reception complete
#if DEBUG //Test
printf("Handler = %d\r\n",LOAR_RX_FLAG);
printf("%s\r\n", LOAR_RX_BUFF);
#endif
}
delay_ms(20);
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
In the file bsp_lora.h, write the following code.
/*
* LCSC-Openkits (LCKFB) software and hardware materials and related expansion board software and hardware materials are all open source on the official website.
* Dev board official website: www.lckfb.com
* Technical support resides on the forum; any technical questions are welcome for exchange and learning at any time.
* LCKFB Forum: club.szlcsc.com
* Follow our Bilibili account: [LCSC-Openkits (LCKFB)] to keep up with our latest updates!
* We do not make money by selling boards; we take cultivating engineers as our mission.
* Change Logs:
* Date Author Notes
* 2024-01-12 LCKFB-lp first version
*/
#ifndef _BSP_LORA_H_
#define _BSP_LORA_H_
#include <stdio.h>
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "driver/i2c.h"
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "freertos/queue.h"
#include <inttypes.h>
#include "sdkconfig.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "rom/ets_sys.h"
#include "esp_system.h"
#include "driver/gpio.h"
#include "driver/spi_master.h"
#include "driver/spi_common.h"
#include "hal/gpio_types.h"
#include "string.h"
// 1: View debug data
// 0: Do not view debug data
#define DEBUG 0
/**************************** UART Configuration ****************************/
#define GPIO_LOAR_TX 1 // UART TX pin
#define GPIO_LOAR_RX 2 // UART RX pin
#define LOAR_USART UART_NUM_2 // UART2
#define LOAR_RX_LEN_MAX 255 //Maximum UART receive length
#define LOAR_TX_LEN_MAX 255 //Maximum UART transmit length
void LOAR_USART_Init(unsigned int bund);
void LOAR_USART_send_String(unsigned char *str);
void LOAR_USART_send_HEX(unsigned char *str, unsigned int len);
unsigned char Anakysis_Data(void);
void LOAR_USART_Handler(void);
#endif2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Porting Verification
In the main.c of ESP32-S3 dev board 1, write the following code. (Make sure bsp_lora.c and bsp_lora.h have been written according to the above)
/*
* LCSC-Openkits (LCKFB) software and hardware materials and related expansion board software and hardware materials are all open source on the official website.
* Dev board official website: www.lckfb.com
* Technical support resides on the forum; any technical questions are welcome for exchange and learning at any time.
* LCKFB Forum: club.szlcsc.com
* Follow our Bilibili account: [LCSC-Openkits (LCKFB)] to keep up with our latest updates!
* We do not make money by selling boards; we take cultivating engineers as our mission.
* Change Logs:
* Date Author Notes
* 2024-01-12 LCKFB-lp first version
*/
#include <stdio.h>
#include "bsp_lora.h"
#include "string.h"
#include "esp_private/esp_task_wdt.h"
#include "esp_private/esp_task_wdt_impl.h"
/*
1: ESP32-S3 dev board 1
0: ESP32-S3 dev board 2
*/
#define USE_1_2 1
int app_main(void)
{
esp_task_wdt_deinit();
LOAR_USART_Init(9600); //LoRa module initialization
printf("Start......\r\n");
// Defined in the bsp_lora.h file
#if USE_1_2
while(1)
{
//Received data
Anakysis_Data();
//Send data
LOAR_USART_send_String((unsigned char *)"LSpi-1\r\n");
vTaskDelay(500 / portTICK_PERIOD_MS);
}
#else
while(1)
{
//Received data
Anakysis_Data();
//Send data
LOAR_USART_send_String((unsigned char *)"LSpi-2\r\n");
vTaskDelay(500 / portTICK_PERIOD_MS);
}
#endif
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
In the main.c of ESP32-S3 dev board 2, write the following code. (Make sure bsp_lora.c and bsp_lora.h have been written according to the above)
/*
* LCSC-Openkits (LCKFB) software and hardware materials and related expansion board software and hardware materials are all open source on the official website.
* Dev board official website: www.lckfb.com
* Technical support resides on the forum; any technical questions are welcome for exchange and learning at any time.
* LCKFB Forum: club.szlcsc.com
* Follow our Bilibili account: [LCSC-Openkits (LCKFB)] to keep up with our latest updates!
* We do not make money by selling boards; we take cultivating engineers as our mission.
* Change Logs:
* Date Author Notes
* 2024-01-12 LCKFB-lp first version
*/
#include <stdio.h>
#include "bsp_lora.h"
#include "string.h"
#include "esp_private/esp_task_wdt.h"
#include "esp_private/esp_task_wdt_impl.h"
/*
1: ESP32-S3 dev board 1
0: ESP32-S3 dev board 2
*/
#define USE_1_2 0
int app_main(void)
{
esp_task_wdt_deinit();
LOAR_USART_Init(9600); //LoRa module initialization
printf("Start......\r\n");
// Defined in the bsp_lora.h file
#if USE_1_2
while(1)
{
//Received data
Anakysis_Data();
//Send data
LOAR_USART_send_String((unsigned char *)"LSpi-1\r\n");
vTaskDelay(500 / portTICK_PERIOD_MS);
}
#else
while(1)
{
//Received data
Anakysis_Data();
//Send data
LOAR_USART_send_String((unsigned char *)"LSpi-2\r\n");
vTaskDelay(500 / portTICK_PERIOD_MS);
}
#endif
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Power-on effect:
Driver code:
File Download
📌 Materials Download Center (click to jump)
📌 In the Materials Download Center -> Module Porting Materials Download, inside the compressed package of this chapter.