UART on I2C pins

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

UART on I2C pins

1,083 Views
sanders7284
Contributor III

Hello, is it possible to use a UART on the I2C pins?

I have tried the following but the functionality seems to be intermittent.

void UART_INIT(void) //---------------------------------------------------------
{

//Connect the U0_TXD_O and not used U0_RXD_I signals to port pins(P0.10, not used P0.11)
  Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); // Enable SWM clock before altering SWM
  Chip_SWM_DisableFixedPin(SWM_FIXED_I2C0_SDA);
  Chip_SWM_DisableFixedPin(SWM_FIXED_I2C0_SCL);
  Chip_SWM_MovablePinAssign(SWM_U0_TXD_O, 10);
  Chip_SWM_MovablePinAssign(SWM_U0_RXD_I, 11);
  Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); // Disable SWM clock after altering SWM
 
  Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_UART0);
  Chip_UART_Init(LPC_USART0);
  Chip_UART_ConfigData(LPC_USART0, UART_CFG_ENABLE | UART_CFG_DATALEN_8 | UART_CFG_PARITY_NONE |                                              UART_CFG_STOPLEN_1);
  Chip_Clock_SetUSARTNBaseClockRate((BAUD_RATE * 16), true);
  Chip_UART_SetBaud(LPC_USART0, BAUD_RATE);
  Chip_UART_Enable(LPC_USART0);
 
  Chip_UART_IntEnable(LPC_USART0, UART_INTEN_RXRDY);
  Chip_UART_IntDisable(LPC_USART0, UART_INTEN_TXRDY);    /* May not be needed */
  NVIC_EnableIRQ(UART0_IRQn);
}
//------------------------------------------------------------------------------

// UART0_IRQ -------------------------------------------------------------------
void UART0_IRQHandler(void)
{

   NVIC_ClearPendingIRQ(UART0_IRQn);
    Rx_State[s] = Chip_UART_ReadByte(LPC_USART0);   
    
    if (Rx_State[s] != Last_Rx_State)
    {
    
    switch (Rx_State[s])
    {
    case 1: //Normal
      New_Event(1);
      break;
      
    case 2: //off
    case 3: //off
    case 4: /off
      New_Event(2);
      break;
      
    case 5: //Fault
      New_Event(3);
      break;
        
    case 6: //test 1
      New_Event(4);
      break;
      
    case 7: //test 2
      New_Event(5);
      break;
        
    case 8: //learn
      break;
    }
    
    }
    
    Last_Rx_State =  Rx_State[s];
    s ++;
    
    if (s >= 16)
    {
      s = 0;
    }
}

Labels (2)
4 Replies

840 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Paul,

Could you please provide more information. Which LPC are you using? Are you using an evaluation board? The pins you are using are P0_10 and P0_11, right? 

Regards,

Victor.

0 Kudos

840 Views
sanders7284
Contributor III

Thanks Victor,

The uC is a LPC824,

I am using p0_10 & p0_11,

The PCB is custom but basically each line has an external pull up and an connection to a header pin.

Regards Paul

0 Kudos

840 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Paul,

I used an example of the CodeBundle for the LPC824 (Example_UART0_Terminal) At first the example uses the P0_0 and P0_4 for the UART0, I made the changes to use P0_10 and P0_11 and I connected these two pins to an external pull up of 4.7K. The example worked as expected even with the pin change. I also tried with different baudrates (2400, 9600 and 115200) and everything went well. 

You can use this example as a guide to see how configurations are made and see if you are missing something. The example is really good commented so it easy to understand how it works.

The changes I made in the example project are the next ones.

First I activate the desired pins:

  // Connect UART0 TXD, RXD signals to port pins
  ConfigSWM(U0_TXD, P0_10);       // Use with USB-to-RS232 break-out cable (see jpeg)
  ConfigSWM(U0_RXD, P0_11);       // Use with USB-to-RS232 break-out cable (see jpeg)
  //ConfigSWM(U0_TXD, TARGET_TX);  // For MBED serial port (requires board mod.)
  //ConfigSWM(U0_RXD, TARGET_RX);  // For MBED serial port (requires board mod.)

Then I change the baudrate in the following line:

  // Configure the USART0 baud rate generator
  LPC_USART0->BRG = 781;

I obtain the value of BRG (depending on the desire baudrate) of the next equation:

  // BRG = ((MainClock Hz.) / (2 * 16 * baudrate Hz.)) - 1
  //     = (60,000,000/(2 * 16 * 115200)) - 1

Please let me know if you have more questions or doubts!

Victor.

 

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

0 Kudos

840 Views
sanders7284
Contributor III

Thanks Victor,

The problem seems to be with my pull up resistors.

I had 1k fitted given the I2C application, I changed these to 47k so it matched everything above and the code I already had jumped into life.

Regards Paul