2020-07-14 01:59 PM
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SPI1_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
MX_USART3_UART_Init();
/* USER CODE BEGIN 2 */
USART1->CR1 |= USART_CR1_RXNEIE_RXFNEIE; ///USART_CR1_RXNEIE;
NVIC_SetPriority(USART1_IRQn, 1);
NVIC_EnableIRQ(USART1_IRQn);
USART2->CR1 |= USART_CR1_RXNEIE_RXFNEIE; ///USART_CR1_RXNEIE;
NVIC_SetPriority(USART2_IRQn, 3);
NVIC_EnableIRQ(USART2_IRQn);
USART3->CR1 |= USART_CR1_RXNEIE_RXFNEIE; ///USART_CR1_RXNEIE;
NVIC_SetPriority(USART3_4_LPUART1_IRQn, 2);
NVIC_EnableIRQ(USART3_4_LPUART1_IRQn);
GPIOB->ODR ^= GPIO_PIN_13; // start modem
GPIOB->ODR ^= GPIO_PIN_14; // glow led
modemInit();
gpsStart();
while(getRssiValueInDbm()==0 && tt!=20){
UARTSendString(logPort,(unsigned char *)"No network\r\n");
HAL_Delay(100);
tt++;
}
UARTSendString(logPort,(unsigned char *)"RSSI in dbm = \r\n");
HAL_Delay(100);
if(checkSimCardPresense()==1){
sendRssiToRtu();
}
UARTSendString(logPort,(unsigned char *)"\r\n");
HAL_Delay(1000);
if(connectCheck()==0){
HAL_Delay(100);
mqttInit();
}
//UARTSendString(logPort,(unsigned char*)"MODEM INIT END");
UARTBufReset(rtuPort);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
startWatchdog();
while (1)
{
/* USER CODE BEGIN 3 */
Geardata gearData;
PointMachineData pmData;
resetWatchdog();
index = -1;
index = dequeue_pm_data(&pmData);
if (index != -1)
createJSONANDSendPMDataToMQTT(pmData);
resetWatchdog();
index = -1;
index = dequeue_gear_data(&gearData);
if (index != -1)
createJSONANDSendGearDataToMQTT(gearData);
/* Send RSSI to RTU in every 2 minute */
if(rssiTimeDelay==1){
if(checkSimCardPresense()==1){
sendRssiToRtu();
}
rssiTimeDelay=0;
}
/* Send GPS time to RTU in every 1 hour */
if(gpsRestartTime==1 || gpsFirstStart==1){
if(gpsTimeToRtu()!=0){
gpsFirstStart=0;
gpsRestartTime=0;
}
}
}
/* USER CODE END 3 */
//}
}
2020-07-14 02:37 PM
Identify sites where failure can occur, use bisection to narrow down the candidates.
Monitor stack usage.
Instrument the Hard Fault Hander and Error Handler routines so they output actionable information if they are reached.
Toggle LEDs on entry/exit for interrupts, or use GPIO you can scope.
2020-07-15 10:37 AM
Thank you for your reply...
My program should restart after any problem, because I had used watchdog. Is there any condition in which controller stuck after using watchdog ??
One week ago, I have install seven devices in field. Three is steel working and four stopped. My device is used to take data through uart from other device and send to mqtt server.
2020-07-15 12:11 PM
>>Is there any condition in which controller stuck after using watchdog ??
If the NRST pin is driven high with a push-pull driver from some other chip or circuit, the STM32 won't restart properly
The device might restart, but issues in the code between Reset_Handler and main() might cause it to look broken/stuck. Basic debugging techniques, like outputting waypoint or progress indications to UART, GPIO or LEDs might help identify where it gets stuck, or whether it restarts properly out of a Watchdog event.
Need to review testing and diagnostic expectations.
2020-07-15 01:50 PM
what is the ratio between baud rate vs clock tolerance?