0
votes

enter image description hereI am trying to write data from a file which contains hex values via UART using MATLAB to my embedded device. The code runs but the output which I am getting is not in hex.

The image shows the issue. The top of the image in numbers is the output I am getting; the below hex data is my input file and this should be my output also.

obj1 = instrfind('Type', 'serial', 'Port', 'COM9', 'Tag', '');
fopen(obj1);
A = fopen('C:\Users\admin\Workspace\STELLARIS-LM4F120_00_210214_104000_0001_temp_025.bin');
while ~feof(A)
    curr = fscanf(A,'%c',1);
% Communicating with instrument object, obj1.
binblockwrite(obj1, 'curr');
end  
% Disconnect from instrument object, obj1.
fclose(obj1);

Please let me know whats the issue here.

Thanks! Kashif

1
The problem basically now is if I am sending say 'AB' then it is converting it into hex first and hence showing me the output as 41 42. Same for any hex combination. problem is I think it is treating it as a string and converting it into hex which I dont want. I want it to be treated as hex. - Kashif Nawaz
The hex value 63, 75, 72, 72 are the ASCII codes for the letters 'curr'. You probably shouldn't put 'curr' in quotes when calling binblockwrite. - kkrambo

1 Answers

0
votes
fopen(obj1);
A = fopen('C:\Users\admin\Workspace\STELLARIS-LM4F120_00_210214_104000_0001_temp_025.bin');
txdata = fread(A,inf,'uint8','ieee-be');
for i = 1:32768
fwrite(obj1,txdata(i),'uint8');
end
fclose(obj1);