General purpose ports in ARM MCU

Microcontrollers aren't imaginable without ability to interact with other devices like indicators, input devices or other off-chip devices. For this every MCU have I/O pins that are used to interact with external world.

General purpose I/O ports can be accessed via registers who provide enhanced features or simply via port registers. Port registers are allocated to the ARM bus so that fasted possible timing can be achieved. Control of individual bits is possible using single instruction. All port registers are byte and half word addressable. After MCU reset all I/O ports are set to input.

Lets take LPC2000 series ARM microcontroller LPC2148. It has two 32 bit general purpose I/O ports PORT0 and PORT1. PORT0 has 30 pins for input/output operations where one is only for output. PORT1 has 16 available pins for GPIO.

Each GPIO pins is controlled by four registers:

  • IOPIN – port pin value. Depending on pin direction settings the value from this register can be read;

  • IOSET – Writing “1” to this register sets port value to high state while writing 0 hasno effect. This register works in conjunction with IOCLR;

  • IOCLR – This register is opposite to IOSET. Writing “1” value to it will set port pin to low state. Writing zero will have no effect;

  • IODIR – this register controls direction of each port pin. If bit is is et “1” pin will be as output and if bit “0” then pin wil be set to input. After reset all pins are set to input.

Bellow is a simplified routine of simple Led flasher.


.....
#define IOPINS016 0x10000 	//16th pin
int main(void)
{
sysInit();	//system init routine: PLL, MAM- not discussed here
IO0CLR = (1<<IOPINS016);	// clear 16th pin output
IO0SET = (1<<IOPINS016);		// set the ONE to 16th pin
IO0DIR =(1<<IOPINS016);		// set the output bit direction
	for (;;)
	{
		IO0CLR = (1<<IOPINS016);	// 16th pin Low output
		_delay(900000);			//delay
		IO0SET = (1<<IOPINS016);		// 16th pin high
		_delay(900000);
	}
	return 0;
}

Comments

Comment: 
Hello.I'd like to thank you for your good tutorial. I have a problem about GPIOs in KEIL UVISION .when I write a simple program which just contains a "main method", all or some of pins of GPIOs are in high state. for example what is shown in debugger: FIO3DIR=0X0; FIO3SET= 0X0; FIO3CLR=0X0; FIO3SPIN=0x078000FF; I don't know why. Thank you.

Add new comment

Who's online

There are currently 0 users online.