I'm using Raspberry Pi 2 to realize RS232 communication between raspberry and my laptop. It seems that my Raspberry Pi can send data, but it can get nothing from my laptop. The following information are about what I've done:
I installed a GPIO UART Shield with RS232 on my Raspberry Pi.
Edit the file
/boot/cmdline.txt, and delete the line
console=ttyAMA0, 115200 kgdbooc=ttyAMA0, 115200
Edit the file
/etc/inittab, comment the last sentence:
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
- Installed python-serial module
In Python 2.7 environment, I tried following commands:
import serial ser=serial.Serial("/dev/ttyAMA0", 9600, timeout=5) ser.write("hello")
On a laptop, I ran a RS232 debug tool. In it, I could directly see the characters "hello". Then, I typed "abcde" on my laptop and pressed "send with every 2 seconds". On Raspberry I executed the following command:
The first time, the data was received, but when I executed the command again, third time, fourth time... nothing was received. The following are the commands I tried, but every time I got " '' "
ser.read(10) > '' ser.readall() > '' ser.inWaiting() > 0
But still, I can use
ser.write() to send data. And after send, I can read, but only one time.
Then I gave the python environment, and used minicom, but the situation was same:
As long as I typed any characters in minicom, the data could be sent to my laptop immediately. But when I tried to send data from the laptop, at first time, minicom can display the data, then, nothing, and always nothing.
Could anyone tell me what the problem is?
I found that only after some data was sent by raspberry, it could receive data! I did following tests:
In raspberry, I executed:
>>import serial >>ser=serial.Serial("/dev/ttyAMA0",9600,timeout=1) >>ser.write("a")
On my laptop, I could receive "a", and I sent "abcde" from my laptop. In respberry I could receive "abcde":
Sent "abcde" from laptop again. In raspberry:
>>ser.read(5) '' #Nothing received >>ser.inWaiting() 0 #Nothing received >>ser.write("a") 1 #"a" was sent successfully >>ser.read(5) 'abcde' #Data received!
If I executed
ser.write(""), still, nothing could be received! It seemed that only after data could be sent successfully, raspberry could read the data! Did any one meet the same situation ?