|
firefly上使用python操作串口
发表于 2015-1-7 09:59:34
浏览:10619
|
回复:2
打印
只看该作者
[复制链接]
楼主
1.前期准备
Firefly-RK3288(以下简称FR)烧写的是单ubuntu 14.04系统,开发板上的uart1使用官方的USB转TTL 串口模块连上PC
PC上使用C-Kermit配置好参数,速度设置为9600
2.内核开启uart1
--- a/kernel/arch/arm/boot/dts/firefly-rk3288.dts
+++ b/kernel/arch/arm/boot/dts/firefly-rk3288.dts
@@ -404,6 +404,13 @@
pinctrl-0 = <&uart0_xfer &uart0_cts>;
};
+&uart_bb {
+ status = "okay";
+ dma-names = "!tx", "!rx";
+ pinctrl-0 = <&uart1_xfer &uart1_cts>;
+};
+
+
&i2c0 {
status = "okay";
rk808: rk808@1b {
编译内核后单独烧写resource.img,重启后可以看到设备/dev/ttyS1
3.FR上Ubuntu安装python-serial:
sudo apt-get install python-serial
4.python验证uart收发,需要sudo执行:
firefly@firefly:~/test$ sudo python
Python 2.7.6 (default, Mar 22 2014, 23:30:12)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> ser = serial.Serial("/dev/ttyS1", 9600)
>>> count = ser.inWaiting()
>>> count
32
>>> ser.read(count) #读取PC上发送的数据
'firefly python serial read test\n'
>>>
>>> ser.write("firefly python serial write test") #发送数据到PC上
32
收发正常:victory:
5.完整测试文件uart_fr.py:
# -*- coding: utf-8 -*
import serial
import time
# 打开串口
ser = serial.Serial("/dev/ttyS1", 9600)
ser.write("***********firefly python serial************\r\n")
def main():
while True:
# 获得接收缓冲区字符
count = ser.inWaiting()
if count != 0:
# 读取内容并回显
recv = ser.read(count)
ser.write(recv)
# 清空接收缓冲区
ser.flushInput()
# 必要的软件延时
time.sleep(0.1)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
if ser != None:
ser.close()
6.执行:sudo python uart_fr.py
参考:http://blog.csdn.net/xukai871105/article/details/22713925
|
|