Activate AT|Five minutes, use AT commands to read and write U disk files

Preparation before experiment

This manual is applicable to the M0R1 series (RDA5981). First, connect the WIFI module GND, DP and DN of the M0R1 to the experimental U disk D+ and D-. The U disk uses 5V power supply. The M0R1 series modules support U disk hot swapping. .

Insert image description here

WIFI module AT command operates U disk files

Routine 1: Create a file and write data

The root directory of our USB flash drive is /u/, and we need to create a file with the root directory name write_test.txt. Before creation, this file does not exist.

1. Open the write_test.txt file

set up return
AT+FOPEN=/u/write_test.txt,at+ +ok

2. Write data.
Here we read the data 12345667890 for testing.

set up return
AT+FWRITE=10 When data is entered after >, +ok=10 appears. 10 indicates the length of data successfully sent.

3. Close the file

set up return
AT+FCLS +ok

4. Pull out the U disk and insert it into the computer. You can see that write_test.txt has been created in the U disk. After opening it, you can see that the data is 1234567890.

Routine 2: Read data from the file

We first create the file read_test.txt in the U disk and write the data asdfghjklz. After saving and closing the file, remove the U disk and connect it to the WIFI module.
1. Open the read_test.txt file

set up return
AT+FOPEN=/u/write_test.txt,r +ok

2. Read data.
Here we assume that the length of the read data is 1000 bytes, and there are only 10 bytes in the actual file.

set up return
AT+FREAD=1000 +ok=10,asdfghjklz. 10 is the length of data saved in the actual file

3. Close the file

set up return
AT+FCLS +ok

Use of continuous read and write functions

When we need to read and write data continuously, we only need to open the file and read or write data continuously. The data will continue to be read and written according to the file stream until there is no data in the file.

Other AT commands

1. Check whether the USB flash drive is connected

set up return
AT+UDLK +ok=Connected(Disconnected means not connected)

2.File displacement function

set up return
AT+FSEEK=0,SET +ok
Parameter 1: offset SET: Beginning of file
CUR: Current location
END: end of file

**For details, please refer to the fseek function in C language**

3. The use of the second parameter of FOPEN is as follows:

string illustrate
r Open the file read-only, the file must exist.
r+ Open a file for read/write, the file must exist.
rb+ Opens a binary file for read/write, allowing only reading/writing of data.
rt+ Opens a text file in read/write mode, allowing both reading and writing.
w Open a write-only file. If the file exists, the file length will be cleared to zero, that is, the file content will disappear; if the file does not exist, the file will be created.
w+ Open a read/write file. If the file exists, the file length will be cleared to zero, that is, the file content will disappear; if the file does not exist, the file will be created.
a Open a write-only file in append mode. If the file does not exist, the file will be created; if the file exists, the written data will be added to the end of the file, that is, the original content of the file will be retained (EOF character retained).
a+ Open read/write files in append mode. If the file does not exist, the file will be created. If the file exists, the written data will be added to the end of the file, that is, the original content of the file will be retained (EOF characters will not be retained).
wb Open or create a new binary file in write-only mode, allowing only data to be written.
wb+ Open or create a new binary file in read/write mode, allowing reading and writing.
wt+ Open or create a new text file in read/write mode, allowing reading and writing.
at+ Opens a text file for reading/writing, allowing reading or appending data to the end of the text.
ab+ Opens a binary file for read/write, allowing reading or appending data to the end of the file.

If you encounter problems using the module, you can join the QQ group with the group number 519630819 to communicate.
For related products, please pay attention to: shop.mqlinks.com

Guess you like

Origin blog.csdn.net/mqlinks/article/details/106691509
Recommended