导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→[求助]熟悉LPC2210的帮看一个串口通信的问题,急啊~[歌以当之]

 *第49335篇: [求助]熟悉LPC2210的帮看一个串口通信的问题,急啊~

  
楼 主:歌以当之 2007年5月30日13:13
 [求助]熟悉LPC2210的帮看一个串口通信的问题,急啊~
帮看一个串口程序,调到2点多,死活就是进不到中断
MCU:LPC2210,ARM7
中断方式发送数据,使用FIFO功能,自动发送512字节的buffer

在main函数中调用UART0Ini,就实现自动发送数据

现在发送前16BYTE数据成功,然后就进不了U0THR空的中断~~~
大家帮看一下,问题出在哪?是不是通常情况下很少用中断方式来发送数据?


/*********UART mode config struct********/
typedef struct _UARTMode
{
 uint8 nDataBits;//frame data length in bits,5/6/7/8 
 uint8 nStopBits;//stop bits,1/2
 uint8 Parity;//0:no parity,1:odd parity,2:even parity
}UARTMode;

/*****Pointing to the byte to send next******/
uint8* pCur;

/*****Position of the byte to send next******/
uint16 nPos;

/*****Flag to tell that buffer needs to be freshed again******/
uint8 bEmpty;


uint8 pBuf[BLOCKSIZE];


/*****Initialize the buffer for send*****/
void BufIni()
{
 uint16 nCnt;
 for(nCnt=0;nCnt  <BLOCKSIZE;nCnt++)
  pBuf[nCnt] = (nCnt >  >   1);
 bEmpty = 0;
}

//配置IO端口,选通UART0
void InitIOport()
{
 PINSEL0 = (PINSEL0 & 0xfffffff0) | 0x00000005;
}

//设置中断寄存器
void IRQConf()
{
 VICIntSelect = 0x00000000;
 VICVectCntl0 = 0x20 | 6;
 VICVectAddr = (uint32)IRQ_UART0_Send;
 VICIntEnable = 0x00000040;
 U0FCR = 0x81;
 U0IER = 0x02;
}

//设置波特率
void SetBaud(uint32 nBaud)
{
 uint32 temp;
 U0LCR = 0x80;
 temp = (Fpclk >  >   4) / nBaud;
 U0DLM = temp >  >   8;
 U0DLL = temp & 0xff;
}

//设置串口工作方式
void SetUART0Mode(UARTMode stUART0M)
{
 uint8 Ctrl;
 Ctrl = stUART0M.nDataBits - 5;
 if(stUART0M.nStopBits == 2)
  Ctrl |= 0x04;
 if(0 != stUART0M.Parity)
 {
  Ctrl |= 0x08;
  stUART0M.Parity --;
 }
 Ctrl |= (stUART0M.Parity   <  < 4);
 U0LCR = Ctrl;
 U0FCR = 0x81;
}

//初始发送16字节数据
void SendBuf()
{
 uint8 i;
 pCur = pBuf;
 for(i=0;i  <16;i++)
 {
  U0THR = *pCur;
  pCur ++;
 }
 nPos += 16;
 if(nPos >  = 512)
 {
  nPos = 0;
  pCur = pBuf;
  bEmpty = 1;
 }

}

/*****irq func. for sending data from UART0,using FIFO mode******/
void __irq IRQ_UART0_Send()
{
 uint8 i;
 if(bEmpty == 1)
  return;
 if(0x02 == (U0IIR & 0x0f))
 {
  for(i=0;i  <8;i++)
  {
   U0THR = *pCur;
   pCur ++;
  }
  nPos += 8;
  if(nPos >  = 512)
  {
   nPos = 0;
   pCur = pBuf;
   bEmpty = 1;
  }
 }
 VICVectAddr = 0x00;
}

//UART0初始化和开始发送数据
void UART0_Ini()
{
 UARTMode stMode;
 BufIni();
 InitIOport();
 SetBaud(115200);
 stMode.nDataBits = 8;
 stMode.nStopBits = 1;
 stMode.Parity = 0;
 SetUART0Mode(stMode);
 IRQConf();
 SendBuf();
}



>>>>>>对该主题发表你的看法

本主题贴数1,分页: [第1页]


[上一篇主题]:请教8019的MAC问题

[下一篇主题]:各位与机器斗争的软件工程师,请进