Hi,
I have mcb2140 which two serial ports COM1 and COM0. I want to connect COM1 to my computer and COM0 to other evaluation board PN544.
I want to basically send commands from my computer to arm board through COM1 and then send command to pn544 evaluation board through COM0 and in turn get and pass response from PN544 to computer via arm board.
Please can anyone suggest how sould i do this.
1)Can two serial ports on arm board work simulataneously.
2)Any specific jumper settings required?
3)Can anyone explain me what is PINSEL0 = 0x00050000; U1LCR = 0x83; U1DLL = 97; U1LCR = 0x03;
how do we define which serial port to use com1 or com0
4)what is U1THR,U1LSR?
cose is as follows:(serial.c)
#include <LPC21xx.H> /* LPC21xx definitions */
#define CR 0x0D
void init_serial (void) { /* Initialize Serial Interface */ PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */ U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */ U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */ U1LCR = 0x03; /* DLAB = 0 */ }
/* implementation of putchar (also used by printf function to output data) */ int sendchar (int ch) { /* Write character to Serial Port */
if (ch == '\n') { while (!(U1LSR & 0x20)); U1THR = CR; /* output CR */ } while (!(U1LSR & 0x20)); return (U1THR = ch); }
int getkey (void) { /* Read character from Serial Port */
while (!(U1LSR & 0x01));
return (U1RBR); }
--- Looking for any suggestion. thanks
> Please can anyone suggest how should i do this.
I would say:
- Initialize UART0 with the Baud Rate you need, and configure it for RX Interrupt. - Write an ISR to test the echo. - Copy&Paste the functions, and rename everything to Uart1 :-) and test it.
Now you have two UARTS, with "blocking" TX and Polling RX. Write some high level functions for handling the two uarts as you need.
The Registers (f.e. UxTHR = Uartx Transmit Holding Register) are described (very good) in the LPC214x user manual.
An other good idea (a bit more complicated, but more flexible) is the retarget-midlayer (retarget.c). If you follow the std C Library very deep, you may re-implement the _sys_read/write/open/close - functions, then you can work with fprintf and filepointers.
Regards, /th.
Some of my very first experiance with LPC2148 (MCB2140):
// Bit_on, bit_off definitions #define bit_on(BYTE, BIT) { BYTE |= 1 << BIT; } #define bit_off(BYTE, BIT) { BYTE &= ~(1 << BIT); } #define DIVADDVAL 0 #define MULVAL 4 #define THRE 5 //THRE is set immediately upon detection of an empty UART0 THR and is cleared on a U0THR write. #define TXEN 7 // TX enable #define DLAB 7 // UART0 contains registers organized as shown in Table 9â€"96. The Divisor Latch Access // Bit (DLAB) is contained in U0LCR[7] and enables access to the Divisor Latches. // UART0 #define UDR_R0 U0RBR #define UDR_T0 U0THR #define RX0INT 0 // enables RX Data avaiable INT /*************************** * getting started * * * * with LPC2148 * * * ***************************/ #include <stdio.h> #include "lpc214x.h" #include "lpc214x_reg_bits.h" #include "main.h" #include "uart.h" char UART0TxEmpty = 1; void init_uart(int baud) { int baud_tmp=0; //switch ON RxD and TxD with PinSelect (see Manual Page 75) bit_on(PINSEL0, 0); bit_off(PINSEL0, 1); bit_on(PINSEL0, 2); bit_off(PINSEL0, 3); // fract. baud off ?? U0FDR = (0 << DIVADDVAL); U0FDR = (1 << MULVAL); // set Divisor Latch Access Bit(DLAB) // to get access bit_on(U0LCR, DLAB); //NOTE: 1.3 is not clean, but works. Have a look at fractional Baud Rate. baud_tmp = CLK / (16 * baud) * 1.3; U0DLL = baud_tmp % 256; U0DLM = baud_tmp / 256; bit_on(U0LCR, 0); // 8 bit data bit_on(U0LCR, 1); bit_off(U0LCR, 2); // 1 stop bit_off(U0LCR, 3); // parity disable bit_off(U0LCR, 4); // parity select (odd) bit_off(U0LCR, 5); // parity select bit_off(U0LCR, 6); // Break Control bit_off(U0LCR, 7); // Divisor Latch Access Bit bit_on(U0TER, 7); // TX enable } void uart_putchar(char character) { //while(!(U0LSR & THRE)); U0THR = character; } /** * \author Th. de Buhr (thorsten@lasertechnix.de) * \param char* text * \return void * \brief Prints a string to the serial console (String ends with '\\0') */ void uart_print(char* text) { char p=0; while(text[p] != '\0') { if (text[p] == '\n') { while (!(U0LSR & (1<<5))); U0THR = '\r'; } while (!(U0LSR & (1<<5))); U0THR = text[p]; p++; } } int fputc(int c, FILE *f) { if (c == '\n') { while (!(U0LSR & (1<<5))); U0THR = '\r'; } while (!(U0LSR & (1<<5))); U0THR = c; return(c); }
*argh* Mistake :-)
"Now you have two UARTS, with "blocking" TX and Interrupt RX. That means that every incomming char produces an interrupt. You may fill a buffer with the chars. Handling them directly in the ISR is - of course - possible, but not recommended. Write some high level functions for handling the two uarts as you need."
What you should do?
Read the user manual for the processor.
Read all the example code that is supplied with the Keil tools and are available (directly or by reference) from the NXP product page.
Now you will now exactly what the different registers are, and what they do. You will now how to initialize serial prots. You will now how to send and receive.
It should be trival to extend that so that data is forwarded between the serial interfaces.
This is a school assignment, and the assignment is not how to perform distributed development - you should not run around requesting others to do all your job. Your assignment is for you to do. Your teacher should have made sure that you have enough knowledge to know how to perform this assignment. And only by doing the assignment (instead of copying other peoples code) will you be able to learn something new.
1) Would you accept a PC that can't use two serial ports at the same time? Do you think the chip vendor would say that the processor has two serial ports if it only has one serial port that is multiplexed?
2) Doesn't the manual for your board explain all strap fields?
3) Didn't you find the explanation of the UART registers in the processor user manual? Didn't that information make it obvious how you access UART0 or UART1?
4) Didn't the processor user manual contain the information about these registers?
thanks for a long suggestion, however it would be good that instead of suggesting what i should do if you could provide some useful links where I could read and make my questions clear. For your information,this is not a school project.I am new to this field of arm processor and would like to gain knowleadge in this area.I am not expecting any code just wanted to make some points clear. Please remember it might be very simple for you but for someone new in this field it might be very difficult and confusing
It seems you really know a lot in this area so please can you answer my questions or provide some useful links which i can read:
3)Following are setting for serial com 1 PINSEL0 = 0x00050000; U1LCR = 0x83; U1DLL = 97; U1LCR = 0x03;
For com0 are the following ok? PINSEL0 = 0x00000005; U0LCR = 0x00000083; U0DLL = 97; U0LCR = 0x00000003;
4)what is U1THR,U1LSR? ( please Define)
Yes, I recommended the individual steps not to be evil but because you need to perform them to get up to speed. Getting yes/no or copy-paste answers here will not help you even a fraction of the way that the correct use of the individual manuals will. There is no substitute for reading. If this was a school assignment, then getting turn-key solutions may have been an alternative to "pass the test", but since this isn't a school work, true knowledge of the target chip is vital. The cost of producing real equipment and later find out that they are broken can be quite high. And the probability of that happening can be quite high if chip manual + data sheet are not read.
Anyway, more specific answers that still requires you to read the user manual for the chip. Note that NXP has many chips, and knowledge about the concepts does not mean that the people who answer happens to have the user manual (and hence the exact pin configuration bits...) for the specific chip model you ask questions about. Also, the one who cares most about your project is (or should be) you, which is a good reason why the manual is important.
Note that PINSEL0 is a bitmap for a number of pins. You can't assign 0x00000005 to it without overwriting any assign you have already done for the other UART.
Either compute a "total" value for PINSEL0 for all pins controlled by this register, or rewrite the code to perform and + or.
PINSEL0 = (PINSEL0 & ~AFFECTED_PINS) | EXPECTED_VALUES;
Or for your UART0 assign
PINSEL0 = (PINSEL0 & ~0xf) | 0x5; // Enable RXD0 and TXD0
How to control which UART to use? That depends on how you are going to send data. If you mean printf() - use the serach function in the upper right of this web page and you will find a number of references how to redirect printf() output to different ports.
Or create your own com0_printf(), com1_printf() etc that performs a sprintf() and then copies the data to the relevant send buffer.
The manual does a good job of defining the Transmit Holding Register and the Line Status Register.
I have read the mcb2140 manual and set the registers for com0 and com1 at baudrate 115200. Arm board com0 is connected to the pc's serial port Arm board com1 is connected to another chip PN544 evaluation board. Pn544 on reseting sends few bytes which I want to scan or read through com1 and send it to pc through com0 to the pc (basically the arm board acts as an interface between pc and another chip). But the problem is I don't exactly the same bytes on PC from Pn544 when it is directly connected without the arm board throuch serial cable.
I just want am board to act as an interface.Please suggest any ideas possible to make it work
the code is for serialcom0 and com1 settings:
void init_serial0 (void) { PINSEL0 = 0x00000005; U0LCR = 0x83; U0DLL = 8; //115200 Baud Rate @ 15MHz VPB Clock //U0DLL = 97; // 9600 Baud Rate @ 15MHz VPB Clock U0LCR = 0x03; }
void init_serial1 (void) { PINSEL0 = 0x00050000; U1LCR = 0x83; U1DLL = 8; U1LCR = 0x03; } ------------------- int main(void) { int j; char c; char st[50]; int cmd[4]= 0;
while(1) { j = 0; init_serial1(); scanf("%d",&j); init_serial0(); sendchar(j); printf("\n"); } } -------------- int sendchar (int ch) {
if( PINSEL0 == 0x00050000) { if (ch == '\n') { while (!(U1LSR & 0x20)); U1THR =CR; } while (!(U1LSR & 0x20)); return (U1THR = ch); } else if( PINSEL0 == 0x00000005) { if (ch == '\n') { while (!(U0LSR & 0x20)); U0THR = CR; } while (!(U0LSR & 0x20)); return (U0THR = ch); } }
int getkey (void) {
if( PINSEL0 == 0x00050000) { while (!(U1LSR & 0x01)); return (U1RBR); } else if( PINSEL0 == 0x00000005) { while (!(U0LSR & 0x01)); return (U0RBR); } }
thanks a lot for ur reply.The mcb2140 manual is really helpful .It cleared many of my doubts but now i am stucked up with this problem .pl can u suggest what is wrong.. I have read the mcb2140 manual and set the registers for com0 and com1 at baudrate 115200. Arm board com0 is connected to the pc's serial port Arm board com1 is connected to another chip PN544 evaluation board. Pn544 on reseting sends few bytes which I want to scan or read through com1 and send it to pc through com0 to the pc (basically the arm board acts as an interface between pc and another chip). But the problem is I don't exactly the same bytes on PC from Pn544 when it is directly connected without the arm board throuch serial cable.
thanks a lot for ur reply.The mcb2140 manual is really helpful .It cleared many of my doubts but now i am stucked up with this problem .pl can u suggest what is wrong.. I have read the mcb2140 manual and set the registers for com0 and com1 at baudrate 115200. Arm board com0 is connected to the pc's serial port Arm board com1 is connected to another chip PN544 evaluation board. Pn544 on reseting sends few bytes which I want to scan or read through com1 and send it to pc through com0 to the pc (basically the arm board acts as an interface between pc and another chip). But the problem is-
I don't get any bytes on the pc(sometimes i get lot of garbage bytes i have no idea from where) Can both UART 0 and UART1 access data from same memory? I mean UART1 will receive data and keep it in UART1 FIFO.But how does UART0 access that FIFO??
Why do you feel that a full duplication of your previous post improve your chances to get an answer?
Where is the text where you tell us your ideas and what you have tried and if it worked or why it failed?
hi,
i know full duplication will not improve my chance of getting my answer,but if you carefully observe i have added few more sentences to make my question clear. i have mentioned the code which i have tried and if i knew the reason why it is not working,i would not have added my post in this forum.Please provide any valuable suggestion if u have thanks
As you may notice, your code is totally unreadable, since you did not follow the posting instructions. Just above the "message" input box, there is information about how to post source code.
No, one UART can't access the FIFO of another uart.
Depending on processor, you will have the following alternatives: - activate the DMA to automagically transfer data from one UART receive FIFO to the other UART transmit FIFO. - write an interrupt routine that picks up received characters from one FIFO and puts them in the transmit FIFO for the other port (start by putting the characters into the transmit FIFO of the same port to verify that you get a perfect echo function). - write polling code that repeatedly checks if there are any characters received on one UART and then copies them to the other UART.
There are a lot of example code that performs both polled and interrupt-driven communication. Unless the baudrates are extremely high, there shouldn't be any need for the DMA solution.
If the receive UART has a higher baudrate than the transmit UART, then you must use the handshake signals, XON/XOFF or any other method for implementing flow control.
So, select a solution. Read the user manual. Look at the examples. Edit the example code until it fits your requirements.
Thanks for ur help.i am sorry i didn't post my source code in proper manner. I would like to try 2 and 3 option as i am not sure whether mcb2140 supports dma or not.Please can u specify some manual or document or simple examples which help me understand as i have never implemented isr.
NXP can supply examples. Keil already has supplied examples. Have you looked at them?