天嵌 ARM开发社区

 找回密码
 注册
查看: 3758|回复: 2

TQ210 裸机UART0 只能发送不能接受,求教是神马情况

[复制链接]
demonguy 发表于 2014-10-3 20:29:33 | 显示全部楼层 |阅读模式
本帖最后由 demonguy 于 2014-10-3 20:39 编辑

我自己写了一段TQ210板子的串口0裸机驱动,但是不知道为什么,PC上可以接受到板子发过来的数据,但是怎么板子怎么都接受不到PC传过去的数据,请问是啥情况?我自己也试过,非常的确定他就是卡在 while (!(UTRSTAT0 & (1 << 2)));      
  1. #define GPC0CON                *((volatile unsigned int *)0xE0200060)
  2. #define GPC0DAT                *((volatile unsigned int *)0xE0200064)

  3. int main() __attribute__((section(".main")));

  4. int main()
  5. {
  6.         unsigned char c;
  7.         uart_init();
  8.         
  9.         GPC0CON &= ~(0xFF << 12);
  10.         GPC0CON |= 0x11 << 12;                // 配置GPC0_3和GPC0_4为输出
  11.         GPC0DAT &= ~(0x3 << 3);                // 熄灭LED1和LED2

  12.         puts("UART Test in S5PV210");
  13.         puts("1.LED1 Toggle");
  14.         puts("2.LED2 Toggle");
  15.         puts("Please select 1 or 2 to Toggle the LED");
  16.         // putchar('1');
  17.         
  18.         while (1)
  19.         {
  20.                 c = getchar();                        // 从串口终端获取一个字符
  21.                 putchar(c);                                // 回显
  22.                 putchar('\r');

  23.                 if (c == '1')
  24.                         GPC0DAT ^= 1 << 3;        // 改变LED1的状态
  25.                 else if (c == '2')
  26.                         GPC0DAT ^= 1 << 4;        // 改变LED2的状态
  27.         }
  28.         return 0;
  29. }
复制代码

  1. #define GPA0CON                *((volatile unsigned int *)0xE0200000)
  2. #define ULCON0                 *((volatile unsigned int *)0xE2900000)
  3. #define UCON0                 *((volatile unsigned int *)0xE2900004)
  4. #define UFCON0                 *((volatile unsigned int *)0xE2900008)
  5. #define UTRSTAT0         *((volatile unsigned int *)0xE2900010)
  6. #define UTXH0                  *((volatile unsigned int *)0xE2900020)
  7. #define URXH0                 *((volatile unsigned int *)0xE2900024)
  8. #define UBRDIV0         *((volatile unsigned int *)0xE2900028)
  9. #define UDIVSLOT0        *((volatile unsigned int *)0xE290002C)



  10. // #define GPA0CON                *((volatile unsigned int *)0xE0200000)
  11. // #define ULCON0                 *((volatile unsigned int *)0xE2900400)
  12. // #define UCON0                 *((volatile unsigned int *)0xE2900404)
  13. // #define UFCON0                 *((volatile unsigned int *)0xE2900408)
  14. // #define UTRSTAT0         *((volatile unsigned int *)0xE2900410)
  15. // #define UTXH0                  *((volatile unsigned int *)0xE2900420)
  16. // #define URXH0                 *((volatile unsigned int *)0xE2900424)
  17. // #define UBRDIV0         *((volatile unsigned int *)0xE2900428)
  18. // #define UDIVSLOT0        *((volatile unsigned int *)0xE290042C)


  19. /* UART0初始化 */
  20. void uart_init()
  21. {
  22.         /*
  23.         ** 配置GPA0_0为UART_0_RXD
  24.         ** 配置GPA0_1为UART_0_TXD
  25.         */
  26.         GPA0CON &= ~0xFF;
  27.         GPA0CON |= 0x22;

  28.         GPA0CON &= ~(0xFF<<16);
  29.         GPA0CON |= (0x22<<16);

  30.         /* 8-bits/One stop bit/No parity/Normal mode operation */
  31.         ULCON0 = 0x3;

  32.         /* Interrupt request or polling mode/Normal transmit/Normal operation/PCLK/*/
  33.         UCON0 = 0x5;//1 | (1 << 2) ;//| (1<<5);

  34.         /* 静止FIFO */
  35.         UFCON0 = 0;

  36.         /*
  37.         ** 波特率计算:115200bps
  38.         ** PCLK = 66MHz
  39.         ** DIV_VAL = (66000000/(115200 x 16))-1 = 35.8 - 1 = 34.8
  40.         ** UBRDIV0 = 34(DIV_VAL的整数部分)
  41.         ** (num of 1's in UDIVSLOTn)/16 = 0.8
  42.         ** (num of 1's in UDIVSLOTn) = 12
  43.         ** UDIVSLOT0 = 0xDDDD (查表)
  44.         */
  45.         UBRDIV0 = 34;
  46.         UDIVSLOT0 = 0xDDDD;
  47. }

  48. void putchar(unsigned char c);

  49. static void uart_send_byte(unsigned char byte)
  50. {
  51.         while (!(UTRSTAT0 & (1 << 2)));        /* 等待发送缓冲区为空 */
  52.         UTXH0 = byte;                                        /* 发送一字节数据 */               
  53. }

  54. static unsigned char uart_recv_byte()
  55. {
  56.         while (!(UTRSTAT0 & 1));                /* 等待接收缓冲区有数据可读 */
  57.         return URXH0;                                        /* 接收一字节数据 */               
  58. }

  59. void putchar(unsigned char c)
  60. {
  61.         uart_send_byte(c);
  62.         /* 如果只写'\n',只是换行,而不会跳到下一行开头 */
  63.         if (c == '\n')
  64.                 uart_send_byte('\r');
  65. }

  66. unsigned char getchar()
  67. {
  68.         unsigned char c;
  69.         c = uart_recv_byte();
  70.         return c;
  71. }

  72. void puts(char *str)
  73. {
  74.         char *p = str;
  75.         while (*p)
  76.                 putchar(*p++);
  77.         putchar('\n');
  78. }
复制代码



本帖子中包含更多资源

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

x
四川路人甲 发表于 2018-11-1 22:53:42 | 显示全部楼层
您好!请问您的问题解决了吗?我也遇到相同的问题了,折腾了1天还是没出结果,代码和您的一样的。
四川路人甲 发表于 2018-11-1 23:58:47 | 显示全部楼层
你好!你的问题解决没有呢?我也遇到相同的问题了,UART0能够发送,但是无法接受来自PC的数据,程序和你的一样,调试时发现卡在while (!(UTRSTAT0 & 1));
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-3-29 03:41 , Processed in 1.031257 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表