Developing the ADC driver
In this section, we will apply everything we have learned about the ADC peripheral to develop a driver for reading sensor values from a sensor connected to one of the ADC channels.
Identifying the GPIO pins for the ADC
Let’s begin by identifying the GPIO pins connected to the ADC channels. To do this, refer to the table on page 39 of the STM32F411RE datasheet. This table lists all the GPIO pins of the microcontroller, along with their descriptions and additional functionalities. As shown in Figure 11.4, part of this table reveals that PA1 has an additional function labeled as ADC1_IN1
. This indicates that PA1 is connected to ADC1, channel 1:
Figure 11.4: Pin definitions
Let’s configure PA1 so that it functions as an ADC pin.
First, create a copy of your previous project in your IDE, following the steps outlined in earlier chapters. Rename this copied project to ADC
. Next, create a new file named adc.c
in...