本帖最后由 ast145 于 2016-3-16 13:24 编辑
stm32f407中USART1中使用DMA接收外设数据,数据传输方向为外设到内存,DMA接收串口数据,使能了传输一半和传输完成中断,但是现在问题是,cpu一直响应处理dma中断函数,其他的程序都都执行不了,请问大家可能会是什么问题?static void GPS_DMA_Config(void)
{
//??IO??????
GPIO_InitTypeDef GPIO_InitStructure;
//??DMA???
DMA_InitTypeDef DMA_InitStructure;
RCC_AHB1PeriphClockCmd(GPS_DMA_CLK, ENABLE);
DMA_Cmd(GPS_DMA_STREAM,DISABLE);
DMA_DeInit(DMA2_Stream5);
while ( DMA_GetCmdStatus(GPS_DMA_STREAM) != DISABLE );
DMA_InitStructure.DMA_Channel = DMA_Channel_4;
//????
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&USART1->DR);
//????
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)gps_rbuff; //´Ë´¦½ÓÊÕµØÖ·¿ÉÄÜÒª¸Ä
//dma????
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
//??DMA??????????
DMA_InitStructure.DMA_BufferSize = GPS_RBUFF_SIZE; //»º³åÊý¾Ý´óСÐèÒªÐÞ¸Ä
//??DMA???????,????
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
//??DMA???????
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
//??????
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
//??????
DMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_Byte;
//??DMA?????
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
//??DMA?????
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
//????FIFO?????????????? : ???FIFO??
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
//???FIFO????
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
//???Burst????????
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
//???Burst???????? */
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(GPS_DMA_STREAM, &DMA_InitStructure);
GPS_Interrupt_Config();
DMA_ITConfig(GPS_DMA_STREAM,DMA_IT_HT | DMA_IT_TC ,ENABLE);
DMA_Cmd (GPS_DMA_STREAM,ENABLE);
USART_DMACmd(GPS_USART, USART_DMAReq_Rx, ENABLE);
}
void GPS_Config(u32 br_num)
{
Usart1_Init(br_num);
GPS_DMA_Config();
}
//´Ë´¦ÅäÖõÄUSART1ûÓпªÖжÏʹÄÜ£¬ÓÃÓÚDMA½ÓÊÕ
void Usart1_Init(u32 br_num)
{
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStruct;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //¿ªÆôUSART1ʱÖÓ
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
//´®¿ÚÖжÏÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
//ÅäÖÃPA9×÷ΪUSART1¡¡Tx
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//ÅäÖÃPA10×÷ΪUSART1¡¡Rx
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//ÅäÖÃUSART1
//Öжϱ»ÆÁ±ÎÁË
USART_InitStructure.USART_BaudRate = br_num; //²¨ÌØÂÊ¿ÉÒÔͨ¹ýµØÃæÕ¾ÅäÖÃ
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //8λÊý¾Ý
USART_InitStructure.USART_StopBits = USART_StopBits_1; //ÔÚÖ¡½áβ´«Êä1¸öֹͣλ
USART_InitStructure.USART_Parity = USART_Parity_No; //½ûÓÃÆæżУÑé
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //Ó²¼þÁ÷¿ØÖÆʧÄÜ
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; //·¢ËÍ¡¢½ÓÊÕʹÄÜ
//ÅäÖÃUSART1ʱÖÓ
USART_ClockInitStruct.USART_Clock = USART_Clock_Disable; //ʱÖӵ͵çƽ»î¶¯
USART_ClockInitStruct.USART_CPOL = USART_CPOL_Low; //SLCKÒý½ÅÉÏʱÖÓÊä³öµÄ¼«ÐÔ->µÍµçƽ
USART_ClockInitStruct.USART_CPHA = USART_CPHA_2Edge; //ʱÖÓµÚ¶þ¸ö±ßÑؽøÐÐÊý¾Ý²¶»ñ
USART_ClockInitStruct.USART_LastBit = USART_LastBit_Disable; //×îºóһλÊý¾ÝµÄʱÖÓÂö³å²»´ÓSCLKÊä³ö
USART_Init(USART1, &USART_InitStructure);
USART_ClockInit(USART1, &USART_ClockInitStruct);
//ʹÄÜUSART1½ÓÊÕÖжÏ
//USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
//ʹÄÜUSART1
USART_Cmd(USART1, ENABLE);
// //ʹÄÜ·¢ËÍ£¨½øÈëÒÆ룩ÖжÏ
// if(!(USARTQ->CR1 & USART_CR1_TXEIE))
// {
// USART_ITConfig(USARTQ, USART_IT_TXE, ENABLE);
// }
}
下面是中断处理函数,中断程序函数名和重写了,现在问题就是程序出中断,进中断,始终执行这个中断函数void GPS_ProcessDMAIRQ(void)
{
if(DMA_GetITStatus(GPS_DMA_STREAM,GPS_DMA_IT_HT) )
{
GPS_HalfTransferEnd = 1;
DMA_ClearFlag(DMA2_Stream5,DMA_FLAG_HTIF5);
}
if(DMA_GetITStatus(GPS_DMA_STREAM,GPS_DMA_IT_TC))
{
GPS_TransferEnd = 1;
DMA_ClearFlag(DMA2_Stream5,DMA_FLAG_TCIF5);
}
}
|