error in serial communication
2 views (last 30 days)
Show older comments
hi,all i use the following codes to transimit data from matlab to 8051 mcu
s=serial('com3','baudrate',9600);
>> fopen(s)
>> fwrite(s,10101010,'int8')
and codes for 8051 to receive data via serial port is
org 2000h
mov tmod,#20h
mov th1,#0fah
mov scon,#50h
setb tr1
here:jnb ri,here
mov a,sbuf
mov p1,a
clr ri
sjmp here
end
the problem when i displayed received data it appear on led 11111110 what the wrong plzzzzzz help at least idea
0 Comments
Answers (1)
Walter Roberson
on 24 Mar 2013
In your command
fwrite(s,10101010,'int8')
you are asking to have decimal 10101010 converted to int8, and transit that. The effect would be as if you had used
fwrite(s, int8(10101010), 'int8')
which, due to the saturation properties of int8, would be equivalent to
fwrite(s, int8(127), 'int8')
High bit is 0, but low bit is transmitted first in serial, so the bit order across the wire would be 11111110 .
Remember, 10101010 is a decimal number, ten million, one hundred and one thousand, and ten.
0 Comments
See Also
Categories
Find more on Standard File Formats 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!