Microcontroller Embedded C Programming lecture 133| IO pin read exercise

  • Post author:
  • Post category:Blog

 

 

IO pin read exercise

 

Exercise:

  • Write a program which reads the status of the pin PA0. If the status of PA0 is LOW, then turn off the onboard LED(PD12) and if the status of the PA0 is HIGH, then turn on the LED. 
  • Change the status of PA0 pin manually by connecting between GND and VDD points of the board.

The GND point of the board is 0v and the VDD point of the board gives you 3.3v. 

 

When the PA0 is connected to the VDD point, so when you read the PA0 pin then you should read HIGH or digitally it is 1. When you observe a PA0 HIGH, then you should turn on the LED, otherwise, you turn off the LED.

And as I said you have to change the status of the PA0 manually by taking one jumper wire.

Figure 1. The connection between PA0 to GND point
Figure 1. The connection between PA0 to GND point

 

Take one connector wire, and connect PA0 to the GND point.  

If you do this, then the LED should turn off.

 

If you connect PA0 to the VDD point, then the program should turn on the LED. So, try to implement this exercise.

IO pin read exercise
Figure 2. The Connection between PA0 to VDD

 

Before doing this exercise let me clear some points.

First of all, you have to check whether PA0 is a free I/O or not.

For example, on the discovery board, PA0 is a free I/O you can use that, but if you are using some other board then PA0 may not be available on the board. 

So, you have to explore the user manual of the board to understand the status of PA0, whether it is free or is used by some other functionality of the board circuit. 

And after that on the discovery board, the onboard LED is PD12; so if your onboard LED is connected to some other pin, then you have to handle that.

First, go to the user manual of the board STM32F4 discovery. In section 6.11 Extension connectors, here I check the stm32 pin description versus board functions table, as shown in Figure 3. 

And the status of the PA0 can see in the column free I/O. It is mentioned as  PA0, which means it is available as a free I/O pin. So, you can use that for your I/O functionality, which is general purpose I/O functionality.

 

If the Free I/O place is blank for a pin, suppose, let’s consider PA4, here it is mentioned that PA4 is not available as a free I/O. So, here it is blank. In that case, you cannot use a PA4 pin for general purpose I/O functionality. So, we can definitely use PA0, no issues with that. 

IO pin read exercise
Figure 3. STM32 pin description versus board functions

 

Some hints 

  • PA0 should be in input mode. (Because you are reading from that pin)
  • To read from pin PA0, your code has to read PORT-A input data register.

Try to code by using these hints and I’ll solve this exercise in the following article.

 

FastBit Embedded Brain Academy Courses,

Click here: https://fastbitlab.com/course1

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.