2023-05-15 10:40 PM
Hello,
For below code, I am surprised that variable value is not updating. I cross checked the same in debug mode.
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include "dac.h"
#include "dma.h"
#include "fdcan.h"
#include "hrtim.h"
#include "i2c.h"
#include "spi.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "core_algo.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
uint16_t nik_variable = 0; //Variable declared here
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc);
void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc);
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* 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_DMA_Init();
MX_FDCAN1_Init();
MX_HRTIM1_Init();
MX_TIM1_Init();
MX_USART3_UART_Init();
MX_ADC1_Init();
MX_ADC2_Init();
MX_ADC3_Init();
MX_TIM8_Init();
MX_TIM20_Init();
MX_DAC1_Init();
MX_I2C1_Init();
MX_SPI3_Init();
MX_TIM2_Init();
MX_ADC4_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
nik_variable = 500; //variable is not updating
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
The variable named nik_variable is not changing its value to 500 from initial value of 0. The increment of nik_variable was also done using nik_variable++ but the result remains the same.
Solved! Go to Solution.
2023-05-16 12:31 AM
Probably the variable has been optimised because you assign it once but don't do anything useful with it. If you set the compiler to "do not optimise", you should find it again.
Regards
/Peter
2023-05-16 12:31 AM
Probably the variable has been optimised because you assign it once but don't do anything useful with it. If you set the compiler to "do not optimise", you should find it again.
Regards
/Peter
2023-05-16 12:45 AM
If it is changed under interrupt or callback, use volatile keyword
2023-06-18 01:58 PM
Hi,
I am also facing the same problem after updating CUBE IDE... I tried using volatile and Optimization - None(O0) from properties menu... But still having the same issue and coding with ST product becomes harder..
A sample code which never executed is listed below. Is there any solution for it....
2023-06-18 03:14 PM
It should not execute - the for () loop condition is always false.
2023-06-18 04:28 PM
are you sure that the code starts to execute in while loop at all ? maybe it freezes before it even gets to while loop.
disable some code, start first with ADC and see what happens.
2023-06-20 03:19 AM
Thank you, but that ( SpicnT == 40 ) was a typematic error and the actual code is listed below. the loop is executing in another function when the commented code (// HAL_GPIO_WritePin(SPI6_CNV_GPIO_Port, SPI6_CNV_Pin, 0) ;) was inserted. My board has an ethernet with 80 Single channel adcs connected in daisy chain (16 ADCs Chained x 5 SPIs), with 32KSPS. everything is working excluding the adc convert/data ready synchronization, for which i am using the below timer code. core STM32H753.
2023-06-20 05:03 AM - edited 2023-06-20 05:04 AM
That's the result of using HAL functions for trivial tasks. Do NOT compare anything with GPIO_PIN_SET constant. If you love HAL so much that you must use it everywhere, then at least do "!= GPIO_PIN_RESET" instead. BTW your use of goto suggests that you need to learn a lot about C basics.