void SPI_Configuration(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE);
/* PB15-MOSI2,PB13-SCK2*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14| GPIO_Pin_15;
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_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB,&GPIO_InitStructure);
/* SPI2 configuration */
SPI_Cmd(SPI2, DISABLE); //必须先禁能,才能改变MODE
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //两线全双工
SPI_InitStructure.SPI_Mode = SPI_Mode_Slave; //主
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //16位
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //CPOL=1
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; //CPHA=1
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //软件NSS
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; //2分频
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //高位在前
SPI_InitStructure.SPI_CRCPolynomial = 7; //CRC7
SPI_Init(SPI2, &SPI_InitStructure);
SPI_Cmd(SPI2, ENABLE);
SPI_I2S_DMACmd(SPI2,SPI_I2S_DMAReq_Rx,ENABLE);
// SPI_CalculateCRC(SPI2, ENABLE);
// SPI_I2S_ITConfig(SPI2,SPI_I2S_IT_RXNE,ENABLE);
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/*UART2*/
// NVIC_InitStructure.NVIC_IRQChannel = SPI2_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
// NVIC_Init(&NVIC_InitStructure);
#if 1
/*DMA的配置 */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
/* DMA通道1*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr =(u32)(&(SPI2->DR)); //ADC1数据寄存器
DMA_InitStructure.DMA_MemoryBaseAddr =(u32)(DmaBuf); //获取ADC的数组 要存放的位置
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //片内外设作源头
DMA_InitStructure.DMA_BufferSize = DMA_DEBUGINITSIZE; // DMA_SENSORBUFSIZE; //每次DMA16个数据
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_Circular; //普通模式
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //高优先级
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //非内存到内存
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC|DMA_IT_TE, ENABLE); //DMA通道1传输完成中断
/* Enable DMA1 channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Enable DMA channel6 IRQ Channel */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#endif
}
就是进不了中断,为什么呢,高手解答下吧 |