香主你好:
我做SPI DMA接收的试验,使用ST的例程。操作没有问题。
可是不能实现循环接收,例程是发送一次,而后查询标志,就结束了。
如何实现不断查询标志的接收啊,也就是接收循环起来!!!万分感谢。
int main(void) { #ifdef DEBUG debug(); #endif
/* System clocks configuration ---------------------------------------------*/ RCC_Configuration();
/* NVIC configuration ------------------------------------------------------*/ NVIC_Configuration();
/* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration();
/* DMA1 channel4 configuration ---------------------------------------------*/ DMA_DeInit(DMA1_Channel4); DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)SPI2_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (u32)SPI2_Buffer_Rx; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = BufferSize; 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_VeryHigh; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel4, &DMA_InitStructure);
/* SPI1 configuration ------------------------------------------------------*/ SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Hard; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI1, &SPI_InitStructure);
/* SPI2 configuration ------------------------------------------------------*/ SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Rx; SPI_InitStructure.SPI_Mode = SPI_Mode_Slave; SPI_Init(SPI2, &SPI_InitStructure);
/* Enable SPI1 NSS output for master mode */ SPI_SSOutputCmd(SPI1, ENABLE);
/* Enable SPI2 Rx request */ SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Rx, ENABLE);
/* Enable SPI2 */ SPI_Cmd(SPI2, ENABLE); /* Enable SPI1 */ SPI_Cmd(SPI1, ENABLE);
/* Enable DMA1 Channel4 */ DMA_Cmd(DMA1_Channel4, ENABLE);
/* Transfer procedure */ while (TxIdx < BufferSize) { /* Wait for SPI1 Tx buffer empty */ while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); /* Send SPI1 data */ SPI_I2S_SendData(SPI1, SPI1_Buffer_Tx[TxIdx++]); }
/* Wait for DMA1 channel4 transfer complete */ while (!DMA_GetFlagStatus(DMA1_FLAG_TC4));
/* Check the corectness of written data */ TransferStatus = Buffercmp(SPI2_Buffer_Rx, SPI1_Buffer_Tx, BufferSize); /* TransferStatus = PASSED, if the transmitted and received data are equal */ /* TransferStatus = FAILED, if the transmitted and received data are different */
while (1) {} }
|