终于把支持3种芯片的板子焊接完成了,累死我了,可以继续学习下面的内容了。。。
开发板贴:https://bbs.eeworld.com.cn/viewthread.php?tid=299669&page=1&extra=page%3D1
LPC1114/LPC1343串口特点:
16字节收发FIFO;
寄存器位置符合16C550工业标准;
接收器FIFO触发点可为1、4、8和14字节;
内置波特率发生器;
用于精确控制波特率的小数分频器,并拥有赖以实现软件流控制的自动波特率检测能力和机制;
支持软件或硬件流控制执行;
包含标准Modem接口信号(CTS、DCD、DTS、DTR、RI、RTS);
支持RS-458/EIA-485的9位模式和输出使能。
LPC11U14串口特点:
• 16-byte receive and transmit FIFOs.
• Register locations conform to ‘550 industry standard.
• Receiver FIFO trigger points at 1, 4, 8, and 14 bytes.
• Built-in baud rate generator.
• Software or hardware flow control.
• RS-485/EIA-485 9-bit mode support with output enable.
• RTS/CTS flow control and other modem control signals.
• 1X-clock send or receive.
• ISO 7816-3 compliant smart card interface.
• IrDA support.
从它们的特点可以看出,LPC11U14的串口功能要强大一些,除了增加了USART,还增加了读卡和红外功能。。。
[
本帖最后由 zhaojun_xf 于 2011-8-31 21:59 编辑 ]
串口寄存器也增加了不少,这里就不再说明,大家可以参考资料手册。
[
本帖最后由 zhaojun_xf 于 2011-9-2 22:49 编辑 ]
LPC1114和LPC1343在UART上是一样的,而LPC11U14多了部分功能,此外代码基本一致,如初始化代码:
收发代码:
但是LPC11U14的寄存器名称是不一样的,寄存器都要改成LPC_USART,如:
当普通串口使用时,其他基本一致。
[
本帖最后由 zhaojun_xf 于 2011-9-2 22:31 编辑 ]
值得一说的是,LPC11U14的串口管脚增加了多个映射管脚,使得设计PCB更加方便灵活:
[
本帖最后由 zhaojun_xf 于 2011-9-2 22:48 编辑 ]
有这个的学习手册没,楼主,这个我真在学,希望给发个
还有我那个板子,想调端口通信,但在计算机上找不到那个端口(com口),是怎么回事,是啥驱动没弄好还是咋回事啊,
回复 8楼 cuanli007 的帖子
如果没有串口,就需要安装USB转串口,并安装驱动。。。。。。。
回复 10楼 cuanli007 的帖子
要连线处理的。。。。。。。。
串口程序。能不能把这个usart.c和usart.h文件给发个,这里乱了。想参考一下
写usart.h是都要用到哪些寄存器 初始化 ,怎么写啊
#ifndef __USART_H
#define __USART_H
#define SYNC_ON (0x1<<0)
#define SYNC_OFF (0x0<<0)
#define SYNC_MASTER (0x1<<1)
#define SYNC_SLAVE (0x0<<1)
#define SYNC_RE (0x0<<2)
#define SYNC_FE (0x1<<2)
#define SYNC_CONT_CLK_EN (0x1<<4)
#define SYNC_CONT_CLK_DIS (0x0<<4)
#define SYNC_STARTSTOPOFF (0x1<<5)
#define SYNC_STARTSTOPON (0x0<<5)
#define SYNC_CON_CLK_CLR (0x1<<6)
#endif /* end __USART_H */这个可以不
#include "lpc11uxx.h"
#include "uart.h"
volatile uint32_t UARTStatus;
volatile uint8_t UARTTxEmpty = 1;
volatile uint8_t UARTBuffer[BUFSIZE];
volatile uint32_t UARTCount = 0;
/*****************************************************************************
** Function name: UART_IRQHandler
**
** Descriptions: UART interrupt handler
**
** parameters: None
** Returned value: None
**
*****************************************************************************/
void UART_IRQHandler(void)
{
uint8_t IIRValue, LSRValue;
uint8_t Dummy = Dummy;
IIRValue = LPC_USART->IIR;
IIRValue >>= 1; /* skip pending bit in IIR */
IIRValue &= 0x07; /* check bit 1~3, interrupt identification */
if (IIRValue == IIR_RLS) /* Receive Line Status */
{
LSRValue = LPC_USART->LSR;
/* Receive Line Status */
if (LSRValue & (LSR_OE | LSR_PE | LSR_FE | LSR_RXFE | LSR_BI))
{
/* There are errors or break interrupt */
/* Read LSR will clear the interrupt */
UARTStatus = LSRValue;
Dummy = LPC_USART->RBR; /* Dummy read on RX to clear
interrupt, then bail out */
return;
}
if (LSRValue & LSR_RDR) /* Receive Data Ready */
{
/* If no error on RLS, normal ready, save into the data buffer. */
/* Note: read RBR will clear the interrupt */
UARTBuffer[UARTCount++] = LPC_USART->RBR;
if (UARTCount == BUFSIZE)
{
UARTCount = 0; /* buffer overflow */
}
}
}
else if (IIRValue == IIR_RDA) /* Receive Data Available */
{
/* Receive Data Available */
UARTBuffer[UARTCount++] = LPC_USART->RBR;
if (UARTCount == BUFSIZE)
{
UARTCount = 0; /* buffer overflow */
}
}
else if (IIRValue == IIR_CTI) /* Character timeout indicator */
{
/* Character Time-out indicator */
UARTStatus |= 0x100; /* Bit 9 as the CTI error */
}
else if (IIRValue == IIR_THRE) /* THRE, transmit holding register empty */
{
/* THRE interrupt */
LSRValue = LPC_USART->LSR; /* Check status in the LSR to see if
valid data in U0THR or not */
if (LSRValue & LSR_THRE)
{
UARTTxEmpty = 1;
}
else
{
UARTTxEmpty = 0;
}
}
return;
}
#if MODEM_TEST
/*****************************************************************************
** Function name: ModemInit
**
** Descriptions: Initialize UART0 port as modem, setup pin select.
**
** parameters: None
** Returned value: None
**
*****************************************************************************/
void ModemInit( void )
{
LPC_IOCON->PIO0_7 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO0_7 |= 0x01; /* UART CTS */
LPC_IOCON->PIO0_17 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO0_17 |= 0x01; /* UART RTS */
#if 1
LPC_IOCON->PIO1_13 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_13 |= 0x01; /* UART DTR */
LPC_IOCON->PIO1_14 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_14 |= 0x01; /* UART DSR */
LPC_IOCON->PIO1_15 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_15 |= 0x01; /* UART DCD */
LPC_IOCON->PIO1_16 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_16 |= 0x01; /* UART RI */
#else
LPC_IOCON->PIO1_19 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_19 |= 0x01; /* UART DTR */
LPC_IOCON->PIO1_20 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_20 |= 0x01; /* UART DSR */
LPC_IOCON->PIO1_21 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_21 |= 0x01; /* UART DCD */
LPC_IOCON->PIO1_22 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_22 |= 0x01; /* UART RI */
#endif
LPC_USART->MCR = 0xC0; /* Enable Auto RTS and Auto CTS. */
return;
}
#endif
/*****************************************************************************
** Function name: UARTInit
**
** Descriptions: Initialize UART0 port, setup pin select,
** clock, parity, stop bits, FIFO, etc.
**
** parameters: UART baudrate
** Returned value: None
**
*****************************************************************************/
void UARTInit(uint32_t baudrate)
{
uint32_t Fdiv;
uint32_t regVal;
UARTTxEmpty = 1;
UARTCount = 0;
NVIC_DisableIRQ(UART_IRQn);
/* Select only one location from below. */
#if 1
LPC_IOCON->PIO0_18 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO0_18 |= 0x01; /* UART RXD */
LPC_IOCON->PIO0_19 &= ~0x07;
LPC_IOCON->PIO0_19 |= 0x01; /* UART TXD */
#endif
#if 0
LPC_IOCON->PIO1_14 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_14 |= 0x03; /* UART RXD */
LPC_IOCON->PIO1_13 &= ~0x07;
LPC_IOCON->PIO1_13 |= 0x03; /* UART TXD */
#endif
#if 0
LPC_IOCON->PIO1_26 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_26 |= 0x02; /* UART RXD */
LPC_IOCON->PIO1_27 &= ~0x07;
LPC_IOCON->PIO1_27 |= 0x02; /* UART TXD */
#endif
/* Enable UART clock */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
LPC_SYSCON->UARTCLKDIV = 0x1; /* divided by 1 */
LPC_USART->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
regVal = LPC_SYSCON->UARTCLKDIV;
Fdiv = ((SystemCoreClock/regVal)/16)/baudrate ; /*baud rate */
LPC_USART->DLM = Fdiv / 256;
LPC_USART->DLL = Fdiv % 256;
LPC_USART->LCR = 0x03; /* DLAB = 0 */
LPC_USART->FCR = 0x07; /* Enable and reset TX and RX FIFO. */
/* Read to clear the line status. */
regVal = LPC_USART->LSR;
/* Ensure a clean start, no data in either TX or RX FIFO. */
while (( LPC_USART->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) );
while ( LPC_USART->LSR & LSR_RDR )
{
regVal = LPC_USART->RBR; /* Dump data from RX FIFO */
}
/* Enable the UART Interrupt */
NVIC_EnableIRQ(UART_IRQn);
#if TX_INTERRUPT
LPC_USART->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART interrupt */
#else
LPC_USART->IER = IER_RBR | IER_RLS; /* Enable UART interrupt */
#endif
return;
}
/*****************************************************************************
** Function name: UARTSend
**
** Descriptions: Send a block of data to the UART 0 port based
** on the data length
**
** parameters: buffer pointer, and data length
** Returned value: None
**
*****************************************************************************/
void UARTSend(uint8_t *BufferPtr, uint32_t Length)
{
while ( Length != 0 )
{
/* THRE status, contain valid data */
#if !TX_INTERRUPT
while ( !(LPC_USART->LSR & LSR_THRE) );
LPC_USART->THR = *BufferPtr;
#else
/* Below flag is set inside the interrupt handler when THRE occurs. */
while ( !(UARTTxEmpty & 0x01) );
LPC_USART->THR = *BufferPtr;
UARTTxEmpty = 0; /* not empty in the THR until it shifts out */
#endif
BufferPtr++;
Length--;
}
return;
}
/*****************************************************************************
** Function name: print_string
**
** Descriptions: print out string on the terminal
**
** parameters: pointer to the string end with NULL char.
** Returned value: none.
**
*****************************************************************************/
void print_string( uint8_t *str_ptr )
{
while(*str_ptr != 0x00)
{
while((LPC_USART->LSR & 0x60) != 0x60);
LPC_USART->THR = *str_ptr;
str_ptr++;
}
return;
}
/*****************************************************************************
** Function name: get_key
**
** Descriptions: Get a character from the terminal
**
** parameters: None
** Returned value: character, zero is none.
**
*****************************************************************************/
uint8_t get_key( void )
{
uint8_t dummy;
while ( !(LPC_USART->LSR & 0x01) );
dummy = LPC_USART->RBR;
if ((dummy>=65) && (dummy<=90))
{
/* convert capital to non-capital character, A2a, B2b, C2c. */
dummy +=32;
}
/* echo */
LPC_USART->THR = dummy;
return(dummy);
}
.h 和.c咋样啊LPC11u14可以用吗
回复 14楼 cuanli007 的帖子
周工网上都有例程,你可以去找找。。。。。。
NVIC_EnableIRQ(UART_IRQn);
NVIC_EnableIRQ(0);这时打开串口中断
NVIC_EnableIRQ(1);这是关闭串口中断支、这是不是就是五一中的ES
对吗??
LPC_USART->IER =1;这是打开接受中断
LPC_USART->IER =0;这是关闭,这话说是不是就是就是五一中的RI啊
对吗?
NVIC_EnableIRQ(UART_IRQn); 编译时下面函数报错啊
static __INLINE void NVIC_ableIRQ(IRQn_Type IRQn)
{
NVIC->ICER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}