Go Down

Topic: BCD through RS232 (Read 288 times) previous topic - next topic

nubcake

Hello I'm new here,

I am currently working on a project where I need to save the data I get from a Photometer using Arduino so we can graph this after.

The problem I have is that in my datasheet it states on page 5, that there is a BCD output interface using 5V TTL but the port used to connect it is of type RS232-DB9

I looked up some things about RS232 and found out that RS232 usually goes from -13v to 13v with -13V sending a 1 and 13V sending a 0.
This is where I'm a bit confused.
can I hook it up directly on my Arduino or will I still need some kind of shield?

Also I tried hooking it up using a cheap Arduino I didn't use much and ran the serial.read code.
The code is the same as the example code from Arduino.
I wired the ground and TX -> arduino RX and RX -> arduino TX.

The only data I get through is a number between 0-255 and not of BCD value?

I have a picture of the machine with the port in attachment and also the datasheet of the photometer

Thanks for the help in advance,

Kind regards.


Paul_KD7HB

Then your device is working correctly. BCD means each byte that is sent consists of two 4 bit numbers, Each 4 bit pair is called a "nibble", or as the original IBM code written in England called it "nyble". Your program does not know about nibbles, so is using the entire byte as a single binary number.
Search the forum for examples of converting BCD bytes to regular 8-bit numbers so your code can use them.
Paul

nubcake

#2
Feb 22, 2021, 08:38 pm Last Edit: Feb 22, 2021, 08:53 pm by nubcake
Aah Thank you! nice so hooking up directly to Arduino was enough.

But The photometer sends in BCD and the Arduino converts to decimal.
1 byte is 2, 4 bit numbers and represents the 2 7-segment displays on the photometer.
What if there are 6 displays?

Can I assume the 1st byte it sends is the first 2 numbers in BCD, the 2nd byte it sends shows display 3 and 4 and the third byte represents display 5 and 6?
Im quite new at this.



This is the code I used and I only received 1 byte,
Am I right to assume the next byte I receive represents the next two digits? or do I have to use something else than a byte to read everything?


Paul_KD7HB

Aah Thank you! nice so hooking up directly to Arduino was enough.

But The photometer sends in BCD and the Arduino converts to decimal.
1 byte is 2, 4 bit numbers and represents the 2 7-segment displays on the photometer.
What if there are 6 displays?

Can I assume the 1st byte it sends is the first 2 numbers in BCD, the 2nd byte it sends shows display 3 and 4 and the third byte represents display 5 and 6?
Im quite new at this.
I suggest you get more information on the protocol used by the machine. Does it continuously send bytes, or are they combines into messages? How is a message identified and how do you know the end of a message? The BCD data may be imbedded in the message, but the message has special characters in the start of the message and some other special characters to tell you this is the end of the message. Look for documents relating to "protocol".
Paul

nubcake


I suggest you get more information on the protocol used by the machine. Does it continuously send bytes, or are they combines into messages? How is a message identified and how do you know the end of a message? The BCD data may be imbedded in the message, but the message has special characters in the start of the message and some other special characters to tell you this is the end of the message. Look for documents relating to "protocol".
Paul
this is the only document I have been able to find from the machine itself, there was no other document explaining the BCD protocol of the machine :/

Paul_KD7HB

this is the only document I have been able to find from the machine itself, there was no other document explaining the BCD protocol of the machine :/
Comment out both of your Serial.print() and Serial.println().
Add this:
Code: [Select]
Serial.print(incomingByte, HEX);  // print as an ASCII-encoded hexadecimal

Then you can see what is really being sent and possible discover more about the messaging from the device.
Paul

Paul_KD7HB


nubcake

Ah yes sorry for my absence.

For now I had a few problems with the connection because of limited tools/wires and thanks to covid it has been delayed.
Right now im awaiting some new cable/rs232 to TTL converter shield with MAX323.

But I've been thinking. If Arduino converts BCD values to Decimal on the serial monitor, then values like 255 should not be possible? 153 should be the maximum value representing a 9 on 1 segment and 9 on the other or 1001 1001.

On a sidenote, what should the peak voltage be when you measure it on a scope?
I sent the character "o" to the arduino serial monitor and got this

https://ibb.co/CJx99CL


500mV seems awfully low but the signal form seems to be correct

Paul_KD7HB

Ah yes sorry for my absence.

For now I had a few problems with the connection because of limited tools/wires and thanks to covid it has been delayed.
Right now im awaiting some new cable/rs232 to TTL converter shield with MAX323.

But I've been thinking. If Arduino converts BCD values to Decimal on the serial monitor, then values like 255 should not be possible? 153 should be the maximum value representing a 9 on 1 segment and 9 on the other or 1001 1001.

On a sidenote, what should the peak voltage be when you measure it on a scope?
I sent the character "o" to the arduino serial monitor and got this

https://ibb.co/CJx99CL


500mV seems awfully low but the signal form seems to be correct
The largest BCD in a single byte is 99. Anything larger than a 9 is not a BCD. So, you are correct in that. Anything you discover that is greater than 99 is likely to be some protocol indicator, like a message end or ?
Your scope shows a voltage going less than zero! What are you measuring and where?
Paul

nubcake

The largest BCD in a single byte is 99. Anything larger than a 9 is not a BCD. So, you are correct in that. Anything you discover that is greater than 99 is likely to be some protocol indicator, like a message end or ?
Your scope shows a voltage going less than zero! What are you measuring and where?
Paul
I made a simple sketch with 
Serial.println("o"); to send a char to my serial monitor on arduino. It'll be read as ASCII and the signal output will be binary so i wanted a comparison.
I hooked it up to arduino ground and Tx pin.
It does look like a binary signal but the peak voltage is so tiny I think there's something wrong here.

arduarn

It does look like a binary signal but the peak voltage is so tiny I think there's something wrong here.
If applicable to your scope: check that the probe attenuation on the probe matches that in the scope settings.

nubcake

If applicable to your scope: check that the probe attenuation on the probe matches that in the scope settings.
Hello, I checked and it was indeed the probe attenuation.
The probe itself had by default x10 but the scope settings had x1
Thank you.

nubcake

Hello,

I wanted to update on my progress regarding this topic.
Going back to the starting point, I hooked up everything on an oscilloscope and got the following results of a RS232 port.


RxD -> -10.4V
DSR -> 9.2V
CTS -> 8.6V
RI -> -10.4V
(all other voltage levels are 0V)

I concluded that my photometer is a DCE (Data Communications Equipment) because my RxD reads a value lower than -3V.
I also concluded that it is in an "idle-state" because the idle state of RS232 is a logic 1 or a constant negative voltage of between -3V and -12V.

The problem is, how do I get this out of the idle-state?
Do I have to perform hardware handshaking?

Kind regards.

Paul_KD7HB

Hello,

I wanted to update on my progress regarding this topic.
Going back to the starting point, I hooked up everything on an oscilloscope and got the following results of a RS232 port.


RxD -> -10.4V
DSR -> 9.2V
CTS -> 8.6V
RI -> -10.4V
(all other voltage levels are 0V)

I concluded that my photometer is a DCE (Data Communications Equipment) because my RxD reads a value lower than -3V.
I also concluded that it is in an "idle-state" because the idle state of RS232 is a logic 1 or a constant negative voltage of between -3V and -12V.

The problem is, how do I get this out of the idle-state?
Do I have to perform hardware handshaking?

Kind regards.
You don't and you don't care! The UART will do the watching and it's code will tell you when it places a byte in the buffer for you to handle. You will know this by a return value from reading the UART or Serial that is greater than 0. That number will the a count of bytes in the buffer.
In the mean time, you code can do anything else you want it to do, or just loop.
Paul
Paul

Go Up