Software SPI and hardware SPI read and write SD card, TF card test program
SD card module and SD card
software SPI read and write SD card program
test platform: STC89C516 and STC12C5A60S2
memory card size: 128MB and 2GB
crystal oscillator: 12MHz
hardware SPI read and write SD card program
test platform: STC12C5A60S2
memory card size: 128MB and 2GB
crystal oscillator: 12MHz
(89C52 does not have hardware SPI)
In order to avoid pitfalls for later comers as much as possible, I have tested these codes repeatedly before sending them out to ensure that they are correct.
In addition, I have written the reading and writing of SD card programs very clearly in the program, and I will not repeat them here.
The microcontroller source program is as follows:
#include "public.h"
#include "SD.h"
//Test platform: STC89C516 and STC12C5A60S2
//Memory card size: 128MB and 2GB
//Crystal oscillator: 12MHz
void main()
{
unsigned int i;
SD_init(); //SD card initialization
for(i=0;i<512;++i) BUFFER_DATA[i]=0x7F;
MCU_write_SD_512Byte(960,512); //MCU writes data to the SD card, up to 512 bytes at a time (sector, data length (maximum 512, recommended to fill in 512))
MCU_read_SD_512Byte(960,512); //MCU reads data from SD card, up to 512 bytes at a time (sector, data length (maximum 512, recommended to fill in 512))
P0=BUFFER_DATA[0];
while(1);
}
/*
unsigned int i;
SD_init(); //SD card initialization
{
Before using the SD card module, initialize the SD card first
}
for(i=0;i<512;++i) BUFFER_DATA[i]=0x7F;
MCU_write_SD_512Byte(960,512); //MCU writes data to the SD card, up to 512 bytes at a time (sector, data length (maximum 512, recommended to fill in 512))
{
Write data to SD card:
First write the data into the data buffer array BUFFER_DATA (I write all the data here as 0x7F),
Then run MCU_write_SD_512Byte(960,512);
960 is the sector of the SD card, which means writing data to the 960 sector of the SD card. 512 is the size of the data to be written at one time, which is 512 bytes. It is recommended to fill in 512 bytes.
Because the size of a sector is 512 bytes
}
MCU_read_SD_512Byte(960,512); //MCU reads data from SD card, up to 512 bytes at a time (sector, data length (maximum 512, recommended to fill in 512))
P0=BUFFER_DATA[0];
{
Read data from SD card:
First run MCU_read_SD_512Byte(960,512);
Here, 960 is the SD sector you want to read. The data size of 512-bit one-time reading is 512 bytes. It is recommended to fill in 512 bytes because the size of 1 sector is 512 bytes.
After completion, the data is stored in the data buffer array BUFFER_DATA
Because it is difficult to judge whether the SD card reading and writing is successful without the phenomenon, so assign P0BUFFER_DATA[0] to P0, connect P0 to the LED light, and you can see the phenomenon.
}
{
Note: After downloading the program to the development board, the data displayed on the P0 port may be inconsistent with the data written to the SD card.
At this time,
To power off the development board and SD card module
To power off the development board and SD card module
To power off the development board and SD card module
Not a reset
Not a reset
Not a reset
After powering off the development board and then powering it on again, you can see the phenomenon
If that doesn't work,
Check whether the connection is correct
Check whether the connection is correct
Check whether the connection is correct
Or try to plug in or out the SD card
After the SD card is successfully read and written, you can modify the sector and the SD write data to test several times to ensure that everything is safe.
}
*/
Previous article:51 MCU controls LED through serial port
Next article:PWM frequency generator
Recommended ReadingLatest update time:2024-11-16 14:25
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- EEWORLD University ---- designing electrical systems vol 1
- Rice goes in and rice comes out. How is rice husked? You may not have seen it even if you have been eating it for decades!
- The gap between actual power supply and ideal power supply
- Okay, let’s talk about the Internet of Things technology protocol
- On-line debugging method for embedded processors
- [Zero-knowledge ESP8266 tutorial] Quick start 21 world clock demo
- National College Student Electronic Design Competition Open Source Flight Control Data Album: APM Learning Materials
- Annual review: 2019 TI training course highlights, good reviews and gifts!
- Which development environment do I use for C8051F58x/F59x?
- C2000 CLA FAQ: Accessing Peripherals