硬汉嵌入式论坛

 找回密码
 立即注册
查看: 2901|回复: 0
收起左侧

[功能实战] H7-TOOL应用实战之出厂批量测试我们的隔离型TTL转RS485/RS232模组

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106749
QQ
发表于 2020-4-14 12:45:13 | 显示全部楼层 |阅读模式
近期分享些H7-TOOL在我们自己的产品中的应用实战,昨天的分享:地址

大大方便了我们工作人员的设备测试:


1、模组:
https://armfly.taobao.com/category-1252243106.htm

1.png

2、出厂测试LUA脚本,直接使用H7-TOOL上位机加载到H7-TOOL即可使用,随时可以更新。也可以脱机存到eMMC里面随时使用。

当前H7-TOOL可以引出两路串口了,一路UART7的TTL,还有RS485/RS232/TTL的三合一复合。

TTL-RS485.lua (2.36 KB, 下载次数: 1)

  1. --F01=自动测试,AutoTestUart()
  2. --F02=单独测试,TestUart()

  3. --成功叫一声,失败叫三声
  4. function TestErr(void)
  5.         print("测试失败")
  6.         beep()
  7.         delayms(100)
  8.         beep()
  9.         delayms(100)
  10.         beep()        
  11. end

  12. function TestOk(void)
  13.         print("测试通过")
  14.         beep()
  15. end

  16. --测试串口硬件功能
  17. function TestUart(void)
  18.         local COM_TTL = 7
  19.         local COM_485 = 1
  20.         local Parity = 0
  21.         local DataBits = 8
  22.         local StopBits = 1
  23.         local tx_str = "H7-TOOL"
  24.         local rx_str
  25.         local rx_len
  26.         local str
  27.         local curr
  28.         local volt
  29.         local ret = "OK"
  30.         
  31.         print("开始测试")
  32.         
  33.         write_reg16(0x01FF,2)
  34.         
  35.         gpio_cfg(0, 5)        -- 配置D0为UART功能
  36.         gpio_cfg(1, 5)        -- 配置D1为UART功能
  37.         
  38.         uart_cfg(COM_TTL, 115200, Parity, DataBits, StopBits)
  39.         uart_cfg(COM_485, 115200, Parity, DataBits, StopBits)

  40.         volt = read_analog(4)
  41.         curr = read_analog(5)
  42.         str = string.format("电压 %0.1fV 电流 %0.1fmA", volt, curr)
  43.         print(str)
  44.         
  45.         --print("RS485 -> TTL")
  46.         uart_send(COM_485, tx_str)
  47.         rx_len, rx_str = uart_recive(COM_TTL, 7, 100)
  48.         if (rx_str == tx_str) then
  49.                 print("RS485 -> TTL : OK")
  50.         else
  51.                 print("RS485 -> TTL : ERROR")
  52.                 ret = "ERROR"
  53.                 goto quit_err
  54.         end

  55.         --print("测试   TTL -> RS485")
  56.         uart_send(COM_TTL, tx_str)
  57.         rx_len, rx_str = uart_recive(COM_485, 7, 100)
  58.         if (rx_str == tx_str) then
  59.                 print("TTL -> RS485 : OK")
  60.         else
  61.                 print("TTL -> RS485 : ERROR")
  62.                 ret = "ERROR"
  63.                 goto quit_err
  64.         end

  65. ::quit_err::
  66.         if (ret == "OK") then
  67.                 TestOk()
  68.         else
  69.                 TestErr()
  70.         end
  71.         
  72.         return ret
  73. end

  74. --插入后自动测试
  75. function AutoTestUart(void)

  76.         local now_curr = 0
  77.         local count = 0
  78.         local inserted = 0
  79.         local key
  80.         
  81.         print("测试 RS485 -> TTL")
  82.         
  83.         write_reg16(0x01FF, 2)        --ADC切换到低速多通道扫描模式
  84.         while(1)
  85.         do
  86.                 now_curr = read_analog(5)
  87.                
  88.                 if (inserted == 0) then
  89.                         if (now_curr > 20) then
  90.                                 delayms(50)
  91.                                 TestUart()
  92.                                 inserted = 1
  93.                                 count = count + 1
  94.                                 print("已测试", count)
  95.                         end
  96.                 else
  97.                         if (now_curr < 5) then
  98.                                 inserted = 0
  99.                         end
  100.                 end
  101.                
  102.                 delayms(100)
  103.             
  104.             --按任意键退出循环
  105.             key = get_key()
  106.             if (key > 0) then
  107.                     return
  108.             end
  109.             
  110.         end
  111. end

  112. --测试GPIO功能,D0和D1短接后测试可通过
  113. function TestGPIO(void)
  114.         local y
  115.         local err = 0
  116.         
  117.         print("")
  118.         print("测试GPIO")
  119.         
  120.         gpio_cfg(0, 1)
  121.         gpio_cfg(1, 0)

  122.         -- D0 = 0
  123.         gpio_write(0, 0)
  124.         delayms(100)        
  125.         y = gpio_read(1)         
  126.         if (y ~= 0) then
  127.                 err = err + 1
  128.         end

  129.         -- D0 = 1
  130.         gpio_write(0, 1)
  131.         delayms(100)        
  132.         y = gpio_read(1)         
  133.         if (y ~= 1) then
  134.                 err = err + 1
  135.         end        
  136.                                 
  137.         if (err == 0) then
  138.                 TestOk()
  139.         else
  140.                 TestErr()
  141.         end
  142. end
复制代码



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-4 07:59 , Processed in 0.171757 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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