2019-04-25 07:44 AM
Hello guys, i am using STM32072 discovery board. I have a problem that i mentioned above. I have a TOUCH SENSE IC (at42qt2120) and it communicates w/i2c. I want to communicate with device that time what i want (when i pushed the buttons). IC has change pin, this pin status changes whenever sensing detected. (3.3V to0) And touched released it will be high again (0 to 3.3v) so i thought i can use this pin as external interrupt and when the intterupt occured i can read the memory that what i want to read w i2c from the touch ic. But i couldn't. Here is the codes i wrote plz help me guys.
main.h
#define DeviceAddress 0x1C<<1
extern uint8_t outbuffer[1] ;
extern I2C_HandleTypeDef hi2c1;
int.c
void EXTI0_1_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
HAL_I2C_Mem_Read(&hi2c1,DeviceAddress, 0x03, 1, outbuffer, 1,1000); // i2c read command
}
2019-04-25 12:00 PM
Calling i2c operations from interrupt handler is not a good idea.
Set a flag in the handler and check it in a background loop. It is more reliable and easier to debug this way.
-- pa
2019-04-26 11:49 PM
if i create a function and call it in while loop, are there any delay time to operate other functions? cause i have to several functions like sending datas taken from i2c with Bluetooth, receive diagnosis by using uart and indicate errors if there is by using leds. I hope u gonna understand what i try to say.
2019-04-27 01:25 AM
If the I2C bus is exclusively done within the interrupt and only there, and if the time of the interrupt is long due to the I2C Read to complete, then you can do as you wish. Otherwise, get in the main loop a polling function when there is nothing else to do and use this time to poll the pin. EXTI has PR latch bit to capture an edge, you will only need to check every 50msec
But remember, if your screen runs at 100Hz, you got 10msec per display frame update, and your touch won't need to react so fast as it's human speed.
Interrupt would be for <100usec reaction time operations with a ISR lasting less than 50us.
2019-04-27 02:07 AM
How to be sure interrupt time is long enough to execute read i2c operations? When i tried put reading i2c codes into ext int routine. I didnt receive any answer. How can i debug that time is enough or not?