keystone76
Posts: 11
Joined: Wed Jan 10, 2018 1:19 am

Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 3:06 pm

I am working on a project to connect a Mitutoyo Digimatatic (digital) dial gage to a raspberry pi and collect the data from the dial gage. This gage submits the data as serial data in a 52 bit serial format which yields a 13 byte output I can translate using Mitutoyo documentation.

I am stumbling all over myself on this project and am spinning my wheels to get started. So I am going to ask some basic questions in an attempt to get going.

A little background info:
5 pin output cable from gage (1. ground 2. Data 3.Clk 4. Data Request 5.Ready)
I must send a DataRequest in order for the gage to send the Data. (To make the request, just send an ASCII character 1)

I am trying to utilize the TX and RX pins and wire directly to the header pins. I assume the TX (GPIO14) would wire to the Data Request pin and RX (GPIO 15) would wire the Data pin.

But I don't know how to incorporate the clock and whether I even need to. In my research, it looks like the TX and RX pins are part of the UART hardware and by definition do not need a clock if they are asynchronous.

Do I need the clock? If so, what does that look like using python to program/setup the clock pin?

This is just one of many questions I have on this project and would really like to start a conversation around it.

Please help! I'm just a dumb mechanical engineer who is struggling something awful here. Any help is greatly appreciated.
Connector-pinLayout.JPG
Connector-pinLayout.JPG (76.41 KiB) Viewed 967 times

scotty101
Posts: 4100
Joined: Fri Jun 08, 2012 6:03 pm

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 3:39 pm

Sure.

With RS232, there is NO clock pin. The data is sent asynchronously and doesn't use a clock.

Seems like you need more information from the manufacturer of this device.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

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

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 3:42 pm

Just to help you narrow down the possibilities...

An asynchronous connection does not have a Clock signal carried between the two devices.

So, conversely, if the hardware is reliant on a Clock signal to maintain accurate timing for the data transfer then it is using a synchronous connection.


In respect of the TX/Rx pins on the 40-way header of an RPi board, as documented here: https://www.raspberrypi.org/documentati ... on/uart.md

- that documentation refers to the use of those pins as a UART, where that abbreviation is a contraction of 'universal asynchronous receiver/transmitter'. So it may not provide an appropriate interface for your apparently synchronous external device.


(Possible duplicate here of another reply as I was typing this... )


Edit: to add - if the working voltage of that external device is 9 volts, do not connect it directly to any GPIO pin on your RPi, since the latter can only handle 3.3 volts and anything greater risks permanent damage to your RPi.

User avatar
davidcoton
Posts: 5496
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 3:49 pm

There is potentially another serious compatibility issue. The device is using a 9V supply, but what voltage is used on the Data (and Clock) outputs? Pi GPIOs expect 3V3 signal, 9V will probably cause permanent damage to your Pi. (Incidentally even if you have a true RS232 device, the Pi will not tolerate the normal RS232 voltage directly.)

Edit: typed while B.Goode was editing...
Location: 345th cell on the right of the 210th row of L2 cache

drgeoff
Posts: 11232
Joined: Wed Jan 25, 2012 6:39 pm

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 4:33 pm

That dial gauge is NOT using an RS232 interface. It is a custom serial interface. You may need to "bit-bang" it. You'll need more details of the electrical signal timing etc. Things like whether the clock is generated by the gauge or must be supplied to it, which edge of the clock is used etc?
Quis custodiet ipsos custodes?

keystone76
Posts: 11
Joined: Wed Jan 10, 2018 1:19 am

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 4:41 pm

Okay. I do understand everything you all have told me.

So let me introduce a little more background info. The manufacturer has an "Input Tool" which is basically a interface between the 10 pin connector and a serial connector. I was trying to bypass this tool to simplify the wiring being that the pi does not have a serial connection. But after going around and around, I think it will be neccessary (or at least easier) to incorporate it. I do have the tool on hand and have ordered a serial to USB converter that should be here today.

I am attaching a few pages of the manual for this tool.

Tech support at Mitutoyo said "To make the request, just send an ASCII character 1. In the manual example it is a print statement.
The Pi must keep it’s ears on to listen for the data."

I could use some help with the code. I think it should look something like this: ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate = 2400,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_NONE,
bytesize=serial.EIGHTBITS,
timeout=1
)

ser.write(1)
data = ser.read() Surely it cant be this easy...

254_inputTool_specsAndConnections.JPG
254_inputTool_specsAndConnections.JPG (146.75 KiB) Viewed 902 times
254_inputTool_outputAndCommSpecs.JPG
254_inputTool_outputAndCommSpecs.JPG (114.23 KiB) Viewed 902 times
254_inputTool_sampleProgram.JPG
254_inputTool_sampleProgram.JPG (100.95 KiB) Viewed 902 times

keystone76
Posts: 11
Joined: Wed Jan 10, 2018 1:19 am

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 4:46 pm

drgeoff wrote:
Tue Feb 25, 2020 4:33 pm
That dial gauge is NOT using an RS232 interface. It is a custom serial interface. You may need to "bit-bang" it. You'll need more details of the electrical signal timing etc. Things like whether the clock is generated by the gauge or must be supplied to it, which edge of the clock is used etc?
I do not know what "bit banging" is. Mitutoyo has provided a great deal of documentation to me. I just don't have the background to understand all of it.

I do understand how the data is output in 52 bit that creates 13 (4 bit) bytes which I could then extract the information I need if I knew what those 13 bytes were.

I really love this stuff but just don't have a mentor or expert to help me directly when I get stumped. I greatly appreciate all the responses here and the speed with which you guys answer my questions.

drgeoff
Posts: 11232
Joined: Wed Jan 25, 2012 6:39 pm

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 4:56 pm

OK so it is RS232 compatible. But not directly to the GPIO header pins on a RPi. (Don't need bit-banging so you can ignore that.)

You are incorrect about 52 bits. It is 13 ASCII characters each encoded in 8 bits.

2400 baud, 1 start bit, 1 stop bit, no parity.
Quis custodiet ipsos custodes?

scotty101
Posts: 4100
Joined: Fri Jun 08, 2012 6:03 pm

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 5:07 pm

Do you have the "input tool" which they mention?
This shows a d-sub 9 (and RS232) connector rather than the other connector with the clock signal on it.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

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

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 5:14 pm

keystone76 wrote:
Tue Feb 25, 2020 4:46 pm
drgeoff wrote:
Tue Feb 25, 2020 4:33 pm
That dial gauge is NOT using an RS232 interface. It is a custom serial interface. You may need to "bit-bang" it. You'll need more details of the electrical signal timing etc. Things like whether the clock is generated by the gauge or must be supplied to it, which edge of the clock is used etc?
I do not know what "bit banging" is. Mitutoyo has provided a great deal of documentation to me. I just don't have the background to understand all of it.

I do understand how the data is output in 52 bit that creates 13 (4 bit) bytes which I could then extract the information I need if I knew what those 13 bytes were.

I really love this stuff but just don't have a mentor or expert to help me directly when I get stumped. I greatly appreciate all the responses here and the speed with which you guys answer my questions.

The 13 8-bit bytes are documented in the document 254_inputTool_outputAndCommSpecs that you have displayed.

keystone76
Posts: 11
Joined: Wed Jan 10, 2018 1:19 am

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 6:31 pm

B.Goode wrote:
Tue Feb 25, 2020 5:14 pm
keystone76 wrote:
Tue Feb 25, 2020 4:46 pm
drgeoff wrote:
Tue Feb 25, 2020 4:33 pm
That dial gauge is NOT using an RS232 interface. It is a custom serial interface. You may need to "bit-bang" it. You'll need more details of the electrical signal timing etc. Things like whether the clock is generated by the gauge or must be supplied to it, which edge of the clock is used etc?
I do not know what "bit banging" is. Mitutoyo has provided a great deal of documentation to me. I just don't have the background to understand all of it.

I do understand how the data is output in 52 bit that creates 13 (4 bit) bytes which I could then extract the information I need if I knew what those 13 bytes were.

I really love this stuff but just don't have a mentor or expert to help me directly when I get stumped. I greatly appreciate all the responses here and the speed with which you guys answer my questions.

The 13 8-bit bytes are documented in the document 254_inputTool_outputAndCommSpecs that you have displayed.


Here is where I got the 4 bit bytes info.

254_inputTool_52bits.JPG
254_inputTool_52bits.JPG (87.59 KiB) Viewed 820 times
254_inputTool_dataFormat.JPG
254_inputTool_dataFormat.JPG (63.36 KiB) Viewed 834 times
Last edited by keystone76 on Tue Feb 25, 2020 6:37 pm, edited 2 times in total.

keystone76
Posts: 11
Joined: Wed Jan 10, 2018 1:19 am

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 6:35 pm

scotty101 wrote:
Tue Feb 25, 2020 5:07 pm
Do you have the "input tool" which they mention?
This shows a d-sub 9 (and RS232) connector rather than the other connector with the clock signal on it.

I do have the tool and you are correct about the connector. I just received an adapter/converter, link below.

https://www.amazon.com/gp/product/B0769 ... prod_image

I do have several documents from Mitutoyo in pdf format but am unsure if I can attach them to these posts. If interested I can send them to anyone willing to help.

Thanks again

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

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 6:39 pm

I don't see anything about 4-bit 'bytes' in those specs. (Not quoted again here to save bulk.)


But in the document I previously cited it definitely says 8-bits, under the 'communication' heading, bottom right.

drgeoff
Posts: 11232
Joined: Wed Jan 25, 2012 6:39 pm

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 6:46 pm

Two possible modes?

One is RS232 with the normal asynchronous transfer. 2400 baud, 1 start, 8 data, 1 stop.

Another is synchronous. Uses the clock and transfers 52 bits. No start and stop bits.

Maybe the latter one is the native mode and the former is only available when using the Input Tool.
Last edited by drgeoff on Tue Feb 25, 2020 6:49 pm, edited 1 time in total.
Quis custodiet ipsos custodes?

User avatar
rpdom
Posts: 17708
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 6:48 pm

B.Goode wrote:
Tue Feb 25, 2020 6:39 pm
I don't see anything about 4-bit 'bytes' in those specs. (Not quoted again here to save bulk.)


But in the document I previously cited it definitely says 8-bits, under the 'communication' heading, bottom right.
Possibly it is returning 4-bit values as ASCII characters "0" to "9" and "A" to "F"? They would use 8-bit communications. The diagrams seem to show it being connected between the PC and keyboard - a method that used to be used a lot before the days of USB keyboards.
Unreadable squiggle

keystone76
Posts: 11
Joined: Wed Jan 10, 2018 1:19 am

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 6:49 pm

Section 7 states "The measurement data is comprised of 13 digits (fixed length), numbered D1 to D13, each of which is 4 bits wide."

I am about to connect everything with the USB to Serial DB9 adaptor.

Any thoughts as I start down this path?

drgeoff
Posts: 11232
Joined: Wed Jan 25, 2012 6:39 pm

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 6:50 pm

rpdom wrote:
Tue Feb 25, 2020 6:48 pm
The diagrams seem to show it being connected between the PC and keyboard
No, the diagrams don't show or even imply that.
Quis custodiet ipsos custodes?

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

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 6:56 pm

keystone76 wrote:
Tue Feb 25, 2020 6:49 pm
Section 7 states "The measurement data is comprised of 13 digits (fixed length), numbered D1 to D13, each of which is 4 bits wide."

I am about to connect everything with the USB to Serial DB9 adaptor.

Any thoughts as I start down this path?


My only thought is that I would interpret that as meaning that only the least significant 4 bits in each 8-bit byte have any significance for this data transfer protocol.

User avatar
rpdom
Posts: 17708
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 7:48 pm

drgeoff wrote:
Tue Feb 25, 2020 6:50 pm
rpdom wrote:
Tue Feb 25, 2020 6:48 pm
The diagrams seem to show it being connected between the PC and keyboard
No, the diagrams don't show or even imply that.
Look again at the "System Connection Method" pictures. The keyboard is plugged into the "Input Tool", which is then plugged into the PC via a Keyboard cable.
Unreadable squiggle

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5901
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 8:30 pm

You may be able to use GtkTerm (or similar) to capture the raw data and save it to a file for post-processing rather than trying to interpret it "on the fly". Something like what I did for a "free-running" DMM "rs232"-based output:
https://www.cpmspectrepi.uk/raspberry_p ... 000zc.html
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

hippy
Posts: 8529
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 8:31 pm

drgeoff wrote:
Tue Feb 25, 2020 6:46 pm
Two possible modes?

One is RS232 with the normal asynchronous transfer. 2400 baud, 1 start, 8 data, 1 stop.

Another is synchronous. Uses the clock and transfers 52 bits. No start and stop bits.

Maybe the latter one is the native mode and the former is only available when using the Input Tool.
That's my reading of it. Some Mitutoyo products have both while others only offer this 52-bit SPI-like protocol and needs a converter "input tool" to translate between that and RS232 for the PC to receive, and to allow the 'send data' request to be triggered by received RS232.

This datasheet for a slightly different product shows the SPC connections, protocol and timing, page 20 -

https://shop.mitutoyo.eu/pim/upload/mit ... b3_eng.pdf

The data which is output may be different to what that sends in its 52-bits but that's a separate issue to requesting and reading the 52-bits. I would expect the 52-bit data format to be described in the SPC part of the manual the OP has for their product.

The easiest way to perhaps read the data is to use SPI slave input on the Pi. Although 52-bits isn't integer divisible by 8 one could request one set of 52-bits then another, capture all 104-bits as 21 bytes, then decode those.

drgeoff
Posts: 11232
Joined: Wed Jan 25, 2012 6:39 pm

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 8:46 pm

rpdom wrote:
Tue Feb 25, 2020 7:48 pm
drgeoff wrote:
Tue Feb 25, 2020 6:50 pm
rpdom wrote:
Tue Feb 25, 2020 6:48 pm
The diagrams seem to show it being connected between the PC and keyboard
No, the diagrams don't show or even imply that.
Look again at the "System Connection Method" pictures. The keyboard is plugged into the "Input Tool", which is then plugged into the PC via a Keyboard cable.
There are 2 versions of Input Tool.

One ("Input Tool") uses the keyboard input (PS/2) of a PC. The other ("Input Tool for RS-232") uses an RS-232 port of a PC.

Which one does the OP have?
Quis custodiet ipsos custodes?

hippy
Posts: 8529
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Please help me understand the clock pin of Serial RS232 communication

Tue Feb 25, 2020 8:55 pm

drgeoff wrote:
Tue Feb 25, 2020 8:46 pm
There are 2 versions of "Input Tool".
Actually three - RS232, PS/2 and USB.

And incredibly expensive, $300-plus for what can be done with little more than a $1 microcontroller.

keystone76
Posts: 11
Joined: Wed Jan 10, 2018 1:19 am

Re: Please help me understand the clock pin of Serial RS232 communication

Wed Feb 26, 2020 2:00 am

hippy wrote:
Tue Feb 25, 2020 8:55 pm
drgeoff wrote:
Tue Feb 25, 2020 8:46 pm
There are 2 versions of "Input Tool".
Actually three - RS232, PS/2 and USB.

And incredibly expensive, $300-plus for what can be done with little more than a $1 microcontroller.
Hippy,

Please enlighten me on how to utilize the microcontroller to retrieve the data. I am desperate to figure this out.

As for which input tool I have, it's the RS232 version, part number 264-007.

hippy
Posts: 8529
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Please help me understand the clock pin of Serial RS232 communication

Wed Feb 26, 2020 10:37 am

keystone76 wrote:
Wed Feb 26, 2020 2:00 am
Please enlighten me on how to utilize the microcontroller to retrieve the data. I am desperate to figure this out.
As far as I can see all the tool does is wait for a "1" to be received. It then sets the REQ line low and the gage sends 52 negative going clock pulses and associated bit data which the micro would read and then send out via serial

The following is Python code for doing that by bit-banging which could be adapted for whatever micro were being used and whatever programming language it supports. This just sends back 52 "0" and "1" characters each representing the bits received. Turning that into some more meaningful character string could either be done in this micro or by the receiver.

Code: Select all

#     ___                                ___
# REQ    |______________________________|
#     _____   ___   ___   _ _ _ _ _   ______
# CLK      |_|   |_|   |_|         |_|
#          ____ _____ _____ _ _ _ _____
# DAT ----|____|_____|_____|_ _ _|_____|----

SerialOpen()
output(REQ_PIN, 1)
while True:
  rx = SerialRead()
  while rx != "1":
    rx = SerialRead()
  s = ""
  Output(REQ_PIN, 0)
  for n in range(52):
    while Input(CLK_PIN) == 1 : pass
    s = s + chr(0x30 + Input(DAT_PIN))
    while Input(CLK_PIN) == 0 : pass
  output(REQ_PIN, 1)
  SerialSend(s + "\n")
  

Return to “Beginners”