effect of using usb to rs232 on transfer data

2 views (last 30 days)
hi,all i want to ask if i use usb to rs232 adapter will change the bits pattern of my binary data when i send binary byte from matlab via usb to rs232 adapter im try and try all formats of fwrite function to send binary data from matlab and display it to 8051 leds .i notice when i seend
fwrite(s,00000001,'uint8')
i receive 00000110 is the data change because i use usb to rs232 adapter or not?
can any human on this plant send 00000001 from matlab and receive in 8051 00000001?how?
please help
thanks in advance
[Merged from duplicate]
Sir,mr walter ,im very grateful for you for your explain to my questions specially for my question " effect of using usb to rs232 on transfer data".
I use laptop and I use its usb to out data transferred from computer and I use usb to rs232 adapter to connect with my 8051 kit .when I send data from matlab using below instruction
Fwrite(s,dec2bin(1),'uint8')
I receive in my 8051 11111000 this displayed on led. I want ask you is this occur because I use usb to rs232 adapter in other word if I use rs232 directly from desktop computer (pc) may I receive 00000001 as I send from matlab?
Thanks in advance for your help, suggestions, idea

Answers (1)

Walter Roberson
Walter Roberson on 6 Apr 2013
fwrite(s,00000001,'uint8') is equivalent to fwrite(s,1,'uint8') as MATLAB does not recognize leading 0's as indicating binary.
fwrite() of 1 would be binary 00000001 but the least significant bit is sent first a true serial connection, so (excluding start and stop bits) the order seen on an RS232 wire would be 10000000.
However, USB uses a much more complicated protocol for its wire transmission, using differential transmission lines. Packets are used, NRZI bit stuffing is used, and looking at the bus states on the wire gets messy; you should expect to need to use special hardware if you want to examine what is on the serial lines of a USB bus. So what you should probably be concerned with is what comes out of the USB device on the microcontroller side.
8051 does not inherently have USB built in (8051 predates USB a fair bit), but you can get 8051 with USB interfaces these days. To say what would show up where on the interfaces for those, we would have to know which such device you were using, and we would have to know which probe point you were using.
If what you are doing is using a USB interface on the computer end (e.g., because you did not have an available serial port) and you were translating to RS232 just outside your computer, then what you should see on the RS232 lines should be the data bytes you are transmitting, except possibly in bit-reversed order.
What do you get when you send uint8(0) over the wire? Is it consistent? When you send uint8(1) is it always the same bit pattern? If so could you show the pattern for uint8(2) and uint8(3) and uint8(127), uint8(128), uint8(129) ?
  1 Comment
Walter Roberson
Walter Roberson on 7 Apr 2013
With regards to your newer code:
dec2bin(1) results in '1' -- the character 1, not an actual binary 1. The character '1' is numeric position 49, binary 00110001.
Have you tested on the receiving end to be sure that your 8051 kit is properly displaying binary values that originate on that end ?

Sign in to comment.

Categories

Find more on Instrument Control Toolbox Supported Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!