2021-06-15 03:34 PM
Hi!
I have STM32F373VBTx and I have set pin PD3 as EXTI3 where PD3 call this function when the PD3 gets a falling edge. PD3 is labeled as TS_IRQ in STM32CubeIDE 1.6.1
/* Callbacks for external interrupt */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){
/* We have pressed on the touch screen -> TS_IRQ falling edge */
if(GPIO_Pin == TS_IRQ_Pin) {
TSC2046_TS_IRQ();
}
}
After this function have been called, then after the exit, then the debugger is going to here.
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
{
/* EXTI line interrupt detected */
if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != 0x00u)
{
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
HAL_GPIO_EXTI_Callback(GPIO_Pin);
}
}
And then here
void EXTI3_IRQHandler(void)
{
/* USER CODE BEGIN EXTI3_IRQn 0 */
/* USER CODE END EXTI3_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
/* USER CODE BEGIN EXTI3_IRQn 1 */
/* USER CODE END EXTI3_IRQn 1 */
}
And then goes back again to
/* Callbacks for external interrupt */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){
/* We have pressed on the touch screen -> TS_IRQ falling edge */
if(GPIO_Pin == TS_IRQ_Pin) {
TSC2046_TS_IRQ();
}
}
What this function
TSC2046_TS_IRQ();
actully does is to call this SPI transmition code.
If I don't call that function above, I don't get stuck in the interrupt. But after 2 times I have called that function above, which does this thinks below, then I get stuck in a never ending interrupt loop that calls itself.
Why? Can't I do SPI transmit inside an interrupt?
// Send TSC2046 Command and wait for a response
static uint16_t TSC2046_SendCommand(uint8_t cmd) {
// return 0; // If I remove this comment, then the function will not doing HAL_SPI and HAL_GPIO and therefore the interrupt will not loop by itself.
uint8_t lcdBuf[3] = { 0, 0, 0 };
uint16_t return16 = 0;
HAL_GPIO_WritePin(lcd.TOUCH_CS_PORT, lcd.TOUCH_CS_PIN, GPIO_PIN_RESET);
lcdBuf[0] = cmd;
HAL_SPI_Transmit(lcd.touchSpi, lcdBuf, 1, 10);
if (HAL_SPI_Receive(lcd.touchSpi, &lcdBuf[1], 2, 10) == HAL_OK) {
return16 = (lcdBuf[1] << 4) + (lcdBuf[2] >> 4);
} else {
return16 = 0;
}
HAL_GPIO_WritePin(lcd.TOUCH_CS_PORT, lcd.TOUCH_CS_PIN, GPIO_PIN_SET);
return return16;
}