• The computer does not see the memory card: SD, miniSD, microSD. What to do? SD card as internal memory of Android

    Installation of programs on the internal memory of the tablet is carried out by default. To place the application on the built-in memory card, it is enough to perform a standard installation. It will take a little longer to send it to external media. One simple session of settings will clean up the file system of the device, installing each new application on the SD card.

    Option 1: specifying the installation address

    Some programs during installation ask the user where to stay. Specifying the installation address is not difficult. Choose a removable memory card, and that's it. But this applies only to some applications, such a minority.

    Option 2: Set the installation path in advance

    The application must support the app2sd patch if the version of the Android OS on the tablet is earlier than 2.2. There will be no such items in the settings. For all new versions, this algorithm for solving the problem is suitable.

    Go to "Settings", find the item "Memory". Click on it and the memory settings menu will open. Here you can also find out about the amount of free memory on your device, how much space is on the tablet in general, how much internal memory is occupied. Some people insert an SD card into a card reader and find out the data about the flash drive on a computer, not knowing that this can be done on a tablet.

    Find the "Default Burn Disk" section, which offers you several sources for installing applications. Among them, select "SD-card". Click on this item, and you will see a circle opposite it. Now installing applications on the memory card on the tablet is the default.

    Option 3: Using Third Party Programs

    Most likely this method will help you. But he demands. You can find out whether or not you have root rights on the tablet by. We download special applications, such as FolderMount or GL to SD, which will help transfer game and program data to an SD memory card. See video instructions below:

    Option 3

    Install a program on your tablet PC that will allow you to select the installation address. Before installing the application directly, a dialog box will appear in which you will specify the installation address.

    This is the most convenient option offered. Because the forced installation of "default" is not desirable in all cases. Utilities such as InstallManager, MagicUneracer will help organize economical and rational filling of the tablet's memory. By the way, these same programs also remove programs with all auxiliary files.

    If the application is not installed on the SD card

    Open the "Applications" item in "Settings". In the list of applications, select the one you would like to transfer to a removable card. Click on the application icon and a menu will open. See if it has a "Move" option. If there is, press the option button and select the memory card. This procedure does not require the installation of additional software, you can do it yourself.

    Now almost every device on the Android operating system supports memory cards (microSD). However, sometimes there are problems associated with its detection in the device. There may be several reasons for the occurrence of such a problem, and certain manipulations are required to solve them. Next, we will consider methods for correcting such an error.

    Before you proceed with the instructions below, we recommend that you do the following:

    • Reboot your device. Perhaps the problem that has arisen is an isolated case, and the next time you start the device, it will simply disappear, and the flash drive will work correctly.
    • Reconnect. Sometimes the removable media is not displayed because the contacts are loose or clogged. Pull it out and insert it back, then check the correctness of the detection.
    • Maximum volume. Some mobile devices, especially older ones, only support certain sizes of memory cards. We advise you to familiarize yourself with this characteristic on the official website of the manufacturer or in the instructions in order to make sure that an SD card with this amount of memory functions normally with your device.
    • Check on other devices. It may well be that the flash drive is damaged or broken. Insert it into another smartphone or tablet, laptop or computer to make sure it works. If it is not readable on any equipment, it should be replaced with a new one.

    In addition to such detection problems, an error occurs notifying that the flash drive has been damaged. For a detailed guide on how to fix it, read our material at the link below.

    If the previous tips did not bring any result and the storage medium is still not detected by a smartphone or tablet, pay attention to the methods below. We have arranged them in order of difficulty so that you can implement each of them in order without much effort.

    Method 1: Deleting cache data

    Temporary data accumulates daily on your device. They not only take up physical space in memory, but can also cause various malfunctions of the device. First of all, we recommend clearing the cache through the menu Recovery. In it you should select the item Wipe Cache Partition, wait for the procedure to complete and restart the phone.

    Detailed instructions on how to switch to Recovery mode in the Android operating system and how else you can delete the cache can be found in the following articles.

    Method 2: Check for memory card errors

    As part of this method, follow a number of simple steps:


    If scanning for errors did not help, then more drastic measures need to be taken.

    Method 3: Format the media

    To perform this method, you will also need to connect the SD card to a computer or laptop using adapters or special adapters.

    Please note that when performing this procedure, all information will be erased from removable media, therefore, before starting, we advise you to save important data in any other convenient place.

    If you have any difficulties with formatting, we recommend that you read our other article at the link below. There you will find seven ways to solve this problem, and you can easily fix it.

    Most often, deleting data from the card helps in cases where it has ceased to be detected after connecting to other equipment. You just need to follow the instructions above, then immediately insert the media into your smartphone or tablet and check its performance.

    Method 4: Create a blank volume

    Sometimes, due to the fact that the card has a hidden section, its memory is not enough to save information from a smartphone. Among other things, in this case, there are problems with detection. To fix them, you need to connect the card to a PC and follow these steps:

    1. Through the menu "Start" go to "Control Panel".
    2. Select a category here "Administration".
    3. Among the list of all components, find and double-click on "Computer Management".
    4. In the window that opens, you should select "Disk Management".
    5. Here, look at the number of the disk that is your flash drive, and also note the total amount of memory. Write down or remember this information for later use.
    6. Key combination Win+R run the snap "Run". Type in cmd and click on "OK".
    7. In the window that opens, enter the diskpart command and click Enter.
    8. Grant permission to run the utility.
    9. Now you have moved on to the program for working with disk partitions. She has an identical "Command line" view. Here you need to enter list disk and click again on Enter.
    10. Check out the list of disks, find your flash drive there, then enter select disk 1, where 1 – disk number of the required medium.
    11. It remains only to clear all data and partitions. This procedure is performed using the clean command.
    12. Wait for the process to complete and you can close the window.

    Now we have achieved that the SD card is completely clean: all information, open and hidden partitions have been deleted from it. A new volume must be created in the phone for normal operation. It is done like this:

    1. Repeat the first four steps from the previous instruction to return to the disk management menu again.
    2. Select the required removable media, right-click on the mark with its memory and select "Create New Volume".
    3. The New Simple Volume Wizard will open in front of you. To get started, click on "Further".
    4. You do not need to specify the volume size, let it occupy all the free space, so the flash drive will work better with a mobile device. So just move on to the next step.
    5. Assign any free letter to the volume and click "Further".
    6. Formatting should be performed if the default format is not FAT32. Then select this file system, leave the cluster size "Default" and move on.
    7. Upon completion of the procedure, information about the selected parameters will be displayed in front of you. Check them out and get the job done.
    8. Now on the menu "Disk Management" you see a new volume that takes up all the logical space on the memory card. This means that the process was completed successfully.

    It remains only to remove the USB flash drive from a PC or laptop and insert it into a mobile device.

    If your device does not have enough internal memory, Can use SD card as internal storage for your android phone. This feature, called Adoptable Storage, allows the Android OS to format an external storage medium as persistent internal storage. The information on the installed SD-card is encrypted and cannot be further used on another device.

    An SD Card is a very convenient option for storing photos, songs, and videos. Even if you have a large amount of internal storage on your Android smartphone, you can always need a large chunk of storage to store long videos taken with your phone's high-definition camera.

    It is important to know

    There is one drawback, the SD chip may lag behind when recording high-definition video.

    Android by default in the internal memory and only occasionally uploads data to the SD card. Thus, you are deprived of installing any additional applications if your phone lacks internal storage, for example, in the case of budget Android One devices.

    What is storage storage?

    Storage storage is the main memory of your smartphone, but if necessary, it can be expanded using an SD card. This on Android it's called Adoptable Storage. This will allow you to use the removable microSD card installed on your Android phone as your primary storage. Thus, you can easily solve the problem of how to make the SD card the main memory on Android and overcome the lack of space if the phone has a small internal volume.

    Features of using the card as the main storage

    There are a number of some important features that should be considered in this procedure.

    Will be useful

    When using a drive, be it an SD flash drive or a USB drive, it is important to remember what format this device is in and whether the Android operating system supports it, and there are four types of main file formats: FAT32 or exFAT, ext4 or f2fs.

    How to change phone memory to android memory card? The question is not entirely correct, it is impossible to completely replace, you can only "increase" additional volume, as it were.

    Using your SD-card as the main storage can be a great solution for music lovers and TV series lovers on the way to work or on a long trip. But, as is often the case, memory expansion always rests on the cost of the required device, because they differ both in speed and volume, as well as in the adaptable function of storing information. Here are some nuances that can be considered from different angles - both in a negative direction and in a positive one:

    How to use SD card as internal storage on Android?

    Do you have enough internal storage to store all your data?

    How to replace internal phone memory with external sd card on android? Configuring your SD card to work as internal storage on Android is actually a fairly simple process. There is nothing complicated about this and you will see for yourself further.

    It is possible that the Adoptable Storage function is not supported by your device, even if the smartphone is running Android 6.0 or higher (this happens, it all depends on the model and brand of the smartphone). The device manufacturer may have disabled this feature. However, there are command line methods that allow you to force the use of a flash drive for data storage.

    The basic formatting steps are listed below.


    On the next screen, you have one last chance to decide for yourself if you want to change your mind.

    It is important to know

    Do not forget to make a backup copy of the data, after formatting the information will disappear without a trace!


    Once the formatting process is complete, you can use the removable SD card as a "temporary" or "removable" permanent location. But keep in mind that hot-swapping and ejecting will no longer be available, as you may have done before. That's why do not eject the flash drive without using the Eject option. In addition, you can practically delete the place accepted by the operating system, which, accordingly, is not recommended, since this can cause certain errors in the device. Now you know how to make a memory card the main memory on Android.

    SD and microSD cards can significantly expand the capabilities of Arduino projects that work with large amounts of data: data loggers, weather stations, smart home systems. The arduino boards are equipped with a relatively small internal memory, only up to 4 kilobytes, including both flash memory and EEPROM. This memory will not be enough to write large amounts of data, especially if the board is constantly turning off or off. Connecting an Arduino SD card as an external drive allows you to multiply the storage space for any information. Removable SD drives are cheap, easy to connect and easy to use. The correct connection of the SD card to the Arduino will be discussed in the article.

    Working with SD memory in arduino is not particularly difficult. The easiest way is to connect a ready-made module and use the standard library. We will start with this option.

    Using a ready-made module has various advantages. This is a fairly simple and convenient tool for working with large amounts of data. It does not require special skills in connection, all connectors are signed directly on the board. You have to pay for convenience, but the cost of the module is relatively low, it can be easily found at affordable prices in Russian and foreign online stores.

    The universal module is an ordinary board on which a card slot, resistors and a voltage regulator are placed. It has the following technical characteristics:

    • Operating voltage range 4.5-5 V;
    • Support SD card up to 2GB;
    • Current 80 mA;
    • FAT 16 file system.

    The SD card module implements such functions as storing, reading and writing information on the card, which is required for the normal operation of the device based on the microcontroller.


    Naturally, inexpensive memory card modules also have disadvantages. For example, the cheapest and most common models only support cards up to 4GB, and almost all modules allow you to store files up to two gigabytes in size on an SD card - this is a limitation of the FAT file system used in most models.

    Another disadvantage of memory cards is the relatively long recording time, but there are ways to work with it, allowing you to increase its speed. For this, a caching mechanism is used, when the data is first accumulated in RAM, and then dumped at a time to the memory card.

    Arduino boards for working with SD

    To work with an SD card, there are several different boards:

    • Arduino Ethernet - This board is equipped with a special module for outputting data. Pin 4 is used for CS output. SD.begin(4) command must be used for correct operation.
    • Adafruit Micro-SD is a development board that is used when working with Micro-SD cards.
    • Sparkfun SD - mounted on top of Arduino, CS uses pin 8 for output. The new version of the board has a 3.3V connection and a built-in six-bit inverter.

    Connecting SD and microSD to Arduino

    There are two types of cards - microSD and SD. They are identical in connection, structure and program, but differ only in size. Before use, it is advised to format the SD card. Usually new cards are already formatted and ready to go, but if you are using an old card, it is better to format it in the Arduino file system. To carry out the procedure, the SD library must be installed on the computer, preferably FAT16. For formatting on Windows, you need to click on the card icon and click “Format”.

    To connect the card, 6 contacts are used, the interaction is performed via the SPI interface. It looks like a six-pin connector on the board. To connect the card, you need the controller itself, the card module and 6 wires. In addition to SPI, there is an SDIO mode, but it is difficult to implement and poorly compatible with Arduino. SPI is easily configured to work with all microcontrollers, so it is advised to use it.

    The digital pins are connected as follows: for the Arduino Nano or Uno board, the MOSI pin is connected to D11, MISO to D12, SCK to D13, CS to 4, VCC to +5 V, .GND to GND. The board has connectors for connecting to 3.3 and 5 volts. The power supply of the card itself is 3.3 volts, so it is easier to use a microcontroller with the same power supply, otherwise you need voltage level converters. On the most common Arduino boards, there is such an output.

    When connecting an SD card, you need to take into account the correspondence of SPI pins for different types of Arduino boards:

    Arduino library for working with SD and microSD

    For the convenience of working with external data drives, ready-made libraries are available in the Arduino IDE. You won't need to download or install anything in most cases.

    To include a library in a sketch, use the include statement:

    #include #include

    The SPI library is needed for the correct operation of devices connected via SPI.

    Library functions are needed to read and write data to the card. The library can support SD and SDHC cards.

    Names are written in 8.3 format, that is, 8 characters for the name, 3 for the extension. The path to the file is written using slashes "/".

    Embedded SD Library Examples

    The Arduino IDE has built-in examples for quickly learning the functions of the library:

    • Card Info is an extraction of information stored in an SD card. With its help, you can find out in which file system the card is formatted, the amount of free space, what data is recorded.
    • Yun Datalogger - allows you to record log data from three sensors on the card.
    • Datalogger - registers and saves the data received from the sensor on the card.
    • Dump File - read data from the card, transfer it to the serial port.
    • Files - creates and deletes data. There is a file.write() function that puts the written data into a buffer. Moving information to the map occurs when calling the flush() or close() functions, so it is important to close it after each file opening, otherwise the data will be lost.
    • Read Write - writes and reads files from the card.

    SD library functions

    The Arduino SD library contains various functions that can be used to manipulate data. SD class functions:

    • begin() - the function initializes the library, assigns a contact for the signal.
    • exists() - is designed to check if the map has the necessary information.
    • mkdir() - allows you to create the desired folder on the memory card.
    • rmdir() - With this function, you can delete a folder. It is important that the folder to be deleted is empty.
    • open() - allows you to open a file that you need to write or read. If the required file is not on the map, it will be created.
    • remove() - removes any file.

    In response to all these functions, one of the values ​​\u200b\u200bmust come - true, in case of successful completion of the operation and false in case of failure.

    Create, edit and delete files.

    To work with files in arduino there is a class File. It includes functions that are designed to write and read information from the card:

    • available() - Checks if the file contains bytes that are available for reading. The response is the amount of space that is available for reading.
    • close() - closes the file, before these it checks if the data is saved to the card.
    • flush() - the function allows you to make sure that the data is written to the card.
    • name() - returns a pointer to the name.
    • peek() - reads bytes of data, while not moving the pointer to the next character.
    • position() - finds the current position of the pointer in the file.
    • print() - outputs data to a separate file.
    • println() - prints data to a file up to the point where a carriage return and an empty line appear.
    • seek() - changes the position of the current position in the file.
    • size() - displays information about the size of the data.
    • read() - reads information.
    • write() - writes to a file.
    • isDirectory() - using this method, it checks whether the file is a directory, that is, a directory or a folder.
    • openNextFile() - displays the name of the next file.
    • rewindDirectory() - returns to the first file in the directory.

    For the board to work correctly, you need to make sure that the SS output is configured.

    Sketch of an example of working with the Arduino SD library

    Below is a sketch showing an example of working with the memory card module.

    /* Data logger using SD cards An example of storing data from analog ports on an SD card. The data will be saved in the file as a set of lines with a field separator in the form of the symbol "," ** CLK - pin 13 ** CS - pin 4 */ #include #include const int PIN_CHIP_SELECT = 4; void setup() ( Serial.begin(9600); Serial.print("Initializing SD card..."); // This pin must be defined as OUTPUT pinMode(10, OUTPUT); // Trying to initialize the module if ( !SD.begin(PIN_CHIP_SELECT)) ( Serial.println("Card failed, or not present"); // If something went wrong, exit: return; ) Serial.println("card initialized."); ) void loop() ( // String with data that we will put in the file: String logStringData = ""; // Read data from ports and write to string for (int i = 0; i< 5; i++) { int sensor = analogRead(i); logStringData += String(sensor); if (i < 4) { logStringData += ","; } } // Открываем файл, но помним, что одновременно можно работать только с одним файлом. // Если файла с таким именем не будет, ардуино создаст его. File dataFile = SD.open("datalog.csv", FILE_WRITE); // Если все хорошо, то записываем строку: if (dataFile) { dataFile.println(logStringData); dataFile.close(); // Публикуем в мониторе порта для отладки Serial.println(logStringData); } else { // Сообщаем об ошибке, если все плохо Serial.println("error opening datalog.csv"); } }

    Creating a file and choosing a name for arduino SD card

    Creating a file is one of the most common tasks when working with SD cards in Arduino. As we saw in the previous sketch, to create a file, simply open it. If we want to check if such a file exists, we can use the exists() function:

    • SD.exists("datalog.csv");

    The function returns TRUE if the file exists.

    A popular practice when creating data logger projects is to split large files into smaller ones that are more convenient to update and open on a computer. For example, instead of one very large datalog.csv file on the SD card, you can have several small ones by adding a number in order to the end: datalog01.csv, datalog02.csv, etc.
    Here is an example sketch to help you get the job done:

    char filename = "datalog00.csv"; // Initial name for (uint8_t i = 0; i< 100; i++) { filename = i / 10 + "0"; filename = i % 10 + "0"; if (! SD.exists(filename)) { // Проверяем наличие logfile = SD.open(filename, FILE_WRITE); break; // Дальше продолжать смысла нет } }

    Conclusion

    As we have seen, connecting an SD memory card to Arduino and using it in a project is not very difficult. For this, there are ready-made libraries in the Arduino IDE and a wide variety of module options. You can buy a memory card at any electronics store, they are inexpensive, and at the same time they can significantly expand the potential of the Arduino board. With the use of memory cards, large amounts of data can be collected and stored for later analysis. With the help of our article, we will be able to endow our research projects with memory, create voice announcement systems for a smart home, create a simple wav player, and much more.

    We displayed the picture on the display from the sd card, but some points were missed in it, the first - connecting the card itself, the second - only part of the library functions was considered Petit FatFs Let's take a closer look at these points.

    Communication with the card is possible via one of two interfaces, SPI or SD.



    I must say that the SD interface can work in one-bit and four-bit modes.

    The scheme for connecting the card via SPI is standard and looks like this, unused card pins must be connected to the power supply using a 10K resistor.


    But in amateur designs, pull-up resistors are often neglected, simplifying the connection diagram.

    It should be noted that when connected via SPI, the card is very demanding on the supply voltage and a small drop in the supply voltage leads to the inoperability of the card, this has been verified from personal experience, there is nothing to say about the SD interface, I have not tried it yet. All this was written to for power supply, it is necessary to install capacitors. As for the inductor, it must be rated for current up to 100mA, but it is not necessary to install it.

    The diagrams shown above show that the card needs 3.3 volts to work, respectively, in the data transmission lines, the voltage should not go beyond the range of 0 - 3.3 volts, and here the question arises, what if the MC is powered by 5 volts?
    The answer is simple, you need to match the data lines, and this can be done using a conventional resistive divider.


    The diagram shows that the MISO line does not need to be matched as data is transmitted over this line from card to MK.
    In fact, few people connect the card directly to the MK, it is much more convenient to connect a card connector to the MK or buy a shield with a connector and all the necessary harness.

    We figured out the connection, now let's look at how to use the library Petit FatFs, which is designed for 8-bit microcontrollers with a small memory size.

    The library consists of 5 files:
    integer.h- a header file that describes the main data types.

    diskio.h- a header file that declares the prototypes of low-level functions for working with the disk and the status codes they return.

    diskio.c- low-level functions should be implemented in this file, initially there are "stubs".

    pffconf.h- configuration file.

    pff.h- header file in which the prototypes of functions for interacting with the disk file system are declared.

    pff.c- the file contains implementations of functions for interacting with the disk file system.

    It can be seen that in order for the library to work, it is necessary to implement low-level functions. But if we are talking about AVR or PIC, for them on the site you can download an example of working with the library, which contains the file mmc, low-level functions are already implemented in it. It is also necessary to set the library configuration in the pff.h file and write the functions necessary for SPI to work.

    Functions of Petit FatFs.

    FRESULT pf_mount (FATFS*)- the function mounts/dismounts the disk. This function must be called before starting work with the disk, if you call the function with a null pointer, the disk is unmounted. The function can be called at any time.

    Options
    FATFS* fs- a pointer to an object of type FATFS, a description of this structure can be found in the pff.h file. We just need to declare a variable of this type.

    Return values:
    FR_OK (0)
    FR_NOT_READY- the device could not be initialized
    FR_DISK_ERR- an error occurred while reading from disk
    FR_NO_FILESYSTEM- the drive does not have a valid FAT partition

    FATFS fs;//Declare an object of type FATFS //Mount the disk if (pf_mount(&fs) == FR_OK) ( //The disk is mounted, working with it //Dismount the disk pf_mount(NULL); ) else ( //Failed to mount the disk )

    FRESULT pf_open (const char* path)- the function opens an existing file. After the file is opened, you can work with it, that is, read from it and write to it. You can work with an open file until another file is opened. The function can be called at any time.

    Options
    const char*path- a pointer to a string indicating the path to the file. The path must be specified completely relative to the root directory, separating the directories with a slash.

    Return values:
    FR_OK (0)- returned in case of successful execution of the function
    FR_NO_FILE- file not found
    FR_DISK_ERR- disk error
    FR_NOT_ENABLED- disk has not been mounted

    FATFS fs;//declaring an object of FATFS type //mounting the disk if (pf_mount(&fs) == FR_OK) ( //opening the file located in the root directory if(pf_open("hello.txt") == FR_OK) ( //doing something ) //open the file located in the folder new if(pf_open("new/hello.txt") == FR_OK) ( //do something ) //dismount the disk pf_mount(NULL); ) else ( // failed to mount disk)

    FRESULT pf_read(void* buff, WORD btr, WORD* br)- the function reads the specified number of bytes from the file and saves them to the buffer. If the number of bytes read is less than specified, then the end of the file has been reached.
    #define _USE_READ 1

    Options:
    void*buff- pointer to the buffer in which the read data is stored
    WORD btr- number of bytes to be read
    WORD*br- a pointer to a variable that stores the number of bytes read.

    Return values:
    FR_OK (0)- returned in case of successful execution of the function
    FR_DISK_ERR- disk error
    FR_NOT_OPENED- the file was not opened
    FR_NOT_ENABLED- disk has not been mounted

    FATFS fs;//declare an object of type FATFS BYTE buff;//buffer for reading a file WORD br; // counter of bytes read // mount the disk if (pf_mount(&fs) == FR_OK) ( // open the file located in the root directory if(pf_open("hello.txt") == FR_OK) ( // read 10 bytes from it pf_read(buff, 10, &br); if(br != 10) ( //if br is not equal to 10 //it means we have reached the end of the file ) ) )

    FRESULT pf_write(const void* buff, WORD btw, WORD* bw)- the function allows you to write data to an open file. In order for the function to work in the pffconf.h file, you need to write
    #define _USE_WRITE 1

    Options:
    void*buff- pointer to the buffer we want to write, zero value finalizes the write
    WORD btw- the number of bytes we want to write
    WORD*bw- a pointer to a variable that stores the number of bytes that could be written. By analyzing this variable, you can find out whether the end of the file has been reached.

    Return values:
    FR_OK (0)- returned in case of successful execution of the function
    FR_DISK_ERR- disk error
    FR_NOT_OPENED- the file was not opened
    FR_NOT_ENABLED- disk has not been mounted

    Due to the fact that the library is designed for microcontrollers with a small amount of memory, this function has a number of limitations:

    • you cannot create new files, and you can only write to existing ones
    • file size cannot be increased
    • can't update timestamp
    • a write operation can only be started/stopped at a sector boundary
    • read-only file attribute cannot prevent writing

    In order to understand the penultimate point, you need to know that the memory of the card is divided into blocks (sectors) of 512 bytes and recording can only be started from the beginning of the sector. Thus, if we want to write 1000 bytes, then the first sector will be written completely, and only 488 bytes will be written to the second, and the remaining 24 bytes will be filled with zeros.

    To write to an open file, do the following:

    • set the pointer to the sector boundary, if set not to the boundary, the pointer will be rounded to the lower sector boundary
    • call the write function the desired number of times
    • finalize the entry by calling the function with a null pointer

    In order to give an example of the work of the recording function, it is necessary to consider one more function.

    FRESULT pf_lseek(DWORD offset)- sets the read/write pointer in the open file. You can set the pointer with an absolute or relative offset; for an absolute offset, you must pass a number to the function
    pf_lseek(5000);
    for relative, pass the value of the pointer to the current position fs.fptr and the amount of displacement
    pf_lseek(fs.fptr + 3000);
    In order for the function to work in the pffconf.h file, you need to write
    #define _USE_LSEEK 1

    Options:
    DWORD offset is the number of bytes to shift the pointer to.

    Return values:
    FR_OK (0)- returned in case of successful execution of the function
    FR_DISK_ERR- disk error
    FR_NOT_OPENED- the file was not opened

    You can write data to a file in the following way.
    FATFS fs;//declare an object of type FATFS BYTE buff;//buffer for reading a file WORD br; // counter of bytes read // mount the disk if (pf_mount(&fs) == FR_OK) ( // open the file located in the root directory if(pf_open("hello.txt") == FR_OK) ( // set the pointer to the first sector pf_lseek(0); //write pf_write(buff, 10, &br); //finalize the write pf_write(0, 0, &br); ) )

    I also leave here a piece of really working code that uses all the functions described above.
    #define F_CPU 8000000UL #define buff_size 10 #include #include #include "diskio.h" #include "pff.h" #include "spi.h" FATFS fs;//declaring an object of type FATFS BYTE read_buff;//buffer for reading the file BYTE write_buff = "hello word";/// /buffer to write to file UINT br; // counter of bytes read int main(void) ( // mount the disk if (pf_mount(&fs) == FR_OK) ( // open the file in the folder new if(pf_open("new/hello.txt") == FR_OK) ( //set write pointer pf_lseek(0); //write pf_write(write_buff, buff_size, &br); //finalize write pf_write(0, 0, &br); //set read pointer pf_lseek(0); //read that that we wrote pf_read(read_buff, buff_size, &br); if(br != buff_size) ( //if br is not equal to buff_size //it means we have reached the end of the file ) ) //mount the disk pf_mount(NULL); ) while(1) ( ) )

    FRESULT pf_opendir(DIR* dp, const char * path)- the function opens an existing directory and creates a pointer to an object of type DIR, which will be used to get a list of files in the open directory.
    In order for the function to work in the pffconf.h file, you need to write
    #define _USE_DIR 1

    Options:
    DIR *dp- pointer to a variable of type DIR.

    const char *path- pointer to a string that contains the path to the directory, directories are separated by a slash

    Return values:
    FR_OK (0)- returned in case of successful execution of the function
    FR_NO_PATH- could not find path
    FR_NOT_READY- Failed to initialize disk
    FR_DISK_ERR- disk error
    FR_NOT_ENABLED- disk has not been mounted

    //declaring variables FATFS fs; DIR dir; //mount disk pf_mount(&fs); //open directory pf_opendir(&dir, "MY_FOLDER");

    FRESULT pf_readdir(DIR* dp, FILINFO* fno)- function allows you to read the contents of the directory. To do this, open a directory with the pf_opendir() function and call pf_readdir(). Each time the function is called, it will return the name of the object (folder/file) located in the specified directory. When it has gone through all the objects, it will return the null string in the fno.fname array element.
    In order for the function to work in the pffconf.h file, you need to write
    #define _USE_DIR 1

    Options:
    DIR *dp- pointer to a variable of type DIR, which must be previously declared

    FILINFO *fno- a pointer to a variable of type FILINFO, which must be previously declared.

    Return values:
    FR_OK- successful completion of the function
    FR_DISK_ERR- disk error
    FR_NOT_OPENED- directory not open

    FATFS fs; FRESULT res; FILINFO fno; DIR dir; //mount disk pf_mount(&fs); //open directory res = pf_opendir(&dir, MY_FOLDER); //read the contents of the directory for(;;)( res = pf_readdir(&dir, &fno); //check if there were any errors while reading // and if there are still files in the specified directory if ((res != FR_OK) || ( fno.fname == 0))( break; ) //display in a convenient way fno.fname usart_sendStr(fno.name); usart_sendStr(/r); )

    And finally, I'll leave the working project here