LPC1347 accessing GPIO registers via halfword

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1347 accessing GPIO registers via halfword

1,311 Views
mateuszkiełbasa
Contributor III

I am reading lpc1347 user manual. I have read two sentences which I don't understand.

GPIO port adresses can be read and written as bytes, halfwords, or words.

And GPIO port WORD register description

Each GPIO pin has a word register in this address range. Any byte, halfword, or word read in this range will be all zeros if the pin is low or all ones if the pin is high[...]

My question is how to read GPIO registers as bytes or halfword. LPCOpen uses byte access for B register and word access for others.

typedef struct { /*!< GPIO_PORT Structure */
__IO uint8_t B[128][32]; /*!< Offset 0x0000: Byte pin registers ports 0 to n; pins PIOn_0 to PIOn_31 */
__IO uint32_t W[32][32]; /*!< Offset 0x1000: Word pin registers port 0 to n */
__IO uint32_t DIR[32]; /*!< Offset 0x2000: Direction registers port n */
__IO uint32_t MASK[32]; /*!< Offset 0x2080: Mask register port n */
__IO uint32_t PIN[32]; /*!< Offset 0x2100: Portpin register port n */
__IO uint32_t MPIN[32]; /*!< Offset 0x2180: Masked port register port n */
__IO uint32_t SET[32]; /*!< Offset 0x2200: Write: Set register for port n Read: output bits for port n */
__O uint32_t CLR[32]; /*!< Offset 0x2280: Clear port n */
__O uint32_t NOT[32]; /*!< Offset 0x2300: Toggle port n */
} LPC_GPIO_T;

Should I make an own pointer to particular register address and use it as byte or halfword like this?

volatile uint8_t *pointer = (volatile uint8_t *)  REGISTER_ADDRESS;

Labels (1)
0 Kudos
Reply
1 Reply

1,038 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Mateusz Kie&#322;basa

Thank you for your interest in NXP Semiconductor products and 
for the opportunity to serve you.
The MCU supports two kinds way of writing and reading the Pin registers, as the Fig 1 shows.
You needn't make an own pointer to particular register address
pastedImage_2.png
Have a great day,

TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply