使用uart.alt(1)时UART数据错误 [英] UART data error when using uart.alt(1)

查看:177
本文介绍了使用uart.alt(1)时UART数据错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从连接到ESP8266的设备获取rs232数据(然后将通过http/wifi将数据发送给我们).

I am trying to acquire rs232 data from a device connected to the ESP8266 (data will then be sent our via http/wifi).

我正在使用max3232 IC为ESP8266提供必要的3.3v TTL.

I am using max3232 IC to provide the necessary 3.3v TTL to the ESP8266.

我已将max3232(引脚12)连接到ESP8266的GPIO引脚13(rx)(我仅接收数据但不发送数据,因此仅连接了rx引脚).

I have have connected the max3232 (pin 12) to GPIO pin 13 (rx) on the ESP8266 (I am only receiving data not sending data, so only the rx pin is connected).

我正在使用的代码:

--
--file: test2.lua 
--
tst2 = require "tst2"
tst2.start()


--tst2.lua (testing script)
local module = {}

function module.start()
    print("in tst2.start")
    uart.alt(1)         --use alt GPIO pin 13 (Rx)
    uart.setup(0, 9600,8, uart.PARITY_NONE, uart.STOPBITS_1,0)
    uart.on("data",10, 
        function(data) 
            file.open("data.tmp", "w+")
            file.writeline("starting")
            for i=1,10 do
                 file.writeline(string.byte(string.sub(data,i,i)) )
            end
            file.writeline("from uart: ", data)
            file.writeline("finished")
            file.close()
    end, 0)
    uart.alt(0)         --switch back to standard Rx/Tx pins
end
return module

连接到ESP8266的rs232设备每3秒发出一个字母字符,但是写入文件(data.tmp)的数据如下所示:

The rs232 device connected to the ESP8266 is putting out a single alphabetic character every 3 seconds, however the data written to file (data.tmp) is as follows

starting
10
13
10
13
10
13
10
13
10
13
from uart: 
finished
file.close()

问题:

1- rs232设备没有发出任何newln或cr字符,但是这些字符出现在数据文件中.

1- The rs232 device is not issuing any newln or cr characters, but these are appearing in the data file.

2-字符串"file.close()"正在写入数据文件,看起来像是最终file.writeline命令后面的实际lua命令.

2- the string "file.close()" is being written to the data file, and looks like it is the actual lua command that follows the final file.writeline command.

3-字母数据没有出现在数据文件中.

3- the alphabetic data is not appearing in the data file.

4-无法通过uart.alt(0)切换回标准uart引脚(ESP8266必须重新启动-这不是主要问题,因为标准uart引脚仅在调试期间使用).

4- switching back to the standard uart pins via uart.alt(0) does not work (the ESP8266 must be rebooted - this is not a major issue as the standard uart pins are only used during debugging).

我将rs232数据写入文件中,而不是简单地在屏幕上打印出来(我正在使用ESPlorer v0.2.0),因为uart.alt(1)命令将串行端口重定向到备用ESP8266 gpio引脚.

I am writing the rs232 data to a file instead of simply printing it out on the screen (I am using ESPlorer v0.2.0) because the uart.alt(1) command redirects the serial port to the alternative ESP8266 gpio pins.

我认为我在设置uart上犯了一些根本性的错误,但我不知道它是什么.

I think I am doing something fundamentally wrong with the uart set up, but i can't tell what it is.

推荐答案

已解决:

看来您无法同时将ESP8266连接到用于调试的串行端口(例如,运行ESPlorer的PC上的串行端口),也无法将备用串行引脚(ESP8266 GPIO 13和15)连接到(外部)串行设备).

It appears that you can't connect the ESP8266 to both the serial port for debugging (e.g. the serial port on a pc running ESPlorer) and also have the alternate serial pins (ESP8266 GPIO 13 and 15) connected (to an external serial device) at the same time.

nodemcu uart.alt()函数似乎无法关闭"标准串行I/O引脚.

The nodemcu uart.alt() function does not appear to "turn off" the standard serial i/o pins.

断开PC与标准串行I/O引脚的连接即可解决此问题(调试成为一个问题,但是有解决方法来解决此问题.)

Disconnecting the pc from the standard serial i/o pins solved the problem (debugging becomes an issue, but there are work-arounds to resolve this).

这篇关于使用uart.alt(1)时UART数据错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆