LoRa wireless communication based on STM32, STM8, STC89C52, AvrMega8 MCU (AS32-TTL-1W)

Official source code: LoRa wireless digital communication module based on STM32, STM8, STC89C52, AvrMega8 MCU (AS32-TTL-1W)

Just look at the code files in the official routines. Now the code is no longer officially provided.


Source package download link (permanently valid):
It already contains the extraction code, and the WeChat App can directly scan the code to enter, but I tried Baidu Netdisk to scan it.
I put the c file first, and put the other corresponding H files in the back. For the code under the std_lib folder, you can find it in the FWLib in the development boards such as punctual atomic battleships. 5 c files and 4 H files are as follows:

main.c

/**
 ***************************************************** *****************************
* @author Zeyao Technology ASHINING
* @version V3.0
* @date 2016-10-08
* @brief main function
***************************************************** *****************************
* @attention
*
* Official website: http://www.ashining.com
* Taobao: https://shop105912646.taobao.com
* Alibaba: https://cdzeyao.1688.com
***************************************************** *****************************
*/
#include "drv_delay.h"
#include "drv_uart.h"
#include "drv_led.h"
#include "drv_AS62.h"


#define __AS62_TX_MODE__ /**@@ Transmit mode, shielding is receive mode @@ **/


#ifdef __AS62_TX_MODE__
char *pAshining = "ashining";
#else
uint8_t g_ashining[ 8 ] ={ 'a', 's', 'h', 'i', 'n', 'i', 'n', \ 'g' };
uint8_t g_As62_rx_buffer[ 100 ] = { 0 };
uint8_t g_RxLength = 0;
#endif



/**
 * @brief : main function
 * @param : none
 * @note : none
 * @retval: None
  */
int main( void )
{

//Serial port initialization changes according to the module baud rate
drv_uart_init(9600);

//ASxx module parameter initialization fixed-point mode address 0x1234 signal 0x17
ASxx_param_init( );

//delayed initialization
drv_delay_init( );

// LED initialization
drv_led_init( );
 
while( 1 )
{
// send mode
#ifdef __AS62_TX_MODE__
ASxx_tx_packet( 0x12, 0x35, 0x17, (uint8_t *)pAshining, 8 ); //Send fixed string ashining string to the module whose address is 0x1235 and channel is 0x17
led_red_flashing( );
drv_delay_500Ms( 3 );
\t
// receive mode
#else
g_RxLength = ASxx_rx_packet( g_As62_rx_buffer );
if( 0 != g_RxLength )
{
led_green_flashing( );
}
#endif
}
}

drv_delay.c

/**
 ***************************************************** *****************************
 * @author Zeyao Technology ASHINING
 * @version V3.0
* @date 2016-10-08
* @brief DELAY configuration C file
***************************************************** *****************************
 * @attention
  *
 * Official website: http://www.ashining.com
 * Taobao: https://shop105912646.taobao.com
 * Alibaba: https://cdzeyao.1688.com
  ***************************************************** *****************************
  */



#include "drv_delay.h"


/**
  * @brief : delayed initialization
  * @param : none
  * @note : The timer is initialized to us-level counting by default
  * @retval: None
  */
void drv_delay_init( void )
{
TIM_TimeBaseInitTypeDef TimerInitStructer;
RCC_ClocksTypeDef RCC_ClocksStatus;

//Get the system clock
RCC_GetClocksFreq( & RCC_ClocksStatus);

//Enable TIM2 clock
RCC_APB1PeriphClockCmd( DELAY_TIME_BASE_CLK, ENABLE );

TimerInitStructer.TIM_ClockDivision = TIM_CKD_DIV1;
TimerInitStructer.TIM_CounterMode = TIM_CounterMode_Up;
TimerInitStructer.TIM_Period = 0x00FF;
TimerInitStructer.TIM_RepetitionCounter = DISABLE;
TimerInitStructer.TIM_Prescaler = ( RCC_ClocksStatus.PCLK1_Frequency / 1000000 ) - 1;
TIM_TimeBaseInit( DELAY_TIME_BASE, &TimerInitStructer );

TIM_ClearFlag( DELAY_TIME_BASE, TIM_FLAG_Update );
TIM_SetCounter( DELAY_TIME_BASE, 0 );
TIM_Cmd( DELAY_TIME_BASE, ENABLE );
while( RESET == TIM_GetFlagStatus( DELAY_TIME_BASE, TIM_FLAG_Update ));
TIM_Cmd( DELAY_TIME_BASE, DISABLE );
TIM_SetCounter( DELAY_TIME_BASE, 0 );
TIM_ClearFlag( DELAY_TIME_BASE, TIM_FLAG_Update );
}

/**
  * @brief : Delay (us)
  * @param :
* @Us: the us number of delay
  * @note : no more than 65535
  * @retval: None
  */
void drv_delay_us( uint16_t Us )
{
DELAY_TIME_BASE->ARR = Us;
DELAY_TIME_BASE->CNT = 0;
DELAY_TIME_BASE->CR1 |= (uint32_t)0x01;
while( RESET == ( DELAY_TIME_BASE->SR & TIM_FLAG_Update ));
DELAY_TIME_BASE->SR & amp;= (uint32_t)( ~(uint32_t)TIM_FLAG_Update );
DELAY_TIME_BASE->CR1 & amp;= (uint32_t)( ~(uint32_t)0x01 );
}

/**
 * @brief : Delay (ms)
 * @param :
 * @Ms: Delayed Ms number
  * @note : no more than 65
  * @retval: None
  */
void drv_delay_ms( uint8_t Ms )
{
DELAY_TIME_BASE->ARR = Ms * 1000;
DELAY_TIME_BASE->CNT = 0;
DELAY_TIME_BASE->CR1 |= (uint32_t)0x01;
while( RESET == ( DELAY_TIME_BASE->SR & TIM_FLAG_Update ));
DELAY_TIME_BASE->SR & amp;= (uint32_t)( ~(uint32_t)TIM_FLAG_Update );
DELAY_TIME_BASE->CR1 & amp;= (uint32_t)( ~(uint32_t)0x01 );
}

/**
* @brief : Delay (500Ms)
 * @param :
* @Ms: 500Ms multiple of delay
  * @note : no more than 255
  * @retval: None
  */
void drv_delay_500Ms( uint8_t Ms_500 )
{
while( Ms_500 -- )
{
drv_delay_ms( 50 ); //1 * 50ms
drv_delay_ms( 50 ); //2 * 50ms
drv_delay_ms( 50 ); //3 * 50ms
drv_delay_ms( 50 ); //4 * 50ms
drv_delay_ms( 50 ); //5 * 50ms
drv_delay_ms( 50 ); //6 * 50ms
drv_delay_ms( 50 ); //7 * 50ms
drv_delay_ms( 50 ); //8 * 50ms
drv_delay_ms( 50 ); //9 * 50ms
drv_delay_ms( 50 ); //10 * 50ms = 500ms
}
}

/**
  * @brief : free delay
  * @param : none
  * @note : none
  * @retval: None
  */
void drv_delay_free( uint32_t Delay_Time )
{
while( Delay_Time-- )
{

}
}

drv_led.c

/**
  ***************************************************** *****************************
 * @author Zeyao Technology ASHINING
 * @version V3.0
 * @date 2016-10-08
 * @brief LED configuration C file
 ***************************************************** *****************************
* @attention
  *
 * Official website: http://www.ashining.com
 * Taobao: https://shop105912646.taobao.com
  * Alibaba: https://cdzeyao.1688.com
  ***************************************************** *****************************
  */



#include "drv_led.h"



/**
 * @brief : LED initialization
 * @param : none
  * @note : none
  * @retval: None
  */
void drv_led_init( void )
{
GPIO_InitTypeDef GpioInitStructer;

//Enable port line clock
RCC_APB2PeriphClockCmd( LED_RED_GPIO_CLK | LED_BLUE_GPIO_CLK, ENABLE ); //Enable port clock

GpioInitStructer.GPIO_Mode = GPIO_Mode_Out_PP;
GpioInitStructer.GPIO_Speed = GPIO_Speed_2MHz;

GpioInitStructer.GPIO_Pin = LED_RED_GPIO_PIN;
GPIO_Init( LED_RED_GPIO_PORT, & amp;GpioInitStructer ); //Initialize the red LED pin
GPIO_SetBits( LED_RED_GPIO_PORT, LED_RED_GPIO_PIN ); //The initial state is set high, and the initial state of the red LED is off by default

GpioInitStructer.GPIO_Pin = LED_BLUE_GPIO_PIN;
GPIO_Init( LED_BLUE_GPIO_PORT, & amp;GpioInitStructer ); //Initialize the blue LED pin
GPIO_SetBits( LED_BLUE_GPIO_PORT, LED_BLUE_GPIO_PIN ); //The initial state is set high, and the blue LED initialization state is off by default

}

/**
  * @brief : LED on
 * @param :
  * @LedPort: LED selection, red or blue
 * @note : none
 * @retval: None
 */
void drv_led_on( LedPortType LedPort )
{
if( LED_RED == LedPort ) //LED_RED
{
GPIO_ResetBits( LED_RED_GPIO_PORT, LED_RED_GPIO_PIN ); //Set the red LED pin to low, and the red LED is on
}
else //LED_BLUE
{
GPIO_ResetBits( LED_BLUE_GPIO_PORT, LED_BLUE_GPIO_PIN ); //Set the blue LED pin to low, and the blue LED is on
}

}

/**
  * @brief : LED off
  * @param :
  * @LedPort: LED selection, red or blue
  * @note : none
  * @retval: None
 */
void drv_led_off( LedPortType LedPort )
{
if( LED_RED == LedPort ) //LED_RED
{
GPIO_SetBits( LED_RED_GPIO_PORT, LED_RED_GPIO_PIN ); //Set the red LED pin high, the red LED off
}
else //LED_BLUE
{
GPIO_SetBits( LED_BLUE_GPIO_PORT, LED_BLUE_GPIO_PIN ); //Set the blue LED pin high, the blue LED off
}

}

/**
  * @brief : LED flashing
  * @param :
  * @LedPort: LED selection, red or blue
  * @note : None
  * @retval: None
  */
void drv_led_flashing( LedPortType LedPort )
{

if( LED_RED == LedPort )
{
LED_RED_GPIO_PORT->ODR ^= (uint32_t)LED_RED_GPIO_PIN;
}
else
{
LED_BLUE_GPIO_PORT->ODR ^= (uint32_t)LED_BLUE_GPIO_PIN;
}
}

drv_uart.c

/**
  ***************************************************** *****************************
  * @author Zeyao Technology ASHINING
 * @version V3.0
 * @date 2016-10-08
* @brief UART configuration C file
***************************************************** *****************************
* @attention
 *
* Official website: http://www.ashining.com
  * Taobao: https://shop105912646.taobao.com
 * Alibaba: https://cdzeyao.1688.com
  ***************************************************** *****************************
 */


#include "drv_uart.h"


/**
  * @brief : serial port initialization
  * @param :
  * @UartBaudRate: serial port baud rate
  * @note : None
  * @retval: None
  */
void drv_uart_init( uint32_t UartBaudRate )
{
GPIO_InitTypeDef UartGpioInitStructer;
USART_InitTypeDef UartinitStructer;

//During the configuration process, in order to prevent TX and RX from being on the same port and enhance portability, solid separate configuration
//Initialize the serial port TX RX pin
RCC_APB2PeriphClockCmd( UART_TX_GPIO_CLK | UART_RX_GPIO_CLK, ENABLE ); //Open TX RX port clock

UartGpioInitStructer.GPIO_Mode = GPIO_Mode_AF_PP;
UartGpioInitStructer.GPIO_Speed = GPIO_Speed_2MHz;
//TX
UartGpioInitStructer.GPIO_Pin = UART_TX_GPIO_PIN;
GPIO_Init( UART_TX_GPIO_PORT, & amp;UartGpioInitStructer ); //Initialize the TX pin and configure it as a multiplex function
//RX
UartGpioInitStructer.GPIO_Mode = GPIO_Mode_IN_FLOATING;
UartGpioInitStructer.GPIO_Pin = UART_RX_GPIO_PIN;
GPIO_Init( UART_RX_GPIO_PORT, & amp;UartGpioInitStructer ); //Initialize the RX pin and configure it as an input

//Configure USART peripherals
USART_DeInit( UART_PORT ); //peripheral reset

if( USART1 == UART_PORT ) //enable peripheral clock
{
RCC_APB2PeriphClockCmd( UART_PORT_CLK, ENABLE );
} // Different USART peripherals may be on different APB clocks
else //STM32F103 MCU only has USART1 on APB2, if there is a difference between the platforms, make corresponding changes
{
RCC_APB1PeriphClockCmd( UART_PORT_CLK, ENABLE );
}

UartinitStructer.USART_BaudRate = UartBaudRate; //Set the baud rate
UartinitStructer.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //do not use flow control
UartinitStructer.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; // send and receive
UartinitStructer.USART_Parity = USART_Parity_No; //Without parity
UartinitStructer.USART_StopBits = USART_StopBits_1; //A stop bit
UartinitStructer.USART_WordLength = USART_WordLength_8b; //8 data bits

USART_Cmd( UART_PORT, DISABLE ); //Disable peripherals
USART_Init( UART_PORT, & amp;UartinitStructer ); //Initialize peripherals
USART_Cmd( UART_PORT, ENABLE ); //Enable the peripheral
}

/**
  * @brief : Serial port sends data
  * @param :
  * @TxBuffer: first address of sending data
  * @Length: data length
  * @note : None
  * @retval: None
  */
void drv_uart_tx_bytes( uint8_t* TxBuffer, uint8_t Length )
{
while( Length-- )
{
while( RESET == USART_GetFlagStatus( UART_PORT, USART_FLAG_TXE ));
UART_PORT->DR = *TxBuffer;
TxBuffer++;
}
}

/**
  * @brief : The serial port receives data
  * @param :
  * @RxBuffer: Send data first address
  * @note : none
  * @retval: the number of bytes received
  */
uint8_t drv_uart_rx_bytes( uint8_t* RxBuffer )
{
uint8_t l_RxLength = 0;
uint16_t l_UartRxTimOut = 0x7FFF;
\t
while( l_UartRxTimOut-- ) //Waiting to query serial port data
{
if( RESET != USART_GetFlagStatus( UART_PORT, USART_FLAG_RXNE ))
{
*RxBuffer = (uint8_t)UART_PORT->DR;
RxBuffer++;
l_RxLength++;
l_UartRxTimOut = 0x7FFF; // Receive a character, reply waiting time
}
if( 100 == l_RxLength )
{
break; // cannot exceed 100 bytes
}
}
\t
return l_RxLength; //Waiting for timeout, data receiving is complete
}

drv_AS62.c

/**
  ***************************************************** *****************************
  * @author Zeyao Technology ASHINING
  * @version V3.0
  * @date 2016-10-08
  * @brief AS62 configuration C file
  ***************************************************** *****************************
  * @attention
  *
  * Official website: http://www.ashining.com
  * Taobao: https://shop105912646.taobao.com
  * Alibaba: https://cdzeyao.1688.com
  ***************************************************** *****************************
  */
  
  
#include "drv_AS62.h"


// module configuration parameter array
//To change the module parameters, just change the value of the parameter array, and then initialize
const uint8_t g_ASxx_Param_Config[ 6 ] = { 0xC0, 0x12, 0x34, 0x1A, 0x17, 0xC4 }; //fixed-point mode
const uint8_t g_ASxx_Config_Status_OK[ ] = { 0x4F, 0x4B, 0x0D, 0x0A };


/**
  * @brief : ASxx module initialization
  * @param : none
  * @note : According to the default parameter initialization, modify the default parameter table to change the module initialization parameters
  * @retval:
  * @ASxx_Write_OK write success
  * @ASxx_Write_ERROR write failed
  */
ASxxWriteStatusType ASxx_param_init( void )
{
uint8_t i = 0;
uint8_t Read_Buff[ 5 ] = { 0 };
\t
drv_uart_tx_bytes((uint8_t *)g_ASxx_Param_Config, 6 );
drv_uart_rx_bytes( Read_Buff );
\t
for( i = 0; i < 4; i ++ )
{
if( Read_Buff[ i ] != g_ASxx_Config_Status_OK[ i ] )
{
break;
}
}
\t
if( 4 == i )
{
return ASxx_Write_OK; //The configuration is successful
}
else
{
return ASxx_Write_ERROR; //configuration failed
}
\t
}

/**
  * @brief : ASxx module read configuration parameters
  * @param :
  * @pReadBuffer: parameter return address
  * @note : none
  * @retval: None
  */
void ASxx_read_param( uint8_t *pReadBuffer )
{
uint8_t Read_Cmd[ 3 ] = { 0xC1, 0xC1, 0xC1 };

drv_uart_tx_bytes( Read_Cmd, 3 );
drv_uart_rx_bytes( pReadBuffer );
\t
}

/**
  * @brief : The ASxx module reads the hardware version number
  * @param :
  * @pReadBuffer: hardware version number return address
  * @note : none
  * @retval: None
  */
void ASxx_read_version( uint8_t *pReadBuffer )
{
uint8_t Read_Cmd[ 3 ] = { 0xC3, 0xC3, 0xC3 };

drv_uart_tx_bytes( Read_Cmd, 3 );
drv_uart_rx_bytes( pReadBuffer );
}

/**
  * @brief : ASxx module reads the actual voltage value
  * @param :
  * @pReadBuffer: voltage return address
  * @note : none
  * @retval: None
  */
void ASxx_read_voltage( uint8_t *pReadBuffer )
{
uint8_t Read_Cmd[ 3 ] = { 0xC5, 0xC5, 0xC5 };

drv_uart_tx_bytes( Read_Cmd, 3 );
drv_uart_rx_bytes( pReadBuffer );
}

/**
  * @brief : ASxx module reset
  * @param : none
  * @note : none
  * @retval: None
  */
void ASxx_reset( void )
{
uint8_t Read_Cmd[ 3 ] = { 0xC4, 0xC4, 0xC4 };

drv_uart_tx_bytes( Read_Cmd, 3 );
}

/**
  * @brief : ASxx module sends data (fixed-point mode)
  * @param :
  * @Addr_H: address high
  * @Addr_L: address low
  * @Channel: channel
  * @pTxBuff: send data address
  * @Length: the number of sent data
  * @note : The maximum number of data in fixed-point mode is 29
  * @retval: None
  */
void ASxx_tx_packet( uint8_t Addr_H, uint8_t Addr_L, uint8_t Channel, uint8_t *pTxBuff, uint8_t Length )
{
uint8_t Header[ 3 ] = { 0 };
\t
Header[ 0 ] = Addr_H;
Header[1] = Addr_L;
Header[2] = Channel;
\t
drv_uart_tx_bytes( Header, 3 );
\t//send data
drv_uart_tx_bytes( pTxBuff, Length );
}

/**
  * @brief : ASxx module receives data (fixed-point mode)
  * @param : none
  * @note : The maximum number of data in fixed-point mode is 29
  * @retval: None
  */
uint8_t ASxx_rx_packet( uint8_t *pRxBuff )
{
uint8_t Length = 0;
\t
Length = drv_uart_rx_bytes( pRxBuff );
\t
return Length;
}

drv_delay.h

/**
  ***************************************************** *****************************
  * @author Zeyao Technology ASHINING
  * @version V3.0
  * @date 2016-10-08
  * @brief DELAY configuration H file
  ***************************************************** *****************************
  * @attention
  *
  * Official website: http://www.ashining.com
  * Taobao: https://shop105912646.taobao.com
  * Alibaba: https://cdzeyao.1688.com
  ***************************************************** *****************************
  */


#ifndef __DRV_DELAY_H__
#define __DRV_DELAY_H__


#include "stm32f10x_rcc.h"
#include "stm32f10x_tim.h"


/** Use timer for precise delay */
//delay hardware definition
#define DELAY_TIME_BASE TIM2
#define DELAY_TIME_BASE_CLK RCC_APB1Periph_TIM2


void drv_delay_init( void );
void drv_delay_us( uint16_t Us );
void drv_delay_ms( uint8_t Ms );
void drv_delay_500Ms( uint8_t Ms_500 );
void drv_delay_free( uint32_t Delay_Time );

#endif

drv_led.h

/**
  ***************************************************** *****************************
  * @author Zeyao Technology ASHINING
  * @version V3.0
  * @date 2016-10-08
  * @brief LED configuration H file
  ***************************************************** *****************************
  * @attention
  *
  * Official website: http://www.ashining.com
  * Taobao: https://shop105912646.taobao.com
  * Alibaba: https://cdzeyao.1688.com
  ***************************************************** *****************************
  */


#ifndef __DRV_LED_H__
#define __DRV_LED_H__


#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"



//LED hardware definition
#define LED_RED_GPIO_PORT GPIOB
#define LED_RED_GPIO_CLK RCC_APB2Periph_GPIOB
#define LED_RED_GPIO_PIN GPIO_Pin_5

#define LED_BLUE_GPIO_PORT GPIOE
#define LED_BLUE_GPIO_CLK RCC_APB2Periph_GPIOE
#define LED_BLUE_GPIO_PIN GPIO_Pin_5


/** LED definition */
typedef enum LedPort
{
LED_RED = 0, //red LED
LED_GREEN //Green LED
}LedPortType;


void drv_led_init( void );
void drv_led_on( LedPortType LedPort );
void drv_led_off( LedPortType LedPort );
void drv_led_flashing( LedPortType LedPort );

//Red LED operation function
#define led_red_on( ) drv_led_on( LED_RED )
#define led_red_off( ) drv_led_off( LED_RED )
#define led_red_flashing( ) drv_led_flashing( LED_RED )
//Blue LED operation function
#define led_green_on( ) drv_led_on( LED_GREEN )
#define led_green_off( ) drv_led_off( LED_GREEN )
#define led_green_flashing( ) drv_led_flashing( LED_GREEN )


#endif

drv_uart.h

/**
  ***************************************************** *****************************
  * @author Zeyao Technology ASHINING
  * @version V3.0
  * @date 2016-10-08
  * @brief UART configuration H file
  ***************************************************** *****************************
  * @attention
  *
  * Official website: http://www.ashining.com
  * Taobao: https://shop105912646.taobao.com
  * Alibaba: https://cdzeyao.1688.com
  ***************************************************** *****************************
  */


#ifndef __DRV_UART_H__
#define __DRV_UART_H__


#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_usart.h"


//Serial port hardware definition
#define UART_PORT USART1
#define UART_PORT_CLK RCC_APB2Periph_USART1
#define UART_PORT_AF GPIO_Remap_USART1

//serial port pin definition
#define UART_TX_GPIO_PORT GPIOA
#define UART_TX_GPIO_CLK RCC_APB2Periph_GPIOA
#define UART_TX_GPIO_PIN GPIO_Pin_9

#define UART_RX_GPIO_PORT GPIOA
#define UART_RX_GPIO_CLK RCC_APB2Periph_GPIOA
#define UART_RX_GPIO_PIN GPIO_Pin_10


void drv_uart_init( uint32_t UartBaudRate );
void drv_uart_tx_bytes( uint8_t* TxBuffer, uint8_t Length );
uint8_t drv_uart_rx_bytes( uint8_t* RxBuffer );



#endif

drv_AS62.h

/**
  ***************************************************** *****************************
  * @author Zeyao Technology ASHINING
  * @version V3.0
  * @date 2016-10-08
  * @brief AS62 configuration H file
  ***************************************************** *****************************
  * @attention
  *
  * Official website: http://www.ashining.com
  * Taobao: https://shop105912646.taobao.com
  * Alibaba: https://cdzeyao.1688.com
  ***************************************************** *****************************
  */
  
  
#ifndef __DRV_AS62_H__
#define __DRV_AS62_H__


#include "drv_uart.h"


typedef enum
{
ASxx_Write_OK = 0, //write successfully
ASxx_Write_ERROR //write failed
}ASxxWriteStatusType;



ASxxWriteStatusType ASxx_param_init( void );
void ASxx_read_param( uint8_t *pReadBuffer );
void ASxx_read_version( uint8_t *pReadBuffer );
void ASxx_read_voltage( uint8_t *pReadBuffer );
void ASxx_reset( void );
void ASxx_tx_packet( uint8_t Addr_H, uint8_t Addr_L, uint8_t Channel, uint8_t *pTxBuff, uint8_t Length );
uint8_t ASxx_rx_packet( uint8_t *pRxBuff );

#endif

The above is the whole core. If you don’t want to scan the code to download the source code package, you can copy and paste it after logging in. Then, for the steps of creating a project, please refer to the beginning of the bilili punctual atom stm32! !