Page 1 of 1

Serial Communication Question

Posted: Mon Jun 13, 2016 3:48 pm
by TrickyT
First of all, sorry if this is answered somewhere else and I'm just repeating...I likely am, but I don't understand half of what I'm reading at this point, so I most likely missed it entirely. I'm not a coding/development guy, but I've been tasked with trying to make this work, since I'm the only one in my office that can actually spell the word computer, much less make one work. Once again, sorry in advance.

I have a device that I need to communicate via serial UART with in hex. I can only communicate at 3.3 VDC levels, so the Pi looks like a good option. Most things I'm seeing just specify a RX, TX, and GND connection on the GPIO header, but I also need a 3.3 VDC RTS, or "Handshake" line. The communication I'm trying to do basically goes:

1). Pi is monitoring the peripheral, any serial data that comes from the device is put up on screen.
2). I type a data string to transmit and press enter.
3). The Pi raises the "Handshake" line.
4). The Pi sends the serial data.
5). The Pi waits for an acknowledgement response to the command and displays it once received.
5). The Pi lowers the "Handshake" line.
6). The Pi goes back to monitoring.

Am I missing a program/configuration to do this with the Pi? Or do I need to look elsewhere?

Re: Serial Communication Question

Posted: Mon Jun 13, 2016 5:08 pm
by cacti
You first need to enable Serial communication. Here is a guide that will get you started.

http://www.instructables.com/id/Read-an ... pberry-Pi/

Re: Serial Communication Question

Posted: Mon Jun 13, 2016 5:47 pm
by rzusman
Generally, you can ignore the handshake line.
It's a holdover from the days when processors were really, really slow. Now, with interrupt-driven I/O, the Pi can keep up with the input data. So, just set the RTS line high, and capture the data as in comes in.

Re: Serial Communication Question

Posted: Mon Jun 13, 2016 5:49 pm
by TrickyT
The handshake isn't for the Pi, it's for the peripheral. The Pi is the "Master" unit, but it has to set the "Handshake" line high or the "Slave" unit will ignore it. Not my design, I wish it wasn't set up that way, because I think that's going to make my life miserable...

Re: Serial Communication Question

Posted: Mon Jun 13, 2016 5:52 pm
by TrickyT
Cacti:

OK, that covers enabling the software, and I understand the UART TX and RX on the GPIO are 3.3VDC, and the GND pin speaks for itself, but which pin can I use for the 3.3VDC handshake?

Re: Serial Communication Question

Posted: Mon Jun 13, 2016 6:06 pm
by cacti
You can use any general purpose GPIO pin. For example to use GPIO2 (pin 3).

To switch GPIO2 high (3.3v) do the following:

$ sudo python
>>> import RPi.GPIO as GPIO
>>> GPIO.setup(2, GPIO.OUT)
>>> GPIO.output(2, True)

Re: Serial Communication Question

Posted: Mon Jun 13, 2016 6:17 pm
by cacti
I'm not sure which RPi board you are using. Check this out for differences and a short tutorial on GPIO in Python.

http://www.raspberrypi-spy.co.uk/2012/0 ... -and-pins/

Re: Serial Communication Question

Posted: Mon Jun 13, 2016 6:21 pm
by Cancelor
TrickyT wrote:The handshake isn't for the Pi, it's for the peripheral. The Pi is the "Master" unit, but it has to set the "Handshake" line high or the "Slave" unit will ignore it. Not my design, I wish it wasn't set up that way, because I think that's going to make my life miserable...
Sounds like you can just connect it to the 3.3v pin and forget about it but if it really needs to be raised and lowered then a GPIO pin will do the trick.

Re: Serial Communication Question

Posted: Mon Jun 13, 2016 6:23 pm
by TrickyT
Cancelor wrote:
TrickyT wrote:The handshake isn't for the Pi, it's for the peripheral. The Pi is the "Master" unit, but it has to set the "Handshake" line high or the "Slave" unit will ignore it. Not my design, I wish it wasn't set up that way, because I think that's going to make my life miserable...
Sounds like you can just connect it to the 3.3v pin and forget about it.
No, the device doesn't actually carry out the command until the handshake line is set low.

Re: Serial Communication Question

Posted: Mon Jun 13, 2016 6:24 pm
by TrickyT
cacti wrote:I'm not sure which RPi board you are using. Check this out for differences and a short tutorial on GPIO in Python.

http://www.raspberrypi-spy.co.uk/2012/0 ... -and-pins/
This is going to be very helpful, as I'm probably going to have to write some python for several parts of this solution.

Re: Serial Communication Question

Posted: Mon Jun 13, 2016 6:26 pm
by TrickyT
cacti wrote:You can use any general purpose GPIO pin. For example to use GPIO2 (pin 3).

To switch GPIO2 high (3.3v) do the following:

$ sudo python
>>> import RPi.GPIO as GPIO
>>> GPIO.setup(2, GPIO.OUT)
>>> GPIO.output(2, True)
GPIO2 is Pin 3 on my board....Would that output a 3.3V signal or a 5V signal?

Re: Serial Communication Question

Posted: Mon Jun 13, 2016 6:27 pm
by cacti
Cancelor wrote:
TrickyT wrote:The handshake isn't for the Pi, it's for the peripheral. The Pi is the "Master" unit, but it has to set the "Handshake" line high or the "Slave" unit will ignore it. Not my design, I wish it wasn't set up that way, because I think that's going to make my life miserable...
Sounds like you can just connect it to the 3.3v pin and forget about it but if it really needs to be raised and lowered then a GPIO pin will do the trick.
I don't think the external device will send any data while the handshake line is high (in step 1).

Re: Serial Communication Question

Posted: Mon Jun 13, 2016 6:31 pm
by cacti
TrickyT wrote:
cacti wrote:You can use any general purpose GPIO pin. For example to use GPIO2 (pin 3).

To switch GPIO2 high (3.3v) do the following:

$ sudo python
>>> import RPi.GPIO as GPIO
>>> GPIO.setup(2, GPIO.OUT)
>>> GPIO.output(2, True)
GPIO2 is Pin 3 on my board....Would that output a 3.3V signal or a 5V signal?
All the GPIO pins will output 3.3v for a logical high.

Re: Serial Communication Question

Posted: Mon Jun 13, 2016 6:32 pm
by TrickyT
cacti wrote:
Cancelor wrote:
TrickyT wrote:The handshake isn't for the Pi, it's for the peripheral. The Pi is the "Master" unit, but it has to set the "Handshake" line high or the "Slave" unit will ignore it. Not my design, I wish it wasn't set up that way, because I think that's going to make my life miserable...
Sounds like you can just connect it to the 3.3v pin and forget about it but if it really needs to be raised and lowered then a GPIO pin will do the trick.
I don't think the external device will send any data while the handshake line is high.
While the handshake line is high, the device pauses its actual work and listens for a command. Once it receives that command, it replies with an acknowledgment and checksum, and then waits for further commands if the checksum was incorrect. If the "Master" device agrees that the acknowledgement is correct, it sets the handshake low, at which point the device executes the command it was given.

Re: Serial Communication Question

Posted: Mon Jun 13, 2016 6:44 pm
by cacti
TrickyT wrote:While the handshake line is high, the device pauses its actual work and listens for a command. Once it receives that command, it replies with an acknowledgment and checksum, and then waits for further commands if the checksum was incorrect. If the "Master" device agrees that the acknowledgement is correct, it sets the handshake low, at which point the device executes the command it was given.
Using the above info you will be able to get it working. Good luck and enjoy :)