zhanghaijason
Posts: 83
Joined: Tue Sep 29, 2015 9:23 pm

About serial of raspi

Fri Oct 30, 2015 4:47 pm

Hello, I tried Gordon's example code serialTest.c to test my serial. But it only worked once and the output is ''-1 -> -1 ->-1 ->-1 ->-1 ->-1 ->-1 ->-1 ->-1 ->-1 ->" something like that. But only worked once. Then when I run 'sudo ./serialTest', there is no output on the screen. Could anyone give me any suggestion to solve it?
Thanks and regards

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: About serial of raspi

Fri Oct 30, 2015 6:40 pm

zhanghaijason wrote:Could anyone give me any suggestion to solve it?
Probably not without some basic facts to start from...

For example -

What Operating System have you installed?

Who is Gordon?

Where did you download serialTest.c?

What hardware and cabling are you using to create a serial port connection?

zhanghaijason
Posts: 83
Joined: Tue Sep 29, 2015 9:23 pm

Re: About serial of raspi

Fri Oct 30, 2015 7:48 pm

B.Goode wrote:
zhanghaijason wrote:Could anyone give me any suggestion to solve it?
Probably not without some basic facts to start from...

For example -

What Operating System have you installed?

Who is Gordon?

Where did you download serialTest.c?

What hardware and cabling are you using to create a serial port connection?
Sorry that I gave too little information.
OS is NOOBS, Gordon is the person who writing a library named wiringPi in C. the serialTest.c is from the library's examples. I just connected the TXD and RXD of the raspberry A+

User avatar
jlopez2022
Posts: 23
Joined: Fri Oct 30, 2015 9:42 am
Location: Alcobendas, Spain

Re: About serial of raspi

Fri Oct 30, 2015 8:09 pm

Did you give some time delay between write and read at the port?
The writing speed of the port is not unlimited, so perhaps you tried to read before words are written :)

User avatar
DougieLawson
Posts: 39300
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: About serial of raspi

Fri Oct 30, 2015 8:31 pm

Have you disabled the serial console on /dev/ttyAMA0? There's an option in sudo raspi-config to do that.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

zhanghaijason
Posts: 83
Joined: Tue Sep 29, 2015 9:23 pm

Re: About serial of raspi

Fri Oct 30, 2015 9:02 pm

jlopez2022 wrote:Did you give some time delay between write and read at the port?
The writing speed of the port is not unlimited, so perhaps you tried to read before words are written :)
Yes, there is a 'delay' in the codes. I think it's not this reason

zhanghaijason
Posts: 83
Joined: Tue Sep 29, 2015 9:23 pm

Re: About serial of raspi

Fri Oct 30, 2015 9:04 pm

DougieLawson wrote:Have you disabled the serial console on /dev/ttyAMA0? There's an option in sudo raspi-config to do that.
Thanks for your reply first. It worked once again and continued to fail. I guess it may be the enable and disable serial console. But even I enabled the serial console as you told me. It still failed.

User avatar
DougieLawson
Posts: 39300
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: About serial of raspi

Fri Oct 30, 2015 9:58 pm

The usual cause of serial comms failures is mis-matched baud rates. Make sure you've got the same baud rate at both ends and 8,N,1 for bits, parity and stop bits. It's a good idea to start with 9600,8,N,1 as most equipment can run at that speed.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

zhanghaijason
Posts: 83
Joined: Tue Sep 29, 2015 9:23 pm

Re: About serial of raspi

Sun Nov 01, 2015 5:49 pm

DougieLawson wrote:The usual cause of serial comms failures is mis-matched baud rates. Make sure you've got the same baud rate at both ends and 8,N,1 for bits, parity and stop bits. It's a good idea to start with 9600,8,N,1 as most equipment can run at that speed.
I figured out that there is something wrong with my SD card. I tried a new one and it worked. Thank you again.

Return to “Beginners”