I set a serial port in matlab to receive an image via UART. After receiving the image, I notice that the image sometimes shifts and sometimes not shift. As shown in figure, left part is the correct receiving result and right part shows the shift of the image.
The following is my code.Is there any suggestion to improve my figure?
clear all
close all
s = serial('COM3','BaudRate',115200, 'Parity','none','DataBits',8,'StopBits',1);
s.InputBufferSize=200000;
s.timeout=20;
fopen(s);
flushinput(s);
D=fread(s,[200,200]);
E=fread(s,[200,200]);
F=fread(s,[200,200]);
image_RGB(:,:,1)=D;
image_RGB(:,:,2)=E;
image_RGB(:,:,3)=F;
imwrite(image_RGB/256,'myimage.jpg','jpg');
imshow(image_RGB/256);
fclose(s);
fclose all;