#include "e22.h" #include "main.h" #include "inflash.h" #include "uart_dev.h" uint8_t e22_state = 0; //c0 00 09 0000 00 64 00 0a 4d 00 00 WOR定点发送 //c0 00 09 0000 00 64 00 0a 45 00 00 WOR定点收 /* 参数配置 */ e22_config_pack e22_config_data = { 0xc0, 0x00, 0x09, //写,0起始,9长度 0x00, 0x30, //地址 0x00, //网络ID 0x64, //9600,8N1,9.6k 0x00, 0x0A, //信道10 0x45, 0x00, 0x00}; //加密 static unsigned short CRC16(unsigned char *arr_buff, unsigned char len) { unsigned short crc=0xFFFF; unsigned char i, j; for ( j=0; j0){ crc=crc>>1; crc=crc^ 0xa001; }else{ crc=crc>>1; } } } return crc; } void lora_set_mode_normal() { HAL_GPIO_WritePin(RF_M0_GPIO_Port, RF_M0_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(RF_M1_GPIO_Port, RF_M1_Pin, GPIO_PIN_RESET); HAL_Delay(E22_DELAY_MS); } void lora_set_mode_wor() { HAL_GPIO_WritePin(RF_M0_GPIO_Port, RF_M0_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(RF_M1_GPIO_Port, RF_M1_Pin, GPIO_PIN_RESET); } void lora_set_mode_config() { HAL_GPIO_WritePin(RF_M0_GPIO_Port, RF_M0_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(RF_M1_GPIO_Port, RF_M1_Pin, GPIO_PIN_SET); HAL_Delay(E22_DELAY_MS); } void lora_set_mode_sleep() { HAL_GPIO_WritePin(RF_M0_GPIO_Port, RF_M0_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(RF_M1_GPIO_Port, RF_M1_Pin, GPIO_PIN_SET); } void lora_set_mode(e22_mode mode) { switch(mode) { case NORMAL: lora_set_mode_normal(); break; case WOR: lora_set_mode_wor(); break; case CONFIG: lora_set_mode_config(); break; case SLEEP: lora_set_mode_sleep(); break; default: break; } } void e22_init() { /*E22模块上电*/ HAL_GPIO_WritePin(RF_PWR_CTRL_GPIO_Port, RF_PWR_CTRL_Pin, GPIO_PIN_SET); e22_config_data.ADDL = g_stConfigInfo.addr; e22_config_data.NETID = g_stConfigInfo.net_id; e22_config_data.REG2 = e22_config_data.NETID % 27 + 10; lora_set_mode(CONFIG); uart_dev_write(g_lora_uart_handle, (void *)&e22_config_data, sizeof(e22_config_data)/sizeof(e22_config_data.func)); HAL_Delay(E22_DELAY_MS); lora_set_mode(WOR); }