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.
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??