Part Number: MSP432P401R
Hello, I am working on my MSP432P401R Launchpad (red board). I am trying to turn on the LED lights on pins 1.0, 2.0, 2.1, 2.2., Basically the LED1 and LED2 (RGB). I am encountering some issues and hope that someone can help me understand certain concepts.
Issue 1) I initialize P1DIR as #237 (pin 1.1 and pin 1.4 are input pins everything else is output) and P1REN and P1OUT as #0x12 (activate pull up resistors on both buttons pin 1.1, pin 1.4). But when I try to read from the P1IN I keep getting 0x00000012. Why are my input pins reading highs when the buttons are not being pressed. In my code below I am doing an exclusive or to fix it but this doesn't seem right to me.
Thank you
.cdecls C, LIST, "msp432p401r.h" .text .global main main: bl init_port_1 ; Branch to the function called init_port_1 bl init_port_2 ; Branch to the function called init_port_2 mov R3, #0x4c02 ; Move lower 16 bits of address (Port 1 movt R3, #0x4000 ; Move upper 16 bits of address Output mov R1, #0x4c00 ; Move lower 16 bits of address (Port 1 movt R1, #0x4000 ; Move upper 16 bits of address Input) mov R2, #0x4c03 ; Move lower 16 bits of address (Port 2 movt R2, #0x4000 ; Move upper 16 bits of address Output) b loop ; Branch to loop function ; This function will initialize port 1 init_port_1: mov R0, #0x4c04 ; Move lower 16 bits of address (Port 1 movt R0, #0x4000 ; Move upper 16 bits of address Direction) mov R1, #0x4c06 ; Move lower 16 bits of address (Port 1 movt R1, #0x4000 ; Move upper 16 bit of address REN) mov R2, #0x4c02 ; Move lower 16 bits of address (Port 1 movt R2, #0x4000 ; Move upper 16 bits of address Output) mov R5, #0x4c0A ; Move lower 16 bits of address (Port 1 movt R5, #0x4000 ; Move upper 16 bits of address SEL0) mov R6, #0x4c0C ; Move lower 16 bits of address (Port 1 movt R6, #0x4000 ; Move upper 16 bits of address SEL0) mov R3, #237 ; Move 237 bit into register 3 for later use mov R4, #18 ; Move 18 bits into register 4 for later use strb R3, [R0] ; Store 1 bit into Port 1 Direction address strb R4, [R1] ; Store 18 bits into Port 1 REN address (pin 1.1 and 1.4) strb R4, [R2] ; Store 18 bits into Port 1 Output address to enable the pull up bx lr ; Return back from where this function was called from ; This function will initialie port 2 init_port_2: mov R1, #0x4c05 ; Move lower 16 bits of address ( Port 2 movt R1, #0x4000 ; Move upper 16 bits of address Direction) mov R2, #0x4c03 ; Move lower 16 bits of address (Port 2 movt R2, #0x4000 ; Move upper 16 bits of address Output) mov R0, #0x07 ; Move seven bits into register 2 strb R0, [R1] ; Store 7 bits into Port 2 Direction address pins 2.0 2.1 2.2 mov R0, #0 ; Move 0 bits into register 0 strb R0, [R2] ; Store 0 bits into all Port2 pins, all pins low bx lr ; ; The below function will run continuously searching for a button pressed loop: ldrb R0, [R1] ; Load value from register 1 into register 0, this is reading from port 1 eor R0, #18 ; This is to fix the input pins there not working as expected cmp R0, #2 ; If register 0 is equal to #2 then pin 1.1 is being pressed aka left button it eq bleq button1 ; branch to button1 function if equal cmp R0, #16 ; If register 0 is equal to #2 then pin 1.4 is being pressed aka right button it eq bleq button2 ; Branch to button2 function if equal cmp R0, #18 ; If register 0 is equal to #18 then pin 4 and pin 1 are pressed aka both buttons it eq bleq both_buttons ; Branch to both_buttons function if equal b loop ; Branch to the loop function, this is an infinite loop ; The below function check will turn on red LED and green one button1: mov R7, #1 mov R8, #2 strb R7, [R3] ; Store 1 bit into Port 1 Output address located in register 3 strb R8, [R2] ; Store 1 bit into Port 2 LED2 (RGB) bx lr ; Return back from where this function was called from ; The below function will turn on the green LED button2: mov R7, #1 mov R8, #4 strb R7, [R3] strb R8, [R2] ; Store 2 bits into Port 2 Direction address located in register 0 bx lr ; Return back from where this function was called from ; This below function will turn on the blue LED both_buttons: mov R7, #7 ; mov R8, #1 ; strb R8, [R3] ; strb R7, [R2] ; Store 4 bits into Port 2 Direction address located in register 0 bx lr ; Return back from where this function was called from