Azzera filtri
Azzera filtri

error in serial communication

4 visualizzazioni (ultimi 30 giorni)
anas qazaz
anas qazaz il 24 Mar 2013
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

Risposte (1)

Walter Roberson
Walter Roberson il 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.

Community Treasure Hunt

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

Start Hunting!

Translated by