Accessing of GPIO pins of MCU
I have a doubt if the GPIO pins in a MINI2440 accessed programatically. The board is loaded with Android or Linux. can any help me ?
The GPIO pins can be accesed either using Bitwise operation on that whole register or by using enum, struct(Bit fields) etc. together.
Actually the MCU pins are assigned to some specific registers (refer the Datasheet of that particular controller) and this registers are usually having a particular adderss something like REG = 0x12345678h
Eg. It can be re-used for any register:
typedef union // Generic 8-bit register Type
{
uint8 reg; // whole register
struct
{
unsigned bit7 : 1; // Bit 7
unsigned bit6 : 1; // Bit 6
unsigned bit5 : 1; // Bit 5
unsigned bit4 : 1; // Bit 4
unsigned bit3 : 1; // Bit 3
unsigned bit2 : 1; // Bit 2
unsigned bit1 : 1; // Bit 1
unsigned bit0 : 1; // Bit 0
} bit;
} GPIO_REG8; // Give the name using typedef
So, now to define a port we want to address:
#define MCU_GPIO_PORTx (*(volatile GPIO_REG8 *)(0x12345678)) // here Number is the address
And to directly twiddle a pin on that port:
#define MCU_PORTx_PINn (MCU_GPIO_PORTx.bit.bit0)
In the code you can use:
MCU_PORTx_PINn = 1; // Set pin high
Entire register:
MCU_GPIO_PORTx.reg = 0xF; // All pins high