对了为了让大家可以直观的查找我的软件问题,再贴上我的SPI DMA初始化代码吧:
void SPI3_Configuration(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_PCLK1Config(RCC_HCLK_Div2); //36M
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);//JTAG Disable SWDP Enable
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* SPI: CSÍÆÍìÊä³ö */
GPIO_SetBits(GPIOB,GPIO_Pin_0);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* SPI ³õʼ»¯¶¨Òå */
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //SPIÉèÖÃΪ˫ÏßË«ÏòÈ«Ë«¹¤
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //ÉèÖÃΪÖ÷ SPI
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //SPI·¢ËͽÓÊÕ 8 λ֡½á¹¹
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //ʱÖÓÐü¿Õ¸ß
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; //Êý¾Ý²¶»ñÓÚµÚ¶þ¸öʱÖÓÑØ
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //Èí¼þ¿ØÖÆ NSS ÐźÅ
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; //²¨ÌØÂÊÔ¤·ÖƵֵΪ2
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //Êý¾Ý´«Êä´Ó MSB λ¿ªÊ¼
SPI_InitStructure.SPI_CRCPolynomial = 7; //¶¨ÒåÁËÓÃÓÚ CRCÖµ¼ÆËãµÄ¶àÏîʽ
SPI_Init(SPI3, &SPI_InitStructure);
SPI_Cmd(SPI3, ENABLE);
DMA_Config();
}
/************************************************
º¯ÊýÃû³Æ £º DMA_Config
¹¦ ÄÜ £º DMAÅäÖÃ
²Î Êý £º ÎÞ
·µ »Ø Öµ £º ÎÞ
×÷ Õß £º ShiPeng
*************************************************/
void DMA_Config(void)
{
#define SPI3_DR_Addr ((u32)0x40003C0C)
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
DMA_DeInit(DMA2_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = SPI3_DR_Addr;
//DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)FPW_Cache.u8Arry;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 0;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//Byte
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//Byte
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA2_Channel1, &DMA_InitStructure);
DMA_ITConfig(DMA2_Channel1, DMA_IT_TC, DISABLE);
// Disable SPI3 DMA RX request //
SPI_I2S_DMACmd(SPI3, SPI_I2S_DMAReq_Rx, ENABLE);
DMA_Cmd (DMA2_Channel1,DISABLE);
DMA_DeInit(DMA2_Channel2);
DMA_InitStructure.DMA_PeripheralBaseAddr = SPI3_DR_Addr;
//DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)FPW_Cache.u8Arry;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = 0;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//Byte
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//Byte
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA2_Channel2, &DMA_InitStructure);
DMA_ITConfig(DMA2_Channel2, DMA_IT_TC, DISABLE);
DMA_ITConfig(DMA2_Channel2, DMA_IT_TE, DISABLE);
/* Disable SPI3 DMA TX request */
SPI_I2S_DMACmd(SPI3, SPI_I2S_DMAReq_Tx, ENABLE);
DMA_Cmd (DMA2_Channel2,DISABLE);
}
再附上完整代码,有需要的可以为你所用
Udisk.zip
(534.12 KB)
|