@@ -100,6 +100,10 @@ uint8_t PWR_PVDGetLevel(void)
100100// Last measured values
101101static float temperature , pressure , humidity ;
102102
103+ // Last measured values
104+ const uint8_t radio_health_check_state = 4 ;
105+ static uint8_t radio_health_check_state_cnt = 0 ;
106+
103107// Msg frame
104108static radio_msg_sensor_frame msgf =
105109{
@@ -149,9 +153,12 @@ int main(void)
149153 /* USER CODE BEGIN 2 */
150154 dbg ("LUK6" );
151155
156+ // Read current config from eprom
152157 app_settings_init ();
153- radio_init ();
158+ // Enable sensor
154159 sensor_init ();
160+ // Enable radio
161+ radio_init ();
155162 /* USER CODE END 2 */
156163
157164 /* Infinite loop */
@@ -170,6 +177,9 @@ int main(void)
170177 {
171178 sprintf (dbg_buf , "M_LWP_EXIT:%d" , HAL_RTCEx_BKUPRead (& hrtc , RTC_BKP_DR2 ));
172179 dbg (dbg_buf );
180+ // Enable sensor pin
181+ HAL_GPIO_WritePin (SENSOR_VDD_GPIO_Port , SENSOR_VDD_Pin , GPIO_PIN_SET );
182+ HAL_Delay (100 );
173183 HAL_RTCEx_BKUPWrite (& hrtc , RTC_BKP_DR2 , 0 );
174184 }
175185
@@ -189,22 +199,38 @@ int main(void)
189199 msgf .temperature = temperature ;
190200 msgf .pressure = pressure ;
191201 msgf .humidity = humidity ;
192- //PWR_PVDCmd(ENABLE);
193202 msgf .vbatt = 3300 ;//adc_read_vbatt();
194203
195204 /* Send result data */
196205 radio_send (& msgf );
197206
198207 /* Refresh watchdog, no more than 2[s] must expire before next refresh */
199208 HAL_WWDG_Refresh (& hwwdg );
200- uint8_t rxMsgWaitCntSecs = 10 ; // 5 seconds
201- while (rxMsgWaitCntSecs -- )
209+ uint8_t rx_msg_wait_cnt_secs = 5 ; // 5 seconds
210+ while (rx_msg_wait_cnt_secs -- )
202211 {
203212 /* Wait 1 second for incoming data from ledclock */
204213 HAL_Delay (1000 );
205214 /* Refresh watchdog, no more than 2[s] must expire before next refresh */
206215 HAL_WWDG_Refresh (& hwwdg );
207216 }
217+
218+ // Check if any data from ledclock came
219+ if (!radio_was_data_received ())
220+ {
221+ radio_health_check_state_cnt ++ ;
222+ }
223+ else
224+ {
225+ radio_health_check_state_cnt = 0 ;
226+ radio_data_received_clear ();
227+ }
228+
229+ // If any problem with radio exists, restrat it
230+ if (radio_health_check_state_cnt >= radio_health_check_state )
231+ {
232+ radio_restart ();
233+ }
208234 }
209235 /* USER CODE END 3 */
210236}
@@ -620,7 +646,6 @@ static void enter_low_power_mode()
620646
621647 /* Put radio into sleep mode */
622648 radio_sleep ();
623- //HAL_GPIO_WritePin(SX1278_RESET_GPIO_Port, SX1278_RESET_Pin, GPIO_PIN_SET);
624649
625650 /* Disable sensor */
626651 HAL_GPIO_WritePin (SENSOR_VDD_GPIO_Port , SENSOR_VDD_Pin , GPIO_PIN_RESET );
@@ -669,8 +694,6 @@ static void enter_low_power_mode()
669694 /* Enable SysTick. */
670695 //HAL_ResumeTick();
671696 //HAL_GPIO_WritePin(SX1278_RESET_GPIO_Port, SX1278_RESET_Pin, GPIO_PIN_RESET);
672- HAL_GPIO_WritePin (SENSOR_VDD_GPIO_Port , SENSOR_VDD_Pin , GPIO_PIN_SET );
673- HAL_Delay (100 );
674697 dbg ("M_LPM_RUN" );
675698}
676699
0 commit comments