AnsweredAssumed Answered

Re-assigning a pin using the Switch Matrix

Question asked by James Smith on May 20, 2019
Latest reply on May 21, 2019 by James Smith

Hi,

 

What's the best practice for re-assigning a pin via the switch matrix on the LPC802 after it has already been assigned?  For instance, if I have already assigned PIO0_8 and PIO0_9 to be the TX and RX lines for UART0 and now want to make them the SDA and SCL lines for a I2C connection, would the code look like this?

 

 // Enable the switch matrix
 SYSCON->SYSAHBCLKCTRL0 |= (SYSCON_SYSAHBCLKCTRL0_SWM_MASK);
 
 // Remove the Switch Matrix's connections to the UART
 // Clear bits 15:0 in PINASSIGN0
 SWM0->PINASSIGN0 &= ~(SWM_PINASSIGN0_U0_TXD_O_MASK | SWM_PINASSIGN0_U0_RXD_I_MASK);
 
 // USART0 is now disconnected.
  
 // Clear bits 15:0 in PINASSIGN5
 SWM0->PINASSIGN5 &= ~(SWM_PINASSIGN5_I2C0_SDA_IO_MASK | SWM_PINASSIGN5_I2C0_SCL_IO_MASK);
 
 // Assign SCL and SDA to PINASSIGN5 bits 15:0
 // SCL is PIO0_8, so put 4 into bits 7:0
 // SDA is PIO0_9, so put 0 into bits 15:8
 SWM0->PINASSIGN5 |= ( (0x8UL<<SWM_PINASSIGN5_I2C0_SCL_IO_SHIFT) |       // SCL is PIO0_8
        (0x9UL<<SWM_PINASSIGN5_I2C0_SDA_IO_SHIFT));                                          // SDA is PIO0_9
 // I2C is now connected.
 // disable the switch matrix
 SYSCON->SYSAHBCLKCTRL0 &= ~(SYSCON_SYSAHBCLKCTRL0_SWM_MASK);
 // ---------------- End of Switch Matrix code -----------------------------------
My concern is that by clearing the values in PINASSIGN0, am I just assigning the UART0 TX and RX lines to PIO0_0?  (the 0th pin in the GPIO)
thanks!
James

Outcomes