GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
DMA_DeInit(DMA1_Channel3);
DMA_InitStructure.DMA_BufferSize = 0;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) & (SPI1->DR); //
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SPiTram.TramBuff; //ÉèÖÃSRAM´æ´¢µØÖ·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //´«Êä·½Ïò ÄÚ´æ->ÍâÉè
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //ÉèÖÃSPIµÄ½ÓÊÕ³¤¶È
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_MemoryDataSize_HalfWord; //ÄÚ´æ´«Êä¿í¶È
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; //´«Ê䷽ʽ£¬Ò»´Î´«ÊäÍêÍ£Ö¹£¬²»ÖØмÓÔØ
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //½ûÖ¹DMAÄÚ´æµ½ÄÚ´æ´«Êä
DMA_Init(DMA1_Channel3, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel3, ENABLE);
// SPI_I2S_DeInit(SPI1);
SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Tx, ENABLE);
SPI_StructInit(&SPI_InitStructure);
SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;//SPI_Direction_Tx;//µ¥¹¤Í¨ÐÅ Ö»·¢ËÍ
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;//16λ·¢ËÍ£¬DMAÒ²ÊÇ16λ´«ËÍÊý¾Ý
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;//12MHZ
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //ÏÈ´«¸ß×Ö½Ú
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_7;//SPIÒ»¶¨Òª³õʼ»¯SCK(PA5)½Å²ÅÄÜÆôÓÃSPI£¬¼´Ê¹²»Óõ½SCK(PA5)½Å
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource5,GPIO_AF_0);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource7,GPIO_AF_0);
SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Tx, ENABLE);
/********** 更新一次数据 ********/
if(DMA_GetCurrDataCounter(DMA1_Channel3) == 0)
{
DMA_Cmd(DMA1_Channel3, DISABLE);
DMA_ClearFlag(DMA1_FLAG_TC3);//发送完成标志
DMA_SetCurrDataCounter(DMA1_Channel3, 96);//数据长度96
DMA_Cmd(DMA1_Channel3, ENABLE);
}
配置代码如上;
问题是使用示波器测量:SPI-MOSI引脚GPIOA_PIN7并没有数据输出,仿真能看到有跑进去更新数据发送那里。不知道哪里配置有问题,如果是用循环发送那种方式就看到有数据 |