 In this slot, we will do the simple hands-on, which will use the ADC, and we use it together with the interrupt. The principle will be very simple. We will configure the ADC, which will read the value, store it into the data register and then notify the microcontroller with the interrupt that we received the new data. Now the ADC with the interrupt. As usual, we start with the cubeMX, then we create the new project. Again, I'm using the F401 discovery. Like before, we use the F4 line for 1 and package LQFP64 and microcontroller stemCity to F401 RET. Okay, I can select this microcontroller and now I have my pinout. And I want to use the ADC. On this microcontroller is only one. Here on the left, I can see all possibilities. You can see we have 16 input channels for ADC and few internal ones from the temperature sensor and from other internal functions. You can here select the pin by clicking on the checkbox. But here I will select the pin manually and I use the PA0 and set it as the analog input. Now, how to read the analog values? Because this pin is unconnected and at least I want to see some known analog values. For this reason, I connect this pin, the PA0, together with my button. And my button is connected by default to PC13, which is here. Then you only need to search in the schematic and on the header connect together PA0 and PC13. After that, you can read the state of the button also with the ADC. Then this is all for my pinout. I don't need to set anything else. In the clock configuration, I am again okay with 16 MHz. It's not a problem for me. But here in the configuration at least I need to configure the ADC. Then you can look on the configuration and first we start with the parameters. The clock source and the press scalar, I am okay with the default settings, which telling me that the clock source, which is the APB2, will be divided by 2. Which is the main frequency for the ADC. In my case, because I have the 16 MHz on the APB2, then the frequency of the ADC, which I will be used on the oldest parameters, will be 8 MHz. The resolution, I am okay with the 12 bits. In case that you want to sample faster or you don't want to show precise values, you can decrease the number of bits. And I am okay with right that alignment. The scan mode is disabled because I have only one channel. Then I don't need to use the scan mode. Scan mode will be used only in case that you have multiple channels, which you want to read in the 1-1 shot. The continuous conversion means that the ADC automatically converts again and again all the sequence or one channel. For this moment, I will use the not continuous mode. I want to convert my variable only once. This continuous mode is also not used. It means that on each tagger of the ADC, I can convert some specified number of channels. And I am not using the DMAID and this does not make sense for me. End of the conversion selection is here if the end of conversion flag is okay for me. Here in the conversion mode, you can see I have only one channel, which is okay because I set only one. I am not using any external tagger like the timer or the external pane. If you want to tagger ADC on pane or on the timer, you can use this setting. But in my case, it's okay without the tagger. In the channel settings, I can set the sampling time. For my purpose, it doesn't matter because I don't require any precise sampling. Then I will set you, for example, 48, why not? The rest can be left unchanged. But definitely what I need to change is here my NVIC. In my NVIC, I need at least to enable the interrupt because we want to be notified from the end of conversion with the interrupt. And I can check here the GPLs. You can see my GPL is in the analog mode. Then everything is set properly. I can click on OK. And I can save my project. Then I can save it in my Atolic repository because I will use now the studio from Atolic. And I need to name my project and I name it like the ADC with interrupt. For example, this is everything from my project setting. I can click on the OK and we can generate the project. I click on generate. It seems no errors. And I can open my project in Atolic. OK, my project is here, which is good. And we can look in our main. Like usually in our previous examples, we have here the ADC handle like for the USART or SPI. It's still the same. I have here the ADC initialization. If we look inside the initialization, we can see again we're choosing the instance, the initial parameters. And we're calling the ADC in it. And we can see there is the additional initialization because the ADC can have multiple input channels. And all these channels can be configured separately. Then for this, we have the separate configuration API for each channel. And now we can start our ADC. How to do it? Like before, we're starting with the keyword of the library, which is the HL underscore. The name of the pay ferry, which is the ADC. You can see there is also ADCX, which means some extending functionalities, which we add on this device. But I don't want this extended one. And the usually asynchronous pay ferry, like the timer, ADC and others. Starting with the keyword start. Then we search for the start. You can see I have the three starts, the standard software start. The start with the DMA and start with the interrupt. In my case, I will use the start with the interrupt. In case that you want to use the software start without IT, then if you want to detect where is the end of your conversion, you need to use the function HL underscore ADC underscore pool for conversion to detect if the IDC finished the conversion. Okay, but we need to fill this function and only one parameter which we need to add is the handle. Then we put the end symbol H ADC and we put here our handle. Okay, this will start our ADC. And now because we're using the interrupt, we need to define our callback. Like before, our callback is in the drivers source, we're using the ADC. And best way how to search for the callback is search the underscore underscore week. We search the MSP init. This is not what we want the MSP init. And here we have the HL ADC conversion complete callback. This is precisely what I want. I copy this function and I put it here inside my main. Okay, now what to put here after we go inside this function, this means that our conversion which we started here has finished. And now we need to read the values from the ADC manually. Then for this we use the HL, again the ADC. The last keyword will be get. Sorry, get. And it will be get value. Then I can get the value. And the last parameter is the handle. We can use the handle from this local structure or we can use the global handle from here. It depends on you, but I think here the local one is more appropriate. Okay, and we are reading the value and I forget almost to store this value because the value return parameter, return value is the return parameter. Then I need to store it somewhere. Then for this I define here the variable. Because we have 12-bit ADC, I will use the 16-bit variable. And it will be my ADC value. I put it here. And this will store my ADC value into my variable. Now, because we are not using the continuous mode, then after this callback the ADC will stop. To run it again, we need to start it. Then we put here the HL ADC again start. Again start with the interrupt. I can use here the local handle because this is my ADC, which I want. And this will start the conversion again. Without this, the conversion run only once. Don't forget on this, please. Now I can save my project. And we can test our ADC now. I can simply compile my code. It seems no problems. And I can run my debug. My code is here. We are in the debugger. And now if we want to run our code here, we press the F8 or this button with the arrow. And I run it. Now how to detect if my code is working. I can put here the breakpoint into my callback. Okay, we put here our breakpoint. Try it again and again. And how to check the value. I can here mark the value. And here with the right click add this value into my variables. I can delete this previous one. You can see here I can see my value. If I press the F8, it is surfaced. If I press now my button on my board because it's connected together with the PA0 and I run it again. You can see the button drag the value low. This is reading the low values. If I release my button, I go up. Okay, now my ADC is working. But reading the analog values like this is not so nice. It will be good for us to a little bit visualize the value or see it in the real time. Then for this we can use the tool called the STM Studio which can periodically read the data from the memory of the microcontroller and display them for us. Then we can open the STM Studio. Okay, in case that you running the STM Studio first time he can ask you to select the java.w.exe. In case that you don't know where this executable file is it will be in your C. I will show you. It will be on C, disk C. Here in the program files in Java. Here is the Java runtime environment and version which I have. And in binary and here will be the java.w.exe which is here. Then you need to mark for him this file. And then after you run it again and again he never asks about this again. Okay, we open the STM Studio. First what we need to select is the debugging interface because the STM Studio using the stealing to access the internal memory of the microcontroller. This means the STM Studio is not inclusive in this case. Then I have the stealing and SWD interface. Then what to do next? We want to check the content of our memory. Then we can here for example add the variable but we need to set the address of this variable manually and also the data type and the name which is not so nice because sometimes the compiler changes from for us the position and we cannot be sure where the variable is and we need to search in the in the map file and we not use this approach but here in the file we will use the import. We can import all the variables from our executable file. Then first we need to set the executable file. In the Atolic the executable file is the ELF. In IR it's OUT and in KEL is the AXF file. Then I will search for my executable. I will go to trainings, my cube training, my projects and here I will go to my Atolic and inside my ADC and it will be here in the Debug folder and here you can see it's my executable. Then I select this executable and here he found all my variables which I'm using in my project and here I can found my ADC value also with the proper address. I will import this variable. Click on the close. You can see he import the name, the correct address and also the data type. Then it's okay. Now if I want to display this variable in here in my viewer I need to mark it, right click on the variable and here use the send to via viewer which will send the variable here and it will be also visible then in my viewer. The last thing which I need to do is here set the correct range. Because I have the Telef bit ADC then my maximum value can be 4096 which I have to set here. Okay, then after that everything is okay and I can here run my STM studio and see my values. If I run it, I get the error. Why? Because in parallel the STM studio is using the stealing and in case that somebody else using the stealing like my debugger that it will not run then first of all I need to shut down my debugging session here. I shut down my debugging session. Okay, and now I can try to run my STM studio and now it's running. In case that I press the button you can see the value is changing in case that I toggle more. Let's try to refresh the values all the time. Okay, if you want you can change also the visualization to the bar graph or only see the values. Then this is how you can use the STM studio to see the content of your memory which will be refreshed. The refresh rate is done by the number of the values which the stealing need to watch because the stealing bandwidth is limited then if you put here more variables the refresh rate will be a little lower. But at least it's still a very nice tool if in case that you want to see all content inside. Your memory of the maker counter if you want to see the trend how it's changing and it will be very nice tool. Definitely for our case is very useful because we can see that our ADC is working. Okay, this is all from this example and we can move to the next hands-on which will be ADC with TMA.