Hi~
I want to use SPI read data from device via DMA to decrease SPI wait time.
But I have no idea what wrong with these settings!
There have no SPI wave on the scope.
Please kindly to tell me what wrong I did, many thanks.
void API_SPI_DMA_Read_Bytes(u16 *pu16Buffer, u16 u16Len)
{
SPI_InitTypeDef SPI_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
DMA_Cmd(SPI_DMA_CHANNEL, DISABLE);
//DMA_DeInit(SPI_DMA_CHANNEL);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&SPI1->DR;//SPI1_DR_Base;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)pu16Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = (u32)u16Len/2;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(SPI_DMA_CHANNEL, &DMA_InitStructure);
SPI_InitStructure->SPI_Direction = SPI_Direction_2Lines_RxOnly;//SPI_Direction_1Line_Rx;
SPI_InitStructure->SPI_Mode = SPI_Mode_Master;
SPI_InitStructure->SPI_DataSize = SPI_DataSize_16b;
SPI_InitStructure->SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure->SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure->SPI_NSS = SPI_NSS_Soft;//SPI_NSS_Hard;
SPI_InitStructure->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
SPI_InitStructure->SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure->SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Rx, ENABLE);
/* Enable SPI1 */
SPI_Cmd(SPI1, ENABLE);
// SPI_DMA_CHANNEL = DMA1_Channel2
DMA_Cmd(SPI_DMA_CHANNEL, ENABLE);
/* Chip Select low */
SPI_CS_LOW();
while (u16Len>0)
{
//while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
//SPI_I2S_ReceiveData(SPI1);
API_SPI_SendByte(0);
u16Len -= 2;
}
// SPI_DMA_RX_FLAG = DMA1_FLAG_TC2
while(!DMA_GetFlagStatus(SPI_DMA_RX_FLAG));
/* Chip Select high */
SPI_CS_HIGH();
}