Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

read binary data through RS232

Status
Not open for further replies.

Kenyellow

New Member
Dear all,

I have a device to which I want to connect PC. However, the byte format is as follow.

9600 NRZ: 1 start bit, 8 data bit, 1 mode bit, 1 stop bit
(Total 11 bits and the mode bit is set for indicating address byte or data byte.)

I tried to read the signal in VB with function Mscomm but it didn't work as 9 data bits can't be read while MSComm1.Settings="9600,N,8,1" Pls. help.

Enclosed are 2 circuit diagrams for connecting the device to AT89C52 and to PC.

Actually I am not sure why there are 4N26 and the transister between the port of the device and the AT89.

Thx + regards
Ken
 

Attachments

  • max232_113.gif
    max232_113.gif
    3.9 KB · Views: 966
  • at89c52.gif
    at89c52.gif
    7.8 KB · Views: 1,059
What is the "mode bit"? Do you mean parity?

The PC adheres to the standard RS232 protocol, so if you have extra bits in there you can't force the PC to comprehend it.

Mike
 
Kenyellow said:
Dear all,

I have a device to which I want to connect PC. However, the byte format is as follow.

9600 NRZ: 1 start bit, 8 data bit, 1 mode bit, 1 stop bit
(Total 11 bits and the mode bit is set for indicating address byte or data byte.)

I tried to read the signal in VB with function Mscomm but it didn't work as 9 data bits can't be read while MSComm1.Settings="9600,N,8,1" Pls. help.

Your problem is (obviously!) the non-standard 11 bit word, I don't see how you can use a hardware UART with that?, although perhaps you can do something by using the parity bit?.

However, it would be simple to do with a software UART - you can write it to use as many bits as you like!. You could always use a microcontroller to interface between the device and PC.

Enclosed are 2 circuit diagrams for connecting the device to AT89C52 and to PC.

Actually I am not sure why there are 4N26 and the transister between the port of the device and the AT89.

Usually to provide safety isolation - but it's a bit bizarre that the 5V supply crosses the barrier?.
 
What is the "mode bit"? Do you mean parity?

The PC adheres to the standard RS232 protocol, so if you have extra bits in there you can force the PC to comprehend it.

Mode bit is not the standard of RS232 but the standard of an industry (vending machine). It can't be forced to be parity bit as it's used to indicate whether the signal is an address or data only.
 
I said "can" when I meant "can't" for forcing the PC to understand your protocol.

Ken, why do you want to connect this device to a PC? What you could do is take Nigel's suggestion about bit-banging the serial on the microcontroller. And then use the microcontroller's serial port to communicate with the PC.

Mike
 
Your problem is (obviously!) the non-standard 11 bit word, However, it would be simple to do with a software UART - you can write it to use as many bits as you like!. You could always use a microcontroller to interface between the device and PC.
Would you please inform me more of the softward UART. I am a beginner. Did you mean to use MCU implementing the job? My only experience is to write few MCU projects in C when i was in University. Actually I need to study the code of the device. I just think it will be clear for me if I can read it in PC.

Usually to provide safety isolation - but it's a bit bizarre that the 5V supply crosses the barrier?.
I was surprised it's work. May I know:
1.) why the TXD of the device seem opposite to INT0 (5v TXD results in 0V INT0)
2.) if the signal level is TTL non return to zero, is it OK to connect AT89 through MAX232 directly ? (no need to invert the signal)
3.) If it doesn't make sense 5V cross barrier, do you have any suggestion for improvement?
 
Kenyellow said:
Would you please inform me more of the softward UART. I am a beginner. Did you mean to use MCU implementing the job? My only experience is to write few MCU projects in C when i was in University. Actually I need to study the code of the device. I just think it will be clear for me if I can read it in PC.

Yes, using a micro-controller.

If you're using a PIC, there are both software and hardware UART examples in my PIC tutorials. I would suggest using something like the 16F628 (as it has a hardware UART) - use a software UART to receive the data from the device, then simply transfer that byte to the hardware UART. This frees the processor, and you can loop back to wait for the next serial byte from the device.

If you're familiar with a different micro-controller, any one should be up to the task, but having a hardware UART to feed the PC would be an advantage.

Usually to provide safety isolation - but it's a bit bizarre that the 5V supply crosses the barrier?.
I was surprised it's work. May I know:
1.) why the TXD of the device seem opposite to INT0 (5v TXD results in 0V INT0)

Because RS232 uses inverted logic, so a MAX232 inverts the data - if you're not using a MAX232 you need to invert it in some other way.

2.) if the signal level is TTL non return to zero, is it OK to connect AT89 through MAX232 directly ? (no need to invert the signal)

That's how it's designed to be, the MAX232 WILL invert the signal, as it's designed to do.

3.) If it doesn't make sense 5V cross barrier, do you have any suggestion for improvement?

It depends if you need isolation or not? - if not, just use a MAX232.
 
Thanks for your comment. I will study your tutorial first.

Because RS232 uses inverted logic, so a MAX232 inverts the data - if you're not using a MAX232 you need to invert it in some other way.

1. But when the device (which is TTL 9600 NRZ) is connected to AT89C52 not a PC, why is the signal inverted?
may i make sure something:
2. (P3.3 of AT89) 5V -> (RXDof device) 5V or 0V??
3. (TXD of device)5V -> (P3.2 of AT89) 0V ???
4. Can the setting as set out in the figure2 fulfill the requirement?
 
Kenyellow said:
Thanks for your comment. I will study your tutorial first.

Because RS232 uses inverted logic, so a MAX232 inverts the data - if you're not using a MAX232 you need to invert it in some other way.

1. But when the device (which is TTL 9600 NRZ) is connected to AT89C52 not a PC, why is the signal inverted?
may i make sure something:
2. (P3.3 of AT89) 5V -> (RXDof device) 5V or 0V??
3. (TXD of device)5V -> (P3.2 of AT89) 0V ???
4. Can the setting as set out in the figure2 fulfill the requirement?

Simply because the processor is designed to have a MAX232 connected, and as such is inverted so the MAX232 will correct it. If you don't have a MAX232 (or similar) at EITHER end, then you can simply connect the two 5V signals together.

I can't comment on Atmel devices, but PIC's are fixed polarity - you CAN'T alter the polarity of the hardware UART in software.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top