من UART0/1/3 رو راه اندازی کردم و از اونها استفاده کردم. ولی UAR2 رو که فعال می کنم . مشکل داره. راه اندازی UART2 نکته داره؟
همین مشکل رو با LPC1788 دارم.
همین مشکل رو با LPC1788 دارم.
void Init_serial2 (void) { uint16_t usFdiv; LPC_PINCON->PINSEL0 |= (1 << 20); /* Pin P0.10 used as TXD2 (Com2) */ LPC_PINCON->PINSEL0 |= (1 << 22); /* Pin P0.11 used as RXD2 (Com2) */ LPC_SC->PCONP = LPC_SC->PCONP|(1<<24); /*Open UART2 power control bit */ LPC_UART2->LCR = 0x83; /* Allows you to set the baud rate */ usFdiv = (Fcpu / 16) / BaudRate; /* Set baud rate */ LPC_UART2->DLM = usFdiv / 256; LPC_UART2->DLL = usFdiv % 256; LPC_UART2->LCR = 0x03; /* Locked baud rate */ LPC_UART2->IER = 0x01 ; //can be changed only when DLAB=0 LPC_UART2->FCR = 0x07; NVIC_SetPriority(UART2_IRQn,20); // Default priority group 3, can be 0(highest) - 31(lowest) NVIC_EnableIRQ(UART2_IRQn); // Enable UART0 Interrupt } void UART2_IRQHandler (void) __irq { unsigned char IIRValue, LSRValue; IIRValue = LPC_UART2->IIR; IIRValue >>= 1; // skip pending bit in IIR IIRValue &= 0x07; // check bit 1~3, interrupt identification else if ( IIRValue == IIR_RDA ) // Receive Data Available { //Receive Data Available UART2Buffer[UART2Count] = LPC_UART2->RBR; sendchar2(UART2Buffer[UART2Count]); } else if ( IIRValue == IIR_CTI ) // Character timeout indicator { // Character Time-out indicator / UART2Status |= 0x100; // Bit 9 as the CTI error sendchar2(UART2Buffer[UART2Count]); UART2Count++; } } int main (void) { unsigned int i; Init_serial2(); while(1) { i++; sendchar2(i); delay_ms(1000); } }
UARTPutChar(UART_0,'a');
UARTPutChar(UART_0,'a');
#include "lpc17xx.h" /* LPC17xx definitions */ #include "uart.h" #define FPCLK 25000000 #define UART0_BPS 9600 /* 0 Serial communication baud rate */ /********************************************************************************************************* ** Function name: UART0_Init ** Descriptions: By default initialize the serial port 0 pins and communication parameters. Set to 8 data bits, 1 stop bit, no parity ** input parameters: No ** output parameters: No ** Returned value: No *********************************************************************************************************/ void UART0_Init (void) { uint16_t usFdiv; /* UART0 */ LPC_SC->PCONP |=(1<<3); LPC_PINCON->PINSEL0 |= (1 << 4); /* Pin P0.2 used as TXD0 (Com0) */ LPC_PINCON->PINSEL0 |= (1 << 6); /* Pin P0.3 used as RXD0 (Com0) */ LPC_UART0->LCR = 0x83; /* Allows you to set the baud rate */ usFdiv = (FPCLK / 16) / UART0_BPS; /* Set baud rate */ LPC_UART0->DLM =usFdiv / 256; LPC_UART0->DLL =usFdiv % 256; //LPC_UART0->FDR=0X43; LPC_UART0->LCR = 0x03; /* Locked baud rate */ LPC_UART0->FCR =0x07; LPC_UART0->IER = 0x01; NVIC_SetPriority(UART0_IRQn,0); /* Default priority group 0, can be 0(highest) - 31(lowest) */ NVIC_EnableIRQ(UART0_IRQn); } /********************************************************************************************************* ** Function name: UART0_SendByte ** Descriptions: send data from serial port 0 ** Input parameters: data: data sent ** Output parameters: None ** Returned value: None *********************************************************************************************************/ void UART0_SendByte (int ch) { while (!(LPC_UART0->LSR & 0x20)); LPC_UART0->THR =ch; } void UART0_SendChar(int disp) { int dispbuf[4]; int i; dispbuf[3] = disp%10 + '0'; dispbuf[2] = disp/10%10 + '0'; dispbuf[1] = disp/10/10%10 + '0'; dispbuf[0] = disp/10/10/10%10 + '0'; for(i=0;i<4;i++) UART0_SendByte(dispbuf[i]); } /*---------------------------------------------------------------------------- Read character from Serial Port (blocking read) *----------------------------------------------------------------------------*/ int UART0_GetChar (void) { while (!(LPC_UART0->LSR & 0x01)); return (LPC_UART0->RBR); } void UART0_SendString (unsigned char *s) { while (*s != 0) { UART0_SendByte(*s++); } }
دیدگاه