Clear Filters
Clear Filters

matlab help for fwrite

1 view (last 30 days)
anas qazaz
anas qazaz on 25 Mar 2013
i read matlab help about fwrite it say that write binary data to device ,not decimal you answered to my question why when i use code below
s=serial('com3','baudrate',9600);
>> set(s,'flowcontrol','none');
>> set(s,'parity','none');
>> set(s,'databit',8);
>> set(s,'stopbit',1);
>> fopen(s)
>> fwrite(s,10101010,'int8')
my 8051 receive the data via serial port and display it on led as 11111110 then when i use (s,00000110,'int8') 8051 display it 00000110 what is the wrong and what is the code to send data using fwrite in binary fourm,and how i can send like this numbers -34.3 -1.1 please heeeelp

Answers (1)

Walter Roberson
Walter Roberson on 25 Mar 2013
fwrite(s, bin2dec('10101010'), 'int8');
fwrite(s, bin2dec('00000110'), 'int8');
Numbers such as -34.3 and -1.1 do not have a unique binary form. Use whatever form you prefer. You are going to have to write all the code for the 8051 to handle the decimal fractions, as the 8051 instruction set is strictly integer.

Community Treasure Hunt

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

Start Hunting!