测试出一现象,请大家帮忙分析一下:
我用SPI1做从机,DMA接收,由于我不确定会接收多少字节,就
DMA_InitStructure.DMA_BufferSize = 4096;
void SP1_DMA_INIT(void)
{
DMA_InitPara DMA_InitStructure;
RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_DMA1,ENABLE);
/* SPI_MASTER_Rx_DMA_Channel configuration */
DMA_DeInit(DMA1_CHANNEL2);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)0x4001300C;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SPI_ANDR_4KBUF_R;
DMA_InitStructure.DMA_DIR = DMA_DIR_PERIPHERALSRC;
DMA_InitStructure.DMA_BufferSize = 4096;
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_MTOM = DMA_MEMTOMEM_DISABLE;
DMA_Init(DMA1_CHANNEL2, &DMA_InitStructure);
/* SPI_MASTER_Tx_DMA_Channel configuration */
DMA_DeInit(DMA1_CHANNEL3);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)0x4001300C;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SPI_ANDR_4KBUF;
DMA_InitStructure.DMA_DIR = DMA_DIR_PERIPHERALDST;
DMA_InitStructure.DMA_BufferSize = 4096;
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_MTOM = DMA_MEMTOMEM_DISABLE;
DMA_Init(DMA1_CHANNEL3, &DMA_InitStructure);
}
问题就出现了,spi主机发了一个256字节数据(0x00~0xff),我就发现,我spi从机发出的最后一个字节
竟然会是7f!! 如果我DMA_InitStructure.DMA_BufferSize = 256,那就正常,最后一个就是0xff,这个不解。
spi设置如下:
void Android_SPI1_Conf(void)
{
SPI_InitPara SPI_InitStructure;
RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_SPI1, ENABLE);
/* SPI_MASTER configuration */
SPI_InitStructure.SPI_TransType = SPI_TRANSTYPE_FULLDUPLEX;
SPI_InitStructure.SPI_Mode = SPI_MODE_SLAVE;
SPI_InitStructure.SPI_FrameFormat = SPI_FRAMEFORMAT_8BIT;
SPI_InitStructure.SPI_SCKPL = SPI_SCKPL_LOW;
SPI_InitStructure.SPI_SCKPH = SPI_SCKPH_1EDGE;
SPI_InitStructure.SPI_SWNSSEN = SPI_SWNSS_SOFT;
SPI_InitStructure.SPI_PSC = SPI_PSC_8;//9M
SPI_InitStructure.SPI_FirstBit = SPI_FIRSTBIT_MSB;
SPI_InitStructure.SPI_CRCPOL = 7;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_I2S_DMA_Enable(SPI1, SPI_I2S_DMA_TX|SPI_I2S_DMA_RX, ENABLE);
SPI_Enable(SPI1, ENABLE);
SP1_DMA_INIT();
SPI_I2S_ClearBitState(SPI1,SPI_FLAG_RBNE|SPI_FLAG_TBE);
} |