2020-01-21 12:35 AM
I Did few things.
1: I used CubeMx to generate code with keil IDE
2: I made PC13 as Output to Toggle LED.
3: I made PA1 as Interrupt Pin(Button).
4: I called interrupt handler in main file under MX_GPIO_Init() function.
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
HAL_GPIO_EXTI_IRQHandler(Button_Pin); // by me
5: when i went to the defination of HAL_GPIO_EXIT_IRQHandler() function.
i found call back function there and in that function i set my flag to ONE.
and I am using this flag into my while loop for LED blinking.
extern uint8_t Interrupt_Flag;
extern void LED(void);
extern uint8_t Interrupt_Flag;
/**
* @brief This function handles EXTI interrupt request.
* @param GPIO_Pin: Specifies the pins connected EXTI line
* @retval None
*/
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
{
/* EXTI line interrupt detected */
if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
{
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
HAL_GPIO_EXTI_Callback(GPIO_Pin);
}
}
/**
* @brief EXTI line detection callbacks.
* @param GPIO_Pin: Specifies the pins connected EXTI line
* @retval None
*/
__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(GPIO_Pin);
/* NOTE: This function Should not be modified, when the callback is needed,
the HAL_GPIO_EXTI_Callback could be implemented in the user file
*/
Interrupt_Flag = 1;
}
After Doing all this I am expecting that when i give PA1 high my LED should be ON and at LOW it should be OFF.
But i am not getting output as i mention. I don't know where am i wrong.
So need your help. I tried on google but couldn't find any good example. which suits my need.
2020-01-21 12:44 AM
You did not tell us which STM32 are you using, but generally there are EXTI examples for probably all platforms in their respective Cube, e.g. [STM32Cube_FW_F4_V1.21.0]\Projects\STM32F4-Discovery\Examples\GPIO\GPIO_EXTI\
JW
2020-01-21 01:35 AM
STM32F013C8T6 Blue pill
2020-01-21 01:47 AM
When you use things like HAL, Cube (and, truth be told, high-level languages like C and C++ but let's not go there) you are adding layers that hide the underlying steps and mechanisms. This is great to get some (easy) things up and running, as well as porting from one processor to another. But another thing it does is separates the programmer from definitive documentation. All you get are examples that (largely) work but without the explanation as to why things are done in that specific way.
stm32 are complex devices, consisting of an Arm-designed Cortex processor core, some Arm-designed core peripherals and other ST-designed peripherals.
If you actually want to understand how things work so you can use them to best effect, then you could look at the official documentation. But there is a huge amount of information - too much to take in easily. There are books that try to make things easier e.g. "The Designer's Guide to the Cortex-M Processor Family"
The "definitive" documentation is spread over several documents:
When I was learning, I only knew about the Data Sheet and Reference Manual. And it was only some time later that I discovered the Programming Manual - where the Nested Vectored Interrupt Controller was described. Until I had seen that I did not know how interrupts worked.
Hope this helps,
Danish