sdcard_test.c

来自「dsp28335例程」· C语言 代码 · 共 92 行

C
92
字号
#include "SD.h"
#include "DSP2833x_Device.h"     // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h"   // DSP2833x Examples Include File

#define	  LedReg	(*((volatile  Uint16 *)0x41FF))

Uint16    *ExRamStart = (Uint16 *)0x100000;

Uint16 read_buffer[1024], write_buffer[1024];

void main(void)
{

	Uint16 i, testdata = 0x0000;
 

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
   InitSysCtrl();

// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();  // Skipped for this example
// Setup only the GP I/O only for SPI-A functionality

   InitXintf16Gpio();	//zq

   InitSpiaGpio();

// Step 3. Initialize PIE vector table:
// Disable and clear all CPU interrupts
   DINT;
   IER = 0x0000;
   IFR = 0x0000;

// 	Initialize the PIE vector table with pointers to the shell Interrupt 
// 	Service Routines (ISR).  
// 	This will populate the entire table, even if the interrupt
// 	is not used in this example.  This is useful for debug purposes.
// 	The shell ISR routines are found in DSP280x_DefaultIsr.c.
// 	This function is found in DSP280x_PieVect.c.
   	InitPieVectTable();

	LedReg = 0xFF;	

// 	Step 4. Initialize all the Device Peripherals:
   	spi_initialization();					//Initialize SPI	

// 	Step 5. User specific code:	

	//Initialize test data for known data to transmit to card
	for(i=0;i<1024;i++)						 
	{										
		write_buffer[i] = testdata;
		testdata += 0x0100;			//Card accepts 8 bit data so upper 8 bits are used
	}

   	sd_card_insertion();			//Check for card insertion
	sd_initialization();			//Initialize card

	sd_read_register(SEND_CSD);		//Read CSD register
	sd_read_register(READ_OCR);		//Read OCR register
	sd_read_register(SEND_CID);		//Read CID register

//	for(;;)
//	{
	sd_write_block(SECTOR_ZERO, write_buffer);	//Write to sector specified
	sd_read_block(SECTOR_ZERO, read_buffer);	//Read from sector specified
    sd_erase_block(SECTOR_ZERO, 1);				//Erase sector range specified
	sd_read_block(SECTOR_ZERO, read_buffer);	//Read from sector specified
//	}

	sd_write_multiple_block(SECTOR_ZERO, write_buffer, 2);	//Write to multiple sectors specified	
	sd_read_multiple_block(SECTOR_ZERO, read_buffer, 2);	//Read multiple sectors	specified										//Emulation stop
    sd_erase_block(SECTOR_ZERO, 2);							//Erase sectors range specified				
	sd_read_multiple_block(SECTOR_ZERO, read_buffer, 2);	//Read multiple sectors specified	
	
    asm(" ESTOP0");				//Emulation stop
   	for(;;){};					//Loop forever
} 	





//===========================================================================
// No more.
//===========================================================================

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?