 Now we can move to the next hands-on, which will be, again, because on our Leuclo we have only our light in one button. It will be also again a co-operation between the light and the button. But now we do this with a little bit different way. We will use the button, not as the standard floating input, but we will use this as an interrupt. We set the button to create the interrupt, which will be handled with our application, and in the interrupt we will change the state of the button. Then I think it will be a very nice example to show you the different things, which is the base for the microcontroller, and this is the interrupt. How to set up the interrupt and how to start working with the interrupts. Then we first start with the new project. I will start my new project in the selector. I will select again the F4401. I will select the package. In my case is the LQFP64, which is my Leuclo. And the microcontroller is 512 kilobyte flash device. The STM32F401RET. I will select this one. And I will wait. Okay. First of all I will select the PA5, because I know that the LED is on the PA5. Then I select this pin as an output. I think label is not necessary. And now the input. I know that the PC13 is my GPL pin. I can check this pin here. You know this is the pin, which is connected to PC13, connected with the pull-up resistor. Then when we press the button, we will create a falling edge on the pin. This is also good to know. Okay. Then we select the pin PC13. And we not set it as an input. But we select the GPL pin as an XT pin 13. It means the XT means the X10R interrupt controller. We set this as an XT. Then if you have the same configuration, one pin as an output, second one as the GPL XT, then you have the same situation as me. It's good. Clocks, we can left unchanged, because I'm okay with 16 MHz for this application. But we now need to look at the configuration. First of all, we check the GPL settings. Now the GPL, the PA5, this is our LED. Okay. The output level after initialization will be low. This is perfect. GPL mode push-pull. So okay. No pull-up or no pull-down resistor. For me, and the maximum speed is low. This is okay. And now pin PC13. Now we see the GPL mode is set as the XT interrupt mode. This is okay. With rising edge trigger detection. Rising edge, in our case, is the releasing the button. Then we don't want to react on the releasing the pin, the button. Then we look on the defend mode. We have the falling edge. We can create the interrupt. And we have also, we can react on the falling or the raising edges. And there are also more modes. There is the external event mode. What is the defend between the external event and the external interrupt? The defense is that the external event mode not create the interrupt. The microcontroller not stop processing the mine program and jumps into interrupt. In the event, the microcontroller continues. The event mode is mainly used for the wake-uping microcontroller for the low power mode. When we don't want to enter the interrupt routine. But for our case, we will use the external mode with falling edge trigger detection. Then this is okay. Save this. And now, second part, which we need to handle here. It's the NVIC controller, because we not set the external interrupt. One part is the GPO, which create the notification for the core that we want to create the interrupt. And second part is the NVIC controller, which is embedded inside the core. Which also need to allow this interrupt for processing. Then we open the NVIC. What we can see here. We can see here the priority bits. This is okay. But definitely, we can search for our interrupt. And we're using the x-tip. Then we need to enable also this x-tip. Like here, and it's enabled. This is perfect. Then after this, it will jump into the interrupt. Okay. Then I can save my project. My projects. I will use now the system warbench. Why not? And I will name it as the x-t1lap. I click on the okay. And I can generate my project. Okay. When everything is okay. I can run my system warbench here. I select my workspace. It's okay for me. We will delete previous projects from my workspace. It's not necessary. And I need to import the last one. We will open the import. We will open the general. Import from existing project. And the selector. We will open projects. And here is my x-tip. I click on the import. It's here in my project. Okay. Main is always the same. I have the hl in it. We talk about this. It's necessary. I have my clock configuration. It's also necessary. And I have my GPO in it. Now I can look what is inside my GPO in it. What we can see. We are enabling the port C. Port A. This is necessary. But here we can see that the pin for the button is set in the interrupt mode to wrap in the following cache. Everything is okay. But something new. You can see we also here enabling the NVIC. The nest-tip-intervector controller for our button. Then after this initialization, the microcontroller, when the interrupt came, we jump into the interrupt routine. Now, we have to find the interrupt routine. It's here in our not in the main.c file. But it's here in the stm32f4x6 underscore it file. Then here are all interrupt routines which I use now. And we can see the non-mass cable interrupt. Hard-fold handler in case that we do something wrong or some pointers will allow the code into the unhandled memory. Some mem-managed handler. Bus-fold handler. User-fold. Usage-fold handler. Debug-monitor handler. We have here our sys-tick, which is periodic interrupt from our core timer. Which create the interrupt each one millisecond. Which is automatically configured with the HAL library. But here we have our xt interrupt handler, which handles interrupts from the pins from the 10 to 15. Because we have pin 13, it will be handled in this interrupt. Then how to handle the interrupt? You can see that the QPMX gave here the function, which for us will handle the interrupts. This means that when the microcontroller or the external pay-fay triggers the interrupt, the microcontroller jumps into this routine. And the correct handling of the interrupts depends on the pay-fay, but usually you need to clear some bits in the registers to allow the microcontroller to leave the interrupt. If we not clear all the bits, which is necessary to do, the description is usually in the reference manual, we can enter again this interrupting and we will be here trapped forever in the loop. Then for this, the QPMX gave for us the HAL library IACO handler, which will clear all these bits for us. This is very nice because we don't need now to read the reference manual, check which bits need to be clear. Then this is a nice automatic part, also a nice feature of the HAL. But now, how to be notified about the interrupt? For this, the HAL library used the callbacks. Then for us, it's only a question how to find the callbacks, which is used inside this IACO handler. For this, we go into the drivers, into the HAL drivers, into the sources, and we go into the gpl.c. And we know that all the callbacks are defined as an underscore-underscore weak. Then we will try to find this function. I will try, and if I, what I think, I think here the HAL underscore-gpl underscore-xt underscore-callback. This seems that I can use this function because this function will be called from my interrupt in the interrupt HAL handler. And how to use this? I will copy this part because it's defined as a weak. That this mean, the weak mean that if he not found this function in my code, he used this one. But if he found this one somewhere else in the code without weak, he will use the defend definition. Then I put it inside my main, I put it here on the top. It's not so correct. The correct place will be here on the bottom in section 4. But this is closer to my main. I will use this part. Okay, and now I defined my callback. Then when I will go into the interrupt, the HAL library, the HAL HAL handler will notify me with this callback. And I can put here some action. I discard this callback. Then I put here the HAL underscore-gpio underscore-callback. It will be the gpioa. Then gpio underscore-pin underscore-fi, which is my left. I start this. I store my file. Now I can compile my file. Okay, my build finished. No error reported. It's good. Then I can here create my debug configuration. The bucket on the EC6 has 1032 debugging. The window will pop up. And I will create new board for this. You can use existing board if you want. Then I only here select the correct debugger, which is the stealing version 2.1. This will be correct. And I can start debug. Why not? Yes, I want to go into the debugging perspective. Okay, we can run the code. No problems. And when I press the button, my light is on. When I press it again, that is all. Also what you need to be careful. In case that you have the different button configuration or you connect the button on your own, be careful with the debouncing effect. When the button without the filtering capacitor can create some bouncing noise. And then the microcontroller can register multiple falling edges. Then be careful. In my case, in our new claw, in this connection, you can see there is 100 nanofat capacitor, which will help to filter these noises, which created the switching the button on and off.