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
Hello, The code as follows. Sorry for the inconvenience. 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
void uart_rs485_receive(void) { GPIO_PinWrite(4,11,0);//Receive Enable a = LPC_USART3->RBR; }
Hi Rajesh, I have a request to you. Please read the each and every line of the answers you get here. If it is not understandable in first read then read it again and again until it is completely making sense to you. yes sometimes it is difficult for us because of the too much english they use in the answers ;).
So from the first response your questions Andy,
Whoever trying to help you here did not find your post as well presented as they like every professionals do. Again too much expectations on us right.. Your code look like you have a map on scribbles. So he is trying to help you to improve in that area. It is not technically solving your URGENT problem. But believe me you will be needing that anytime soon in your career.
Next, from the second answer you got from B Carutt, He asking you to uncomment an important line which seems to directly linked to your problem statement. But he also asking you to check the criticality of all other commented lines because he thinks those commented lines seem to be more than just comments.
Next, From the third answer you got from Westonsupermare Pier, I do not understand the meaning of the sarcasm. If it same to you then just ignore that answer.
Next, from your response, you did some clean up in your copy pasted code. And added some proper(I assume) register settings. But you failed to mention many information here. They do not know what is the result after you modified the code such as 1.Even after your code change still not able to load the FCR reg? and many more may be (i.e micro, hardware info, details of testing method etc).
And a final note from me, in this forum you do not get the right answers always but always learn something if you're willing. I was once in your shoes.
You still have not followed the simple, clearly-stated instructions on how to post source code!
Look at the picture: www.danlhenry.com/.../keil_code.png
You have also not stated what chip you are using.
The chip I am using is LPC1857
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; }
So you really don't believe in indentation for 'C' source code?
Sorry Neil, What you meant by this identation
Seriously?! You've never heard of indentation in the context of writing source code?!
en.wikipedia.org/.../Indent_style
It is an (almost?) universal way of laying out the text to make the structure clear & easy to read.
For example:
void uart_rs485_transmit(void) { GPIO_PinWrite(4,11,1); //Making Transmit Enable high if(LPC_USART3->LSR & 0x20) { LPC_USART3->THR = 83; } }
K. I am following the above told identation.
Hello, Let me know about the PCLK value that should be given for UART communication. How to assign PCLK in mdk5
Hi Rajesh check my message if it is helpful in anyway.
www.keil.com/.../ In the above link, they have given enough examples to start a product company. There is no direct RS-232 or RS-485 example programs. But even blink sample will have UART and/or LCD as a basic information display medium.
So with the given example you do not have to configure anything for UART(Including PCLK). But note that those examples targeted for MCB1800 board. You may have to modify pin configurations for your board.
I would suggest you to verify your UART functionalists first before testing your hardware dependent RS485 functionalists.
Hi Dharmaraj, Thanks a lot.I will check that link you have shared.
Hi Dharmaraj, I have gone through all the sample codes given. But I didnt get any match codes for UART communication. USB and I2C coomunications are similar to RS485?
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.