本帖最后由 song19881218 于 2013-3-22 11:20 编辑
void SPI_FLASH_DMA_PageWrite(u8 *pBuffer, u32 WriteAddr, u16 NumByteToWrite)
{
//u32 i = 0;
DMA_InitTypeDef DMA_InitStructure;
/* MSD chip select low */
SPI_FLASH_CS_LOW();
/*initial the spi1 in write mode*/
/*initial dma channel5*/
DMA_DeInit(DMA1_Channel5);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)SPI2->DR;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)pBuffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = NumByteToWrite;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel5, &DMA_InitStructure);
SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Tx, ENABLE);
// SPI_Cmd(SPI1, ENABLE);
SPI_FLASH_WriteEnable();
SPI_FLASH_CS_LOW();
/* Send "Write to Memory " instruction */
SPI_FLASH_SendByte(WRITE);
/* Send WriteAddr high nibble address byte to write to */
SPI_FLASH_SendByte((WriteAddr & 0xFF0000) >> 16);
/* Send WriteAddr medium nibble address byte to write to */
SPI_FLASH_SendByte((WriteAddr & 0xFF00) >> 8);
/* Send WriteAddr low nibble address byte to write to */
SPI_FLASH_SendByte(WriteAddr & 0xFF);
DMA_Cmd(DMA1_Channel5, ENABLE);
while(!DMA_GetFlagStatus(DMA1_FLAG_TC4)) ;
DMA_Cmd(DMA1_Channel5, DISABLE);
/* MSD chip select high */
SPI_FLASH_CS_HIGH();
/* Send dummy byte: 8 Clock pulses of delay */
SPI_FLASH_SendByte(0xA5);
}
为什么不行呢,一直死到这个里面while(!DMA_GetFlagStatus(DMA1_FLAG_TC4)) ;
|