LPC824
调试串口0收发数据,用调试助手发12345678,但接受到8个1,大神帮忙看一下!!
#include "LPC8xx.h"
#include
#include
#define UART_BPS 9600
#define BUFFSIZE 64
#define tiME (3.5*10)/UART_BPS
volatile uint8_t UART0_GucRcvNew;
uint8_t UART0_GucRcvBuf[BUFFSIZE];
uint8_t UART0_GucRcvProcess[BUFFSIZE];
uint32_t Gul0Num;
uint32_t Sen0Num;
void UARTInit (void)
{
LPC_SWM->PINASSIGN[0] &= ~( 0xFFFF << 0 );
LPC_SWM->PINASSIGN[0] |= ( 4 << 0 );
LPC_SWM->PINASSIGN[0] |= ( 0 << 8 );
LPC_SYSCON->UARTCLKDIV = 1;
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 14);
LPC_USART0->BRG = SystemCoreClock * LPC_SYSCON->SYSAHBCLKDIV /
(LPC_SYSCON->UARTCLKDIV * 16 * UART_BPS) - 1;
LPC_USART0->CFG = (1 << 0) |
(1 << 2) |
(0 << 4) |
(0 << 6);
LPC_USART0->INTENSET = (1 << 0);
NVIC_EnableIRQ(UART0_IRQn);
NVIC_SetPriority(UART0_IRQn,5);
}
void UART0_IRQHandler (void)
{
LPC_MRT->CHANNEL[0].INTVAL = SystemCoreClock*TIME;
LPC_MRT->CHANNEL[0].INTVAL |= 1UL << 31;
if (LPC_USART0->STAT & 0x01)
{
UART0_GucRcvBuf[Gul0Num] = LPC_USART0->RXDATA;
Gul0Num++;
Sen0Num=Gul0Num;
LPC_MRT->CHANNEL[0].INTVAL = SystemCoreClock*TIME;
LPC_MRT->CHANNEL[0].INTVAL |= 1UL << 31;
void UART0SendByte (uint8_t ucData)
{
while ((LPC_USART0->STAT & 0x04) == 0);
LPC_USART0->TXDATA = ucData;
while ((LPC_USART0->STAT & 0x08) == 0);
}
void UART0SendString (uint8_t *pucData, uint32_t uiLen)
{
uint32_t i;
for(i=0;i
{
UART0SendByte(*pucData);
}
}
void MRTInit (void)
{
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 10);
LPC_SYSCON->PRESETCTRL &= ~(1 << 7);
LPC_SYSCON->PRESETCTRL |= (1 << 7);
LPC_MRT->CHANNEL[0].CTRL = (1 << 0) | (1 << 1);
NVIC_EnableIRQ(MRT_IRQn);
NVIC_SetPriority(UART0_IRQn,4);
}
/*********************************************************************************************************
** Function name: MRT_IRQHandler
** Descriptions: MRTÖжϷþÎñº¯Êý
** input parameters: ÎÞ
** output parameters: ÎÞ
** Returned value: ÎÞ
*********************************************************************************************************/
void MRT_IRQHandler (void)
{
uint32_t i;
LPC_MRT->CHANNEL[0].STAT = (1 << 0);
UART0_GucRcvNew=1;
for(i=0;i
{
UART0_GucRcvProcess=UART0_GucRcvBuf;
}
Gul0Num=0;
LPC_MRT->CHANNEL[0].INTVAL = 0;
LPC_MRT->CHANNEL[0].INTVAL |= 1UL << 31; 关闭定时器
}
int main (void)
{
SystemInit();
UARTInit();
MRTInit();
// GuiNum=0;
// GucRcvNew=0;
while (1)
{
if(UART0_GucRcvNew==1)
{
UART0_GucRcvNew=0;
UART0SendString (UART0_GucRcvProcess,Sen0Num);
}
}
}
回帖(3)
2018-4-17 10:47:41
最佳答案
系统时钟的问题
系统时钟的问题
举报
2018-4-17 10:55:04
2018-5-2 17:07:59
怎么解决的? 分享一下
怎么解决的? 分享一下
举报
更多回帖