MCU software SPI and hardware SPI read and write SD card, TF card test program

Publisher:泉地水无痕Latest update time:2020-10-14 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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:

  1. #include "public.h"

  2. #include "SD.h"


  3. //Test platform: STC89C516 and STC12C5A60S2

  4. //Memory card size: 128MB and 2GB

  5. //Crystal oscillator: 12MHz


  6. void main()

  7. {

  8.         unsigned int i;


  9.         SD_init(); //SD card initialization

  10.        

  11.         for(i=0;i<512;++i) BUFFER_DATA[i]=0x7F;

  12.         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))

  13.        

  14.         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))

  15.         P0=BUFFER_DATA[0];

  16.        

  17.         while(1);

  18. }


  19. /*

  20.         unsigned int i;

  21.        

  22.         SD_init(); //SD card initialization

  23.        

  24.         {

  25.                 Before using the SD card module, initialize the SD card first

  26.         }

  27.        

  28.         for(i=0;i<512;++i) BUFFER_DATA[i]=0x7F;

  29.         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))

  30.        

  31.         {

  32.                 Write data to SD card:

  33.                 First write the data into the data buffer array BUFFER_DATA (I write all the data here as 0x7F),

  34.                 Then run MCU_write_SD_512Byte(960,512);

  35.                 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.

  36.                 Because the size of a sector is 512 bytes

  37.         }

  38.        

  39.         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))

  40.         P0=BUFFER_DATA[0];

  41.        

  42.         {

  43.                 Read data from SD card:

  44.                 First run MCU_read_SD_512Byte(960,512);

  45.                 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.

  46.                 After completion, the data is stored in the data buffer array BUFFER_DATA

  47.                

  48.                 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.

  49.         }


  50.         {

  51.                 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.

  52.                 At this time,

  53.                         To power off the development board and SD card module

  54.                         To power off the development board and SD card module

  55.                         To power off the development board and SD card module

  56.                         Not a reset

  57.                         Not a reset

  58.                         Not a reset

  59.                 After powering off the development board and then powering it on again, you can see the phenomenon

  60.                 If that doesn't work,

  61.                         Check whether the connection is correct

  62.                         Check whether the connection is correct

  63.                         Check whether the connection is correct

  64.                 Or try to plug in or out the SD card

  65.                

  66.                 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.

  67.         }

  68. */

Keywords:MCU Reference address:MCU software SPI and hardware SPI read and write SD card, TF card test program

Previous article:51 MCU controls LED through serial port
Next article:PWM frequency generator

Recommended ReadingLatest update time:2024-11-16 14:25

Kitchen timer based on AT89C2051 microcontroller
The device uses 5 minutes as a timing unit and can last up to 1 hour. It uses a 3V battery as the power source and has a buzzer alarm. The power consumption is about 6mA when working (using AT89C2051). It can use a 3V button battery and has an automatic shutdown function. The power consumption is negligible when not
[Industrial Control]
Kitchen timer based on AT89C2051 microcontroller
PIC microcontroller A/D conversion program
//Select RAO as the analog input channel; //Convert 4 times continuously and then calculate the average value as the conversion result //Finally, only the lower 8 bits are taken from the structure //The result is sent to the lower 3 bits of the digital tube for display #include p IC .h //Includes the predefined intern
[Microcontroller]
MSP430 MCU AD conversion LCD1602&TUBE display
#include #define uint unsigned int #define uchar unsigned char #define ulint unsigned long int #define RS BIT0; #define RW BIT1; #define EN BIT2; uint Volt0;                      //Set voltage variable ulint Volttem0; unsigned data0=0,data1=0; uint ADresult0;        //Set A/D conversion result uint a ={0xc0
[Microcontroller]
Use the 51 single chip microcomputer's LED dot matrix to output Happy Birthday
Led dot matrix schematic diagram Ports D0-D7 are connected to the 74HC595 chip, and the chip's input ports are ports P34, P35, and P36; Each column is controlled by ports P00-P07 Working principle of LED dot matrix According to the dot matrix schematic, the LED lights up when P00-P07 is connected to a low level
[Microcontroller]
Use the 51 single chip microcomputer's LED dot matrix to output Happy Birthday
MCU Test 4: Understanding Digital Tubes
If you want to play with single-chip microcomputer, you must play with digital tube. The above picture is a screenshot of the four-digit digital tube of our single-chip microcomputer test board. How does this digital tube display 1, 2, 3, 4? Don't worry, listen to me slowly.     The digital tube is actually composed o
[Microcontroller]
MCU Test 4: Understanding Digital Tubes
Inventory of 11 common parameters of automotive-grade MCUs
MCU is a core power electronic unit unique to new energy vehicles. It controls the motor to output the specified torque and speed by receiving the vehicle driving control instructions from the VCU, and drives the vehicle to drive. It converts the DC power of the power battery into the required high-voltage AC power
[Embedded]
DS18B20 temperature wireless transmission microcontroller source code based on NRF24L01
The microcontroller model is stc12c5a60s2 The temperature sensor is DS18B20 Wireless transmission is NRF24L01 Temperature display LCD1602 The microcontroller source program is as follows: #include STC12C5A60S2.H #include stdio.h #include "DELAY.h" #include "NRF24L01.h" #include "LCD1602.h" #include "DS18B20.h"
[Microcontroller]
Design of a vehicle-mounted infrared night vision device based on PIC microcontroller
0 Introduction With the rapid development of the automobile market and the increasing awareness of security, people have higher and higher requirements for automobile safety technology. However, the existing automobile lighting system has the disadvantages of short viewing distance and p
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号