TrickyT
Posts: 7
Joined: Mon Jun 13, 2016 3:32 pm

Serial Communication Question

Mon Jun 13, 2016 3:48 pm

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?

cacti
Posts: 56
Joined: Fri Feb 01, 2013 6:52 pm

Re: Serial Communication Question

Mon Jun 13, 2016 5:08 pm

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/

rzusman
Posts: 347
Joined: Fri Jan 01, 2016 10:27 pm

Re: Serial Communication Question

Mon Jun 13, 2016 5:47 pm

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.

TrickyT
Posts: 7
Joined: Mon Jun 13, 2016 3:32 pm

Re: Serial Communication Question

Mon Jun 13, 2016 5:49 pm

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...

TrickyT
Posts: 7
Joined: Mon Jun 13, 2016 3:32 pm

Re: Serial Communication Question

Mon Jun 13, 2016 5:52 pm

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?

cacti
Posts: 56
Joined: Fri Feb 01, 2013 6:52 pm

Re: Serial Communication Question

Mon Jun 13, 2016 6:06 pm

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)

cacti
Posts: 56
Joined: Fri Feb 01, 2013 6:52 pm

Re: Serial Communication Question

Mon Jun 13, 2016 6:17 pm

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/

User avatar
Cancelor
Posts: 778
Joined: Wed Aug 28, 2013 4:09 pm
Location: UK

Re: Serial Communication Question

Mon Jun 13, 2016 6:21 pm

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.
Last edited by Cancelor on Mon Jun 13, 2016 6:25 pm, edited 1 time in total.
Can't find the thread you want? Try googling : YourSearchHere site:raspberrypi.org

TrickyT
Posts: 7
Joined: Mon Jun 13, 2016 3:32 pm

Re: Serial Communication Question

Mon Jun 13, 2016 6:23 pm

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.

TrickyT
Posts: 7
Joined: Mon Jun 13, 2016 3:32 pm

Re: Serial Communication Question

Mon Jun 13, 2016 6:24 pm

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.

TrickyT
Posts: 7
Joined: Mon Jun 13, 2016 3:32 pm

Re: Serial Communication Question

Mon Jun 13, 2016 6:26 pm

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?

cacti
Posts: 56
Joined: Fri Feb 01, 2013 6:52 pm

Re: Serial Communication Question

Mon Jun 13, 2016 6:27 pm

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).

cacti
Posts: 56
Joined: Fri Feb 01, 2013 6:52 pm

Re: Serial Communication Question

Mon Jun 13, 2016 6:31 pm

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.

TrickyT
Posts: 7
Joined: Mon Jun 13, 2016 3:32 pm

Re: Serial Communication Question

Mon Jun 13, 2016 6:32 pm

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.

cacti
Posts: 56
Joined: Fri Feb 01, 2013 6:52 pm

Re: Serial Communication Question

Mon Jun 13, 2016 6:44 pm

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 :)

Return to “Interfacing (DSI, CSI, I2C, etc.)”