Memory-mapped I/O example

Since MSP432 uses memory-mapped I/O, all interactions with all the registers in all the peripherals amounts to load and store operations, which are the two instructions used for reading from memory and writing to it. Holding the Ctrl key while clicking on any of the register macros such as P1DIR in the CCS project, opens up a header file that shows the addresses for all these registers. The screenshot below shows these addresses.

In addition to the driverlib method, it is possible to find the address of each register using the microcontroller manual and datasheet. For example, the address for P1DIR is the sum of various numbers that can be looked up from the datasheets.

P1DIR = PORT_MODULE_BASE + PxDIR = 0x40004C00 + 0x04 = 0x40004C04

The above numbers are all extracted from the manuals as seen in the series of images below. In the first image, we can find that port addresses start at 0x4000_4C00. These addresses are specific to MSP432P401R and MSP432P401M, and not the rest of MSP432 family. Therefore, you can find this information in the datasheet document.

Chapter 12 of the MCU technical manual is dedicated to digital i/o. However, it specfically mentions that for the base address of the port module, one has to refer to the datasheet. (See below)

As for the registers within the port, the offset addresses can be found both in the technical manual and in datasheet. The below image is from the technical manual which is shared between all members of MSP432 family.

Once the addresses are known, the rest of operations are reading from or writing to these addresses. For example, when we want to program P1DIR such that its Pin 1 becomes an output that can drive LED1, in C we write

P1DIR = P1DIR | LED1; // LED1 is a macro as 0x1

In psuedo-assmebly, the above code is written as follows:

EQU LED1 0x0001  (symbol LED1 = 0x0001) 

MOV &P1DIR, r0   (move contents of  memory address P1DIR to register 0)

OR LED1, r0      (register 0 <- register 0 OR 0x0001)

MOV r0, &P1DIR   (move contents of register 0 to memory address P1DIR)