📄 example_280xspi_sd.c
字号:
#include "DSP280x_Device.h" // DSP280x Headerfile Include File
#include "DSP280x_Examples.h" // DSP280x Examples Include File
#include "type.h"
#include "spi_mmc.h"
//#include "mmcmain.h"
#define MAX_BLOCK_NUM 0x80
#define SD_cs_Hi GpioDataRegs.GPASET.bit.GPIO27 = 1
#define SD_cs_Lo GpioDataRegs.GPACLEAR.bit.GPIO27 = 1
extern BYTE MMCWRData[MMC_DATA_SIZE];
extern BYTE MMCRDData[MMC_DATA_SIZE];
// Prototype statements for functions found within this file.
// interrupt void ISRTimer2(void);
void delay_loop(void);
void spi_b_init();
void main(void)
{
DWORD i, BlockNum = 0;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP280x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP280x_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
// This function is found in DSP280x_Spi.c
InitSpiaGpio();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP280x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
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();
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP280x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
//spi_b_init(); // init SPI
// Step 5. User specific code:
// Interrupts are not used in this example.
SPI_Init(); /* initialize SPI for MMC card */
if ( mmc_init() != 0 )//MMC 初始化
{
//IOSET0 = SPI_SEL; /* set SSEL to high */
SD_cs_Hi;
while ( 1 ); /* Very bad happened */
}
/* write, read back, and compare the complete 64KB on the MMC
* card each block is 512 bytes, the total is 512 * 128 */
for ( BlockNum = 0; BlockNum < MAX_BLOCK_NUM; BlockNum++ )
{
if ( mmc_write_block(BlockNum) == 0 )
{
mmc_read_block(BlockNum);
}
else
{
//IOSET0 = SPI_SEL; /* set SSEL to high */
SD_cs_Hi;
while ( 1 ); /* Very bad happened */
}
for ( i = 0; i < MMC_DATA_SIZE; i++ ) /* Validate */
{
if ( MMCRDData[i] != (MMCWRData[i]&&0xff) )
{
//IOSET0 = SPI_SEL; /* set SSEL to high */
SD_cs_Hi;
while ( 1 ); /* Very bad happened */
}
}
for ( i = 0; i < MMC_DATA_SIZE; i++ ) /* clear read buffer */
MMCRDData[i] = 0x00;
}
for(;;)
{
}
}
// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:
void delay_loop()
{
long i;
for (i = 0; i < 1000000; i++) {}
}
//===========================================================================
// No more.
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -