This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RS485

Hello, I am working in mdk5. For my application I am writting code for RS485. While debugging I found that my FCR register is not loading its value. The code I have written is show below.
void uart_rs485(void)
{ SCU_PinConfigure(2,3, SCU_CFG_MODE_FUNC2);// p2_3 for U3_TXD SCU_PinConfigure(2,4, SCU_CFG_MODE_FUNC2);// p2_4 for U3_RXD GPIO_SetDir(4,11,GPIO_DIR_OUTPUT);// Set GIO_B1_RS485_DIR as output

LPC_USART3->LCR = 0x83;// Line Control Register LPC_USART3->FCR =0x07;//FIFO buffer LPC_USART3->FDR =0;// Fractional Divide LPC_USART3->DLM =0;//Divide Latch MSB LPC_USART3->DLL =98;//Divide Latch LSB LPC_USART3->LCR =0x03;//Disable DLAB

}
void uart_rs485_transmit(void)
{ GPIO_PinWrite(4,11,1);//Making Transmit Enable high if(LPC_USART3->LSR & 0x20) { LPC_USART3->THR = 83; }
}

void uart_rs485_receive(void)
{ GPIO_PinWrite(4,11,0);//Receive Enable a = LPC_USART3->RBR;
} Please help me in this flow. Thank you in advance

Parents
  • Hi all, While dealing with UART1 of LPC1857 to be used as RS232 I have coded as below.
    For providing clock:

    void SCI_PortClock (uint32_t clock) {
      if (clock) {
        LPC_CCU1->CLK_M3_UART1_CFG |= 3;
        while (!(LPC_CCU1->CLK_M3_UART1_STAT & 1));
      }
      else {
        LPC_CCU1->CLK_M3_UART1_CFG   &= ~(3);
        while (LPC_CCU1->CLK_M3_UART1_STAT & 1);
      }
    }
    


    Pin configuration and UART configuration:

    RS232 PINS
    U1_TXD = P3_4
    U1_RXD = P3_5
    */
    const PIN_ID RS232_PIN[] = {
      { RTE_UART1_RX_PORT, RTE_UART1_RX_BIT, (RTE_UART1_RX_FUNC | SCU_SFS_EZI)},
      { RTE_UART1_TX_PORT, RTE_UART1_TX_BIT, (RTE_UART1_TX_FUNC)}
    };
    
    
    void uart_sci(void)
    {
            const PIN_ID *pin;
            SCI_PortClock (1);
            for (pin = RS232_PIN; pin != &RS232_PIN[sizeof(RS232_PIN)/sizeof(PIN_ID)]; pin++) {
        if (pin->port == 0x10) {
          SCU_CLK_PinConfigure (pin->num, pin->config_val);
          continue;
        }
        SCU_PinConfigure(pin->port, pin->num, pin->config_val);
      }
    
            LPC_UART1->LCR = 0x83;     //Line Control Register
            LPC_UART1->FDR = 0;        //Fractional Divide
            LPC_UART1->DLM = 0;        //Divide Latch MSB
            LPC_UART1->DLL = 98;       //Divide Latch LSB
            LPC_UART1->LCR = 0x03;     //Disable DLAB
            LPC_UART1->FCR = 0x07;     //FIFO buffer
    }
    void uart_sci_transmit(void)
    {
    
            if(LPC_UART1->LSR & 0x20)
            {
                    LPC_UART1->THR = 83;
            }
    }
    
    void uart_sci_receive(void)
    {
    
            a = LPC_UART1->RBR;
    }
    


    While debugging, I came to know that FCR, DLL, DLM are not configured as I have given.
    Transmission and reception is unsuccessful. LCR is loaded properly. Inviting your valuable suggestions. I am using Keil MDK5.

Reply
  • Hi all, While dealing with UART1 of LPC1857 to be used as RS232 I have coded as below.
    For providing clock:

    void SCI_PortClock (uint32_t clock) {
      if (clock) {
        LPC_CCU1->CLK_M3_UART1_CFG |= 3;
        while (!(LPC_CCU1->CLK_M3_UART1_STAT & 1));
      }
      else {
        LPC_CCU1->CLK_M3_UART1_CFG   &= ~(3);
        while (LPC_CCU1->CLK_M3_UART1_STAT & 1);
      }
    }
    


    Pin configuration and UART configuration:

    RS232 PINS
    U1_TXD = P3_4
    U1_RXD = P3_5
    */
    const PIN_ID RS232_PIN[] = {
      { RTE_UART1_RX_PORT, RTE_UART1_RX_BIT, (RTE_UART1_RX_FUNC | SCU_SFS_EZI)},
      { RTE_UART1_TX_PORT, RTE_UART1_TX_BIT, (RTE_UART1_TX_FUNC)}
    };
    
    
    void uart_sci(void)
    {
            const PIN_ID *pin;
            SCI_PortClock (1);
            for (pin = RS232_PIN; pin != &RS232_PIN[sizeof(RS232_PIN)/sizeof(PIN_ID)]; pin++) {
        if (pin->port == 0x10) {
          SCU_CLK_PinConfigure (pin->num, pin->config_val);
          continue;
        }
        SCU_PinConfigure(pin->port, pin->num, pin->config_val);
      }
    
            LPC_UART1->LCR = 0x83;     //Line Control Register
            LPC_UART1->FDR = 0;        //Fractional Divide
            LPC_UART1->DLM = 0;        //Divide Latch MSB
            LPC_UART1->DLL = 98;       //Divide Latch LSB
            LPC_UART1->LCR = 0x03;     //Disable DLAB
            LPC_UART1->FCR = 0x07;     //FIFO buffer
    }
    void uart_sci_transmit(void)
    {
    
            if(LPC_UART1->LSR & 0x20)
            {
                    LPC_UART1->THR = 83;
            }
    }
    
    void uart_sci_receive(void)
    {
    
            a = LPC_UART1->RBR;
    }
    


    While debugging, I came to know that FCR, DLL, DLM are not configured as I have given.
    Transmission and reception is unsuccessful. LCR is loaded properly. Inviting your valuable suggestions. I am using Keil MDK5.

Children
No data