//.... int main(void) { /* USER CODE BEGIN 1 */ uint8_t lora_params[8], tx_buf[LoRa_MAX_DATA_SIZE], rx_buf[64]; uint32_t cur_tick; HAL_StatusTypeDef status; /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART3_UART_Init(); /* USER CODE BEGIN 2 */ MX_I2C2_Init(); memset(tx_buf, 0, LoRa_MAX_DATA_SIZE); memset(rx_buf, 0, 64); //Wait initially until the controller io transactions is available cur_tick = HAL_GetTick(); while(((HAL_GetTick() - cur_tick) < 1000) && HAL_GPIO_ReadPin(GPIOB, LoRa_AUX_Pin) != GPIO_PIN_SET); //Wait until the AUX pin is set //If controller is busy and exceeds the timeout, blink the led then abort if(HAL_GPIO_ReadPin(GPIOB, LoRa_AUX_Pin) != GPIO_PIN_SET){ HAL_GPIO_WritePin(GPIOA, USER_LED_Pin, GPIO_PIN_SET); Error_Handler(); } else{ //Set the initial lora module mode [11 -> Sleep] HAL_GPIO_WritePin(GPIOB, LoRa_M0_Pin, GPIO_PIN_SET); //M0 HAL_GPIO_WritePin(GPIOB, LoRa_M1_Pin, GPIO_PIN_SET); //M1 HAL_Delay(20); //Wait until the controller is available cur_tick = HAL_GetTick(); while(((HAL_GetTick() - cur_tick) < 100) && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4) != GPIO_PIN_SET); //Wait until the AUX pin is set //Clear buffer & send the initial option parameters memset(lora_params, 0, 8); //Save after shutdown (through command flash interface) lora_params[0] = 0xC0; //Broadcast transmission (NC address) lora_params[1] = 0x00; lora_params[2] = 0x00; //UART PARITY: 8N1, BAUD: 9600bps, DATA RATE (SF): SF7 / 2.4k, lora_params[3] = 0x1A; //0b00011010 //Channel settings: 868 MHz (862 + OFFSET->6) lora_params[4] = 0x06; //Options: Transparent Transmission, IO Push-Pull, Wireless wakeup: 250ms, FEC OFF, Power: 30 dBm lora_params[5] = 0x40; //0b0100 0000; //Send the option bytes (wait for the AUX pin after the transaction) if((status = HAL_UART_Transmit(&huart3, lora_params, 6, 100)) == HAL_OK){ //HAL_Delay(20); if((status = HAL_UART_Receive(&huart3, rx_buf, 6, 1000)) == HAL_OK){ HAL_Delay(50); //Check if the params sent equal to the echo packet sent back if(strncmp((const char*)rx_buf, (const char*)lora_params, 6) == 0){ //Set the normal mode and get ready for the operations HAL_GPIO_WritePin(GPIOB, LoRa_M0_Pin, GPIO_PIN_RESET); //M0 HAL_GPIO_WritePin(GPIOB, LoRa_M1_Pin, GPIO_PIN_RESET); //M1 memset(rx_buf, 0, 64); //Clear RX buffer HAL_Delay(1); //Initialize the MPU int ret = mpu6050_init(&hi2c2); if (ret != 0) Error_Handler(); HAL_Delay(1); } else{ HAL_GPIO_WritePin(GPIOA, USER_LED_Pin, GPIO_PIN_SET); Error_Handler(); } } else{ HAL_GPIO_WritePin(GPIOA, USER_LED_Pin, GPIO_PIN_SET); Error_Handler(); } } else{ HAL_GPIO_WritePin(GPIOA, USER_LED_Pin, GPIO_PIN_SET); Error_Handler(); } } //.... } //....