[MATLAB] millisecond-level delay (solved, Shengrun Bluetooth (CC2541) sends too fast packet loss problem)

Problem description:
Based on MATLAB21b, when I used the serial port to do the Bluetooth communication test, I found that there was a packet loss problem when sending 200 bytes at a time.

Solve the key:

1. Data packetization
2. Millisecond-level delay

millisecond delay

pause(n)
temporarily stops the execution of MATLAB. The default unit of parameter n is seconds. n is a non-negative number greater than 0.
To achieve millisecond delay:pause(n/1000)

Delay example

pause(2) ; % 暂停2s
pause(20/1000) ; % 暂停20ms

Solutions

Check the data sheet of my use of Bluetooth Shengrun Bluetooth (CC2541) and find the following:
insert image description here
Divide the data into single packets of less than 17 bytes,
and use pause (20/1000) to pause for 20ms after each packet is sent.
Then repeat the packet transmission until the data transmission is completed.

Guess you like

Origin blog.csdn.net/qq_44078824/article/details/123680234