RS485 using LPC1857

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

RS485 using LPC1857

1,216 Views
nelvijohn
Contributor I

Hi all,

I am a beginner to MDK5 from Keil. This is the first time I am working on LPC1857. I have created a web page using the HTTP server sample code from Keil. Now I want to receive values using RS485. So, I am using Uart3 of my LPC1857 for this purpose. The code I have written is given below.

void uart_rs485(void) { SCU_PinConfigure(2,3, SCU_CFG_MODE_FUNC2); SCU_PinConfigure(2,4, SCU_CFG_MODE_FUNC2); GPIO_SetDir(4,11,GPIO_DIR_OUTPUT); LPC_USART3->LCR = 0x83; LPC_USART3->FCR =0x07; LPC_USART3->FDR =0; LPC_USART3->DLM =0; LPC_USART3->DLL =98; LPC_USART3->LCR =0x03;  } 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; }

While debugging I came to know that FCR is not loading its value. What might be the reason. Besides, is it require to provide power to the uart unit? Is there any sample code for that? Please help me in this flow.

Labels (1)
0 Kudos
9 Replies

797 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi NELVI JOHN,

   Of course, you need to power on the UART3 module.

pastedImage_1.png

This is the basic configuration.

But about the 485 code for LPC1857, I don't have the direct project now, you can refer to this post for LPX1765.

https://community.nxp.com/message/770119?commentID=770119#comment-770119 

Please refer to the 485 code to configuration your LPC1857 at first.

If you still have question, just let me know!


Have a great day,
Kerry

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

0 Kudos

797 Views
nelvijohn
Contributor I

Hi Kerry,

   Thank you for your response. I have read the power and clocking information in the user manual. But I dont know how to learnt it and provide the clock using the IDE MDK5. Could you help me in this. I dont even understand what is the default value of PCLK. Let me know about how to learnt the user manual for getting the required clock.

0 Kudos

797 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi NELVI JOHN,

    Please download the MCB1857 lpcopen code from this link:

http://www.nxp.com/assets/downloads/data/en/software/lpcopen_2_20_keil_iar_keil_mcb_1857.zip 

  Then open periph_examples in folder:lpcopen_2_20_keil_iar_keil_mcb_1857\applications\lpc18xx_43xx\keil\keil_mcb_1857

  You will can find the uart initialization code in uart_18xx_43xx.c.

pastedImage_2.png

   About the clock, you can debug it to get it, this is also one way to learn it.

Wish it helps you!


Have a great day,
Kerry

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

0 Kudos

797 Views
nelvijohn
Contributor I

Hi Kerry,

 Let me know about the the PCLK value at which the UART of LPc1857 is working? I am using Keil MDK5. Is there any window available during debugging to know the available clocks like PCLK and their values loaded? How we can know the activated Baud rate corresponding to the DLL and DLM loaded by us in MDK5?

0 Kudos

797 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi NELVI JOHN,

   Please check this MDK IDE debug result:

pastedImage_1.png


Have a great day,
Kerry

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

0 Kudos

797 Views
nelvijohn
Contributor I

Hi Kerry,

    I have configured clock to USART3 by software. the code is as below:

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);   } }

I haven't configured PCLK separately. So, is it there is any fault in being the conclusion that the PCLK is default 12MHz.

0 Kudos

797 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi NELVI JOHN,

    If you don't configure it, just enable the UART3 clock to RUN, yes, the default clock is IRC12MHZ.

   You can find it from these pictures:

pastedImage_1.png

pastedImage_2.png

Wish it helps you!


Have a great day,

Kerry

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

0 Kudos

797 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi NELVI JOHN,

    What the board you are using now?

   Your own board or the official board?


Have a great day,
Kerry

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

0 Kudos

797 Views
nelvijohn
Contributor I

Hi Kerry,

   My board is based on MCB1800. But some pins are customized as well. But it is following the standard of MCB1800.

0 Kudos