I have connected lpc 2368 to computer via uart-1 and using bioscom funtion in c++ i have made a programme to send and receive char through uart.my problem is that i can send char from lpc 2368 and able to receive it on pc but when i send it from pc i am unable to receive it on lpc 2368 board.
receiver code::
#include <LPC23xx.H> /* LPC23xx definitions */
#define UART1 /* Use UART 0 for printf */
/* If UART 0 is used for printf */ #ifdef UART0 #define UxFDR U0FDR #define UxLCR U0LCR #define UxDLL U0DLL #define UxDLM U0DLM #define UxLSR U0LSR #define UxTHR U0THR #define UxRBR U0RBR /* If UART 1 is used for printf */ #elif defined(UART1) #define UxFDR U1FDR #define UxLCR U1LCR #define UxDLL U1DLL #define UxDLM U1DLM #define UxLSR U1LSR #define UxTHR U1THR #define UxRBR U1RBR #endif
void init_serial (void) { /* Initialize Serial Interface */ #ifdef UART0 PINSEL0 |= 0x00000050; /* Enable TxD0 and RxD0 */ #elif defined (UART1) PINSEL0 |= 0x40000000; /* Enable TxD1 */ PINSEL1 |= 0x00000001; /* Enable RxD1 */ #endif UxFDR = 0; UxLCR = 0x83; UxDLL = 78; UxDLM = 0; UxLCR = 0x03; }
int getkey (void) { /* Read character from Serial Port */
while (!(UxLSR & 0x01));//it just wait hear for infinite time???
return (UxRBR); }
int main() {
char c; init_serial(); PINSEL10=0;
FIO2DIR0=0xff; FIO2CLR0=0xFF;
c=getkey();
FIO2SET0=0x01;//never reach to this point??? while(1);
}
plz help me....
There could be several reasons for that:
1. The PC doesn't actually transmit it properly or at all;
2. There is a hardware fault somewhere between the PC and the lpc 2368 - so that it never actually reaches the UART's input pin
3. A problem in your receiving software.
You need to isolate which one(s) it is.
You also need to pay attention to the instructions for posting source code:
www.danlhenry.com/.../keil_code.png
The code isn't readable because of the incorrect posting method but have you taken a closer look at all bits of the line status register? If you have a baudrate error, you might get a framing error.
If you are using Windows Xp or greater you do not have direct access to the comm ports like you used to in DOS. Instead of bioscom you should be able to rewrite your windows code using a function called CreateFile and then use WriteFile to transmit if you go the Win32 library route.
You can confirm that the fault lies with the PC by doing a loopback test both on the ARM and on the PC. I suspect you'll find the ARM code is fine.
to isolate the problem i try to short the rx and tx pin of same uart but i still cant receive char!!! (which is possible in case of pc).so is there any power bit or some other bit which needed to set??
Yes, the LPC23xx has power control bits for all devices. The user manual describes what these bits are, and their initial values.
UART0 and UART1 should be default on, while UART2 and UART3 is default off.
But haven't you looked at the Keil or the NXP example code for using the serial ports?
And how do you read a source code line like this:
Are you using a -1-relative indexing of the ports?
i have copied that def from serial.h file given in keil exampls. examples are there but i dont understand it...
and i have check the manual and defalt value is '1' means power is on.plz tell me what should i do?