when i read data from pic the speed is very low but when i send data from matlab to pic the speed is very high. how can increase the speed of received data.
u=[1.3 2.4 3.3 4.4 5.1]; for k=1:5 s=serial('com4'); set(s,'baudrate',19200); fopen(s); fwrite(s,u(k)); y(k)=fread(s) fclose(s) delete(s) end
No products are associated with this question.
You do not appear to have set a terminator or a buffer size.
A = fread(obj) and A = fread(obj,size) read binary data from the device connected to the serial port object, obj, and returns the data to A. The maximum number of values to read is specified by size. If size is not specified, the maximum number of values to read is determined by the object's InputBufferSize property.
The default value is 512.
Thus, each round you are attempting to read 512 bytes and store the result into a single location y(k).
It is also quite inefficient to fopen() and fclose() the serial port on each iteration. fopen() only once, before the loop, and fclose() after the loop, and control the amount of data you want to read using the size parameter of fread()