1453111536 发表于 2017-2-17 09:56 从模式 void DMA2_Stream0_IRQHandler(void) { if(DMA_GetITStatus(DMA2_Stream0,DMA_IT_TCIF0)==SET) { DMA_Cmd(DMA2_Stream0,DISABLE); DMA_ClearITPendingBit(DMA2_Stream0,DMA_IT_TCIF0); DMA_Cmd(DMA2_Stream5, ENABLE); } } void DMA2_Stream5_IRQHandler(void) { if(DMA_GetITStatus(DMA2_Stream5,DMA_IT_TCIF5)==SET) { DMA_Cmd(DMA2_Stream5,DISABLE); DMA_ClearITPendingBit(DMA2_Stream5,DMA_IT_TCIF5); } } void EXTI15_10_IRQHandler(void ) { if(EXTI_GetITStatus(EXTI_Line15) != RESET) { if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_15) == Bit_RESET) { DMA_Cmd(DMA2_Stream0, ENABLE); } if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_15) == Bit_SET) { DMA_Cmd(DMA2_Stream5, DISABLE); DMA_Cmd(DMA2_Stream0, DISABLE); } EXTI_ClearITPendingBit(EXTI_Line15); } } void SPISCfgPort(void) { GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; DMA_InitTypeDef DMA_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 |RCC_APB2Periph_SYSCFG, ENABLE); RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_DMA2 , ENABLE); //复用 GPIO_PinAFConfig(GPIOB,GPIO_PinSource3,GPIO_AF_SPI1); GPIO_PinAFConfig(GPIOB,GPIO_PinSource4,GPIO_AF_SPI1); GPIO_PinAFConfig(GPIOB,GPIO_PinSource5,GPIO_AF_SPI1); GPIO_PinAFConfig(GPIOA,GPIO_PinSource15,GPIO_AF_SPI1); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_Init(GPIOA, &GPIO_InitStructure); //EXIT SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, GPIO_PinSource15); EXTI_ClearITPendingBit(EXTI_Line15); EXTI_InitStructure.EXTI_Line = EXTI_Line15; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); //NVIC NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //DMA DMA_DeInit(DMA2_Stream0); DMA_DeInit(DMA2_Stream5); DMA_InitStructure.DMA_Channel = DMA_Channel_3; DMA_InitStructure.DMA_BufferSize = MAX_BUFF_LEN; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull ; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single ; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&(SPI1->DR)); DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_Priority = DMA_Priority_High; /* Configure TX DMA */ DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Buff.BuffTx; DMA_Init(DMA2_Stream5, &DMA_InitStructure); DMA_ITConfig(DMA2_Stream5,DMA_IT_TC,ENABLE); /* Configure RX DMA */ DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory ; DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)Buff.BuffRx; DMA_Init(DMA2_Stream0,&DMA_InitStructure); DMA_ITConfig(DMA2_Stream0,DMA_IT_TC,ENABLE); //SPI1设置 SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Slave; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI1, &SPI_InitStructure); SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Tx, ENABLE); SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Rx, ENABLE); SPI_Cmd(SPI1, ENABLE); DMA_Cmd(DMA2_Stream5, DISABLE); DMA_Cmd(DMA2_Stream0, DISABLE); }
所在话题
参与活动
-
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
线下 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
网络 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
网络 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
网络 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
线下 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
线下 2020-10-16