查看: 3430|回复: 4

[原创] K60 UART模块的半双工模式

[复制链接]
  • TA的每日心情
    开心
    2018-8-30 16:02
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    36

    主题

    1065

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    1851
    最后登录
    2019-11-19
    发表于 2015-9-13 21:09:52 | 显示全部楼层 |阅读模式
        今天看参考手册,发现UART模块可以支持半双工模式,如下图所说:
    捕获.PNG
    发送端的引脚可以作为发送也可作为接收。
    但我不明白的是,它是怎么保证发送的时候数据不被接收端接收?
    还有一种是循环模式,内部将发送端接到接收端:
    捕获1.PNG
    这个倒是可以理解。
    哎...今天够累的,签到来了~
    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    2017-5-3 11:19
  • 签到天数: 10 天

    连续签到: 1 天

    [LV.3]偶尔看看II

    50

    主题

    1万

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    14090
    最后登录
    2024-4-19
    发表于 2015-9-13 21:40:37 | 显示全部楼层
    回贴送金币吗? null.png null1.png null2.png null3.png null4.png null5.png null6.png null7.png null8.png null9.png
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    61

    主题

    965

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    2394
    最后登录
    1970-1-1
    发表于 2015-9-13 22:24:44 | 显示全部楼层

    送1个        
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2018-8-30 16:02
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    36

    主题

    1065

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    1851
    最后登录
    2019-11-19
     楼主| 发表于 2015-9-13 22:26:59 | 显示全部楼层

    额,特派员怎么阔以这样。。
    哎...今天够累的,签到来了~
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    124

    主题

    3600

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    5781
    最后登录
    1970-1-1
    发表于 2015-9-14 09:48:11 | 显示全部楼层
    本帖最后由 FSL_TICS_ZP 于 2015-9-14 11:04 编辑

    半双工也是串口的支持通信之一,通信原理建立楼主可以去度娘一下,例程代码分享如下:


    1. int uart_single_wire_test()
    2. {
    3.     UART_MemMapPtr module1, module2;
    4.     char ch;
    5.     int error = 0;

    6.     printf("\n\nStarting setup for UART single wire mode tests.\n");

    7.     /* Determine which UART to use as module1 for testing. UART2 or UART3
    8.      * could be used. We'll use UART2 as long as it isn't used as the TERM_PORT.
    9.      */

    10.   
    11.        module1 = UART1_BASE_PTR;   // set the module pointer

    12.       printf("\nUsing UART1 on the daughter card as module1.\n");


    13.     /* Determine which UART to use as module2 for testing. UART4 or UART5
    14.      * could be used. We'll use UART4 as long as it isn't used as the TERM_PORT.
    15.      */
    16.          
    17.        module2 = UART3_BASE_PTR;   // set the module pointer

    18.     printf("\nUsing UART3 on the daughter card as module2.\n");
    19.    
    20.     printf("Setup complete. Starting UART single wire mode tests...\n");

    21.    
    22.     /* Configure both UARTs for single wire mode */
    23.   //  UART_C1_REG(module1) |= (UART_C1_LOOPS_MASK | UART_C1_RSRC_MASK);
    24. //   UART_C1_REG(module2) |= (UART_C1_LOOPS_MASK | UART_C1_RSRC_MASK);

    25.     /* Test sending data from module1 to module2 */
    26.    
    27.     /* Configure the module1 TXD pin as an output */
    28.     UART_C3_REG(module1) |= UART_C3_TXDIR_MASK;
    29.         /*
    30.         //²âÊÔ·¢ËÍ
    31.         while(1)
    32.         {
    33.                 uart_putchar(module1,0x01);
    34.         }
    35.         */
    36.         
    37.         /*
    38.         //²âÊÔʹÓÃ:PC·¢Ë͸øUART3,uart3½«½ÓÊÕµÄÊý¾Ýͨ¹ýuart1»áËÍPC
    39.         while(1)
    40.         {
    41.                   ch = uart_getchar(module2);
    42.                    uart_putchar(module1,ch );
    43.         
    44.         }
    45.         */
    46.     uart_putchar(module1,0x01);

    47.     /* Get the received data from module2 */
    48.     ch = uart_getchar(module2);
    49.    
    50.     /* Test to make sure the data matches */
    51.     if( ch != 0x01)
    52.     {
    53.         error++;
    54.         printf("\nERR! Incorrect data received. Expected: 0xAA Recieved: 0x%02X", ch);
    55.     }
    56.    
    57.     /* Make sure that module1 ignored the data (since it sent it) */
    58.     if( uart_getchar_present(module1) )
    59.     {
    60.         error++;
    61.         printf("\nERR! Data received on module1 when only module2 should have received.");
    62.     }
    63.       

    64.     /* Test sending data from module2 to module1 */
    65.    
    66.     /* Configure the module1 TXD pin as an input */
    67.     UART_C3_REG(module1) &= ~UART_C3_TXDIR_MASK;
    68.    
    69.     /* Configure the module2 TXD pin as an output */
    70.     UART_C3_REG(module2) |= UART_C3_TXDIR_MASK;   
    71.    
    72.     uart_putchar(module2,0x55);
    73.    
    74.     /* Get the received data from module1 */
    75.     ch = uart_getchar(module1);
    76.    
    77.     /* Test to make sure the data matches */
    78.     if( ch != 0x55)
    79.     {
    80.         error++;
    81.         printf("\nERR! Incorrect data received. Expected: 0x55 Recieved: 0x%02X", ch);
    82.     }
    83.    
    84.     /* Make sure that module2 ignored the data (since it sent it) */
    85.     if( uart_getchar_present(module2) )
    86.     {
    87.         error++;
    88.         printf("\nERR! Data received on module2 when only module1 should have received.");
    89.     }
    90.    

    91.     /* Clear TXDIR for both UARTs */
    92.     UART_C3_REG(module1) &= ~UART_C3_TXDIR_MASK;
    93.     UART_C3_REG(module2) &= ~UART_C3_TXDIR_MASK;

    94.     /* Disable single wire mode for both UARTs*/
    95. //   UART_C1_REG(module1) &= ~(UART_C1_LOOPS_MASK | UART_C1_RSRC_MASK);
    96.   //  UART_C1_REG(module2) &= ~(UART_C1_LOOPS_MASK | UART_C1_RSRC_MASK);
    97.     printf(" -------------------------endUART single wire mode tests-------------------------\n");



    98.     return error;   
    99. }     
    复制代码


    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-7-28 17:36 , Processed in 0.089943 second(s), 24 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

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