2022-07-22 12:20 AM
Hi,
I am using Zegbee messaging cluster on STM32WB55 to send messages between some Zigbee end devices and a coordinator.
Each end device measures the temperature via I2C sensor and sends a message with the temperature value to the coordinator and then goes to sleep mode for 5 seconds. The software works well.
But when I try to also measure the reference voltage to send its value with the temperature value in the message, the software freezes!
In app_zigbee.c:
static void APP_ZIGBEE_InitMsg(void)
{
APP_DBG("APP_ZIGBEE_InitMsg");
uint8_t buf22[59];
memset(buf22, '\0', sizeof(buf22));
char buf0[]="TM+1+";
strcat(buf22, buf0); // Adding some text to the meassage
uint8_t buf2[3];
memset(buf2, '\0', sizeof(buf2));
float temp_c2 ;
temp_c2 = TMP117_get_Temperature2(hi2c3); // measuring the temperature
sprintf((char*)buf2,"+%d",
((int)temp_c2 / 100));
strcat(buf22,buf2); // Adding the temperature value to the message
uint16_t u16VRefMilliVoltsValue = 0;
uint16_t g_u32ReadVRefDigitalValue = 0 ;
HAL_ADC_Start( &hadc1 ); // Trying the start the ADC to measure the reference voltage
// The software freezes in this block!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(HAL_OK == HAL_ADC_PollForConversion(&hadc1, 50))
{
g_u32ReadVRefDigitalValue = HAL_ADC_GetValue(&hadc1);
u16VRefMilliVoltsValue = __HAL_ADC_CALC_VREFANALOG_VOLTAGE(g_u32ReadVRefDigitalValue, ADC_RESOLUTION_12B);
}
HAL_ADC_Stop(&hadc1);
my_first_message.message_id=0x00;
my_first_message.start_time=0x0000014;
//my_first_message.start_time=0x0000019;
/* Display message for 5 mn */
my_first_message.duration=0x0005;
/* High priority message */
my_first_message.message_control=0x0c;
strcpy(my_first_message.message_str,buf22);
my_first_message.extended_control=0x00;
}
When i comment the block form HAL_ADC_Start( &hadc1); to HAL_ADC_Stop(&hadc1); the software works fine.
Also when i put this block in main.c in While(1) loop bevore the command UTIL_SEQ_Run(UTIL_SEQ_DEFAULT); the software works also fine.
So, it appears to me that, the problem accrue when trying to run the adc within a task in the sequencer. If that is true, How to solve this problem?
Below are the code of ADC1 and System Clock Configuration, also a foto of the the NVIC Interrupt Table.
static void MX_ADC1_Init(void)
{
/* USER CODE BEGIN ADC1_Init 0 */
/* USER CODE END ADC1_Init 0 */
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC1_Init 1 */
/* USER CODE END ADC1_Init 1 */
/** Common config
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_VREFINT;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */
/* USER CODE END ADC1_Init 2 */
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Macro to configure the PLL multiplication factor
*/
__HAL_RCC_PLL_PLLM_CONFIG(RCC_PLLM_DIV2);
/** Macro to configure the PLL clock source
*/
__HAL_RCC_PLL_PLLSOURCE_CONFIG(RCC_PLLSOURCE_MSI);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI1
|RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_10;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK4|RCC_CLOCKTYPE_HCLK2
|RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.AHBCLK2Divider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLK4Divider = RCC_SYSCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief Peripherals Common Clock Configuration
* @retval None
*/
void PeriphCommonClock_Config(void)
{
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SMPS|RCC_PERIPHCLK_RFWAKEUP;
PeriphClkInitStruct.RFWakeUpClockSelection = RCC_RFWKPCLKSOURCE_HSE_DIV1024;
PeriphClkInitStruct.SmpsClockSelection = RCC_SMPSCLKSOURCE_HSI;
PeriphClkInitStruct.SmpsDivSelection = RCC_SMPSCLKDIV_RANGE1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
I would be very happy if someone could solve this problem.
Thanks in advance!
2022-07-27 02:57 AM
Hello,
Can you give more information about the task registration for ADC measurement and when you are setting the task ?
Best Regards