SPI2口以i2s模式数据发送,直接往SPI->DR送数据,正常。要提高效率,配置到DMA模式送数据,无法启动数据发送。
望指教。
DMA 配置的代码:
static void DMA_i2sTxConfiguration(uint16_t *BufferSRC, uint32_t BufferSize)
{
DMA_InitTypeDef DMA_InitStructure;
/* DISABLE the SPI2/I2S2 peripheral */
I2S_Cmd(SPI2, DISABLE);
DMA_ClearFlag(DMA1_FLAG_TC5 | DMA1_FLAG_TE5 | DMA1_FLAG_HT5 | DMA1_FLAG_GL5);
/* DMA1 Channel4 disable */
DMA_Cmd(DMA1_Channel5, DISABLE);
/* DMA1 Channel4 Config */
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&SPI2->DR;
printf("addr:%x\r\n", DMA_InitStructure.DMA_PeripheralBaseAddr);
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)BufferSRC;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = BufferSize / 2;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_HalfWord;
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);
// 允许DMA数据发送
SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Tx, ENABLE);
/* DMA1 Channel5 enable */
DMA_Cmd(DMA1_Channel5, ENABLE);
/* ENABLE the SPI2/I2S2 peripheral */
I2S_Cmd(SPI2, ENABLE);
} |