Serial Port

Started by
4 comments, last by miodragsm 17 years, 2 months ago
Hello, I was reading somewhere that a serial port can read hex number from its inputs. I thought it could only read binary (high low) (1 0). Is this possible? "Once your circuit is operational hook it up to the serial port and a terminal program to see if data is being received on your port. It will be transmitted in HEX$ format. So make sure your terminal program can read Hex. You should be able to see a format of 80 0 X X X X X. The first two bytes are for syncin This data, (X) , should be between 0 and 255." (From a site) Will I need a specific UART to do this? I may be using the CDP6402 UART check at http://www.beyondlogic.org/serial/serial1.htm if you scroll down you will find it. Just to summarize, can a Serial Port read hex numbers? And if yes than how? Thanks Zayd
Advertisement
Quote:Original post by zaydenam
Hello,
I was reading somewhere that a serial port can read hex number from its inputs. I thought it could only read binary (high low) (1 0). Is this possible?

Hexadecimal is simply a convenient way for humans to view and edit numbers, by grouping them into sets of four binary digits (bits) and assigning all possible digit groups a number or letter. Quite likely the device you're talking about is capable of sending numbers which have been encoded as the ASCII representation of hexadecimal. It has nothing to do with UARTs or anything.
You can read bytes on serial (7 or 8 bits per byte). As Sneftel wrote it has nothing to do with serial port if device transmits data in ascii format , or any other... you can read only bytes on serial port, and they are 0-ff HEX (0-255 DEC) for 8bit bytes.
Thanks alot. Sorry If I am acting a bit slow, but is this right?

I send 8 bits to the serial port (10101011)If I am using any code to read the serial port, it will return a value of AB (that's in HEX, right?
And so another 8 bits after that and It will again output it in HEX, right?

Is my concept clear? Can you help me out if it's wrong.
Thanks
Zayd
Look, you talk about "sending 8 bits to the serial port". Which gives me a sinking feeling, because I think you might mean that you're doing something like fprintf(serial_port, "10101011");. That's not sending 8 bits to the serial port. That's sending 8 characters to the serial port. Three of them are the character '0', and five of them are the character '1'. (For reference, the character '0' on ASCII systems is represented as the bit-sequence 00110000, and the character '1' is represented as the bit-sequence 00110001.) If the device on the other end is a simple light that blinks every time a bit is received, fprintf(serial_port, "10101011"); will make it blink 64 times, eight times for each of the eight characters.

Now let's suppose that you instead did fprintf(serial_port, "\xAB");. That would, indeed, correctly send the eight bits 10101011. If C had a way of encoding binary in strings (it doesn't), you could do fprintf(serial_port, "\b10101011"); and accomplish EXACTLY the same thing. You could also use octal and send it as fprintf(serial_port, "\253");. You could also do fprintf(serial_port, "%c", 171);, using the decimal representation. All of these are merely different representations of the same thing. The reason there's more than one of them, is merely to help out the human programmers writing them.

Now, your device is probably doing something different. Rather than sending eight bits up the serial line when there's eight bits of information it needs to tell you, it's reencoding each eight bits as two (7- or 8-bit) characters representing hexadecimal digits, and sending them instead. That is, instead of doing fprintf(the_computer, "\xAB");, it's doing fprintf(the_computer, "AB");. It is sending numbers encoded as longer strings. This helps you the human to read them. This is purely a decision of the designers; there's no special hardware needed, and the only special software is something capable of taking a number and expressing it as a string made up of hexadecimal digits.
zaydenam, are you traying to interface some mcu based device with rs232? If the device generates TX signals for serial comm, you can use MAX232 (to adjust voltage levels). If you have only parallel bus from device, use CDP6402 or another mcu and MAX232.

This topic is closed to new replies.

Advertisement