cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO Interrupt not working Properly.

Rohit007
Associate III

Hello,

I am using the stm32G0B1RE MCU board to detect the GPIO interrupts, after every 140ms, but MCU is not responding to these interrupts fully, like I need to detect the 30 interrupts in 4 seconds, but MCU is detecting only 20 to 21 interrupts, but as I try to detect these interrupts in more time like 30 seconds to 6 seconds in between I am getting all the interrupts. but, after  this giving less time like 4 seconds or 5 seconds , frequency of detecting those interrupt just gets reduced. 

i have also checked if I am getting all the signals on pin using CRO, it is able to detect the all the 30 signals, but MCU is not detecting those all signals.

please, help I anybody has any idea what wrong is happening.

Actually I am using a device which contains a gear with 30 tooths, which is connected to motor rotating at speed 1 RPM to 20 RPM, the gear is connected near to the IC that generates the sine and cosine waveforms according to the gear in between the two tooth and also generates the interrupt whenever the tooth is passed across it.

the device I am using is working on 2.7v and stm32 is working on 3v3, can this be the issue, I don't know. but the device is using the arduino MCU which is working perfectly . but I don't know why stm32 is not able to detect the same interrupts.

this is a part of code:

 
 

 

 

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_USART2_UART_Init();

MX_ADC1_Init();

/* USER CODE BEGIN 2 */

/* USER CODE END 2 */

 

/* Infinite loop */

/* USER CODE BEGIN WHILE */

init_TMR_sensor(&hadc1, &TMR_info);

HAL_ADCEx_Calibration_Start(&hadc1);

 

 

while (1)

{

printf("%d\r\n",tooth);

HAL_Delay(100);

 

}

 

 

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

 

}

/* USER CODE END 3 */

}

void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)

{

tooth++;

}

static void MX_GPIO_Init(void)

{

GPIO_InitTypeDef GPIO_InitStruct = {0};

/* USER CODE BEGIN MX_GPIO_Init_1 */

/* USER CODE END MX_GPIO_Init_1 */

 

/* GPIO Ports Clock Enable */

__HAL_RCC_GPIOC_CLK_ENABLE();

__HAL_RCC_GPIOF_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();

__HAL_RCC_GPIOB_CLK_ENABLE();

 

/*Configure GPIO pin Output Level */

HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_RESET);

 

/*Configure GPIO pin : TOOTH_GEAR_EXTI_Pin */

GPIO_InitStruct.Pin = TOOTH_GEAR_EXTI_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;

GPIO_InitStruct.Pull = GPIO_NOPULL;

HAL_GPIO_Init(TOOTH_GEAR_EXTI_GPIO_Port, &GPIO_InitStruct);

 

/*Configure GPIO pin : DIRECTION_GPIO_Pin */

GPIO_InitStruct.Pin = DIRECTION_GPIO_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

GPIO_InitStruct.Pull = GPIO_PULLDOWN;

HAL_GPIO_Init(DIRECTION_GPIO_GPIO_Port, &GPIO_InitStruct);

 

/*Configure GPIO pin : LED_GREEN_Pin */

GPIO_InitStruct.Pin = LED_GREEN_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_PULLUP;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

HAL_GPIO_Init(LED_GREEN_GPIO_Port, &GPIO_InitStruct);

 

/*Configure GPIO pin : TMR_TOOTH_INTERRUPT_PIN_Pin */

GPIO_InitStruct.Pin = TMR_TOOTH_INTERRUPT_PIN_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;

GPIO_InitStruct.Pull = GPIO_PULLDOWN;

HAL_GPIO_Init(TMR_TOOTH_INTERRUPT_PIN_GPIO_Port, &GPIO_InitStruct);

 

/* EXTI interrupt init*/

HAL_NVIC_SetPriority(EXTI0_1_IRQn, 0, 0);

HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);

 

/* USER CODE BEGIN MX_GPIO_Init_2 */

/* USER CODE END MX_GPIO_Init_2 */

}

 

 

10 REPLIES 10

> I have checked the edges on CRO,

Can you show this here?

> Difference between the each rising edge passed is 140ms which I believe is enough.

Yes, it should be. I suspect something is wrong in the test setup. Perhaps toggle a pin in the interrupt and capture both the input and the state of this pin on a logic analyzer to prove your assumptions are correct.

 

Is tooth defined as volatile? Doubt it is the issue, but could be.

If you feel a post has answered your question, please click "Accept as Solution".