新手求助 LPC2368 串口通信

[复制链接]
2219|3
 楼主| zjk0728 发表于 2013-1-11 13:49 | 显示全部楼层 |阅读模式
刚学习LPC2368,按照深入浅出LPC213X上面写了个串口通信,调试中发现能初始化,但是用串口助手发数据不能返回,自己折腾了半天没弄明白,求教!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
huangxz 发表于 2013-1-11 13:59 | 显示全部楼层
lpc23xx跟lpc21xx 很多不一样的

  1. #include <LPC23xx.H>                    /* LPC24xx definitions               */

  2. /*----------------------------------------------------------------------------
  3. *       init_serial:  Initialize Serial Interface
  4. *---------------------------------------------------------------------------*/
  5. void init_serial (void) {
  6.    /* Initialize the serial interface */

  7.    /* Configure UART0 for 115200 baud. */
  8.    PINSEL0 &= ~(3 << 4);
  9.    PINSEL0 |=  1 << 4;                   /* Enable TxD0 pin              */
  10.    PINSEL0 &= ~(3 << 6);
  11.    PINSEL0 |=  1 << 6;                   /* Enable RxD0 pin              */

  12.    U0LCR = 0x83;                             /* 8 bits, no Parity, 1 Stop bit*/
  13.    U0DLL = 26;                                /* for 11.0592MHz PCLK Clock         */
  14. //   U0FDR = 0x67;                             /* Fractional Divider           */
  15.    U0LCR = 0x03;                             /* DLAB = 0                     */
  16. }

  17. /*----------------------------------------------------------------------------
  18. *       sendchar:  Write a character to Serial Port
  19. *---------------------------------------------------------------------------*/
  20. int sendchar (int ch) {
  21.    if (ch == '\n') {
  22.       while (!(U0LSR & 0x20));
  23.       U0THR = '\r';
  24.    }
  25.    while (!(U0LSR & 0x20));
  26.    return (U0THR = ch);
  27. }

  28. /*----------------------------------------------------------------------------
  29. *       getkey:  Read a character from Serial Port
  30. *---------------------------------------------------------------------------*/
  31. int getkey (void) {
  32.    while (!(U0LSR & 0x01));
  33.    return (U0RBR);
  34. }

  35. /*----------------------------------------------------------------------------
  36. *       RxDataReady:  if U1RBR contains valid data reurn 1, otherwise 0
  37. *---------------------------------------------------------------------------*/
  38. int RxDataReady( void )
  39. {
  40.         return ( U0LSR & 0x01 );        //Receive data ready
  41.         //return ( U0LSR & 0x01 );        //Receive data ready
  42. }

  43. /*----------------------------------------------------------------------------
  44. * end of file
  45. *---------------------------------------------------------------------------*/

哦.

评分

参与人数 1威望 +1 收起 理由
zjk0728 + 1 赞一个!

查看全部评分

ceac1 发表于 2013-1-11 14:08 | 显示全部楼层
关注一下了
 楼主| zjk0728 发表于 2013-1-11 14:18 | 显示全部楼层
huangxz 发表于 2013-1-11 13:59
lpc23xx跟lpc21xx 很多不一样的哦.

谢谢你的回复和代码,我再试试
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

1

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部