AnsweredAssumed Answered

LPC1347 accessing GPIO registers via halfword

Question asked by Mateusz Kiełbasa on Sep 22, 2017
Latest reply on Sep 24, 2017 by jeremyzhou

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;

Outcomes