我利用DMA+空闲中断,在调试的时候一直进不了中断,求解答
void RS485_Configuration()
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* Configure USART3 Tx (PB.10) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸´ÓÃÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USART3 Rx (PB.11) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //¸¡¿ÕÊäÈë
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //·×ªÆµÂÊ50MHz
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //·×ªÆµÂÊ50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);//TX½Å¸´ÓÃÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);//RX½Å¸¡¿ÕÊäÈë
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//ÍÆÍìÊä³ö
GPIO_Init(GPIOC, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;//²¨ÌØÂÊ
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//Êý¾Ýλ
USART_InitStructure.USART_StopBits = USART_StopBits_1;//ֹͣλ
USART_InitStructure.USART_Parity = USART_Parity_No;//ÎÞУÑé
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//Ó²¼þÁ÷¿ØÖÆʧÄÜ
USART_InitStructure.USART_Mode = USART_Mode_Rx;//·¢ËͽÓÊÕʹÄÜ
USART_Init(USART2, &USART_InitStructure);//´®¿Ú2³õʼ»¯
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//ʹÄܽÓÊÕÖжÏ
USART_Cmd(USART2, ENABLE);//´®¿Ú2ÍâÉèʹÄÜ
USART_InitStructure.USART_BaudRate = 9600 ;
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_Rx | USART_Mode_Tx;//ʹÄÜ·¢ËÍ/½ÓÊÕ
USART_Init(USART3, &USART_InitStructure); //´®¿Ú3³õʼ»¯
USART_ITConfig(USART3, USART_IT_IDLE, ENABLE); //ʹÄÜ¿ÕÏÐÖжÏ
USART_DMACmd(USART3,USART_DMAReq_Rx,ENABLE); //ʹÄÜDMA½ÓÊÕ
USART_Cmd(USART3, ENABLE);
}
/******************************************************************************
£»DMAÅäÖÃ
******************************************************************************/
void UART3_DMA_RX_Configuration()
{
DMA_InitTypeDef DMA_Initstructure;
DMA_Initstructure.DMA_PeripheralBaseAddr = (u32)(&USART3->DR);
DMA_Initstructure.DMA_MemoryBaseAddr = (u32)receive_data;
DMA_Initstructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_Initstructure.DMA_BufferSize = 20;
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_High;
DMA_Initstructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel3,&DMA_Initstructure);
DMA_Cmd(DMA1_Channel3,ENABLE);
//DMA_ITConfig(DMA1_Channel3,DMA_IT_TC,ENABLE);
}
/******************************************************************************
£»ÖжÏÓÅÏȼ¶ÅäÖÃ
******************************************************************************/
void NVIC_Configuration()
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//Ñ¡Ôñ×é2
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;//TIME2
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;//ÏÈÕ¼ÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;//´ÓÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//¿ªÆôTIME2ÖжÏ
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;//TIME3
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;//ÏÈÕ¼ÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;//´ÓÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//¿ªÆôTIME3ÖжÏ
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;//UART2
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//ÏÈÕ¼ÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;//´ÓÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//¿ªÆôUART2ÖжÏ
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;//UART3
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//ÏÈÕ¼ÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;//´ÓÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//¿ªÆôUART3ÖжÏ
NVIC_Init(&NVIC_InitStructure);
}
unsigned char aa;
void USART3_IRQHandler()
{
unsigned char num=0;
unsigned char n=0;
aa++;
if(USART_GetITStatus(USART3,USART_IT_IDLE) !=RESET)
{ num = USART3->SR;
num = USART3->DR;
DMA_Cmd(DMA1_Channel3,DISABLE);
num = 20 - DMA_GetCurrDataCounter(DMA1_Channel3);
DMA1_Channel3->CNDTR=20;
//if(floortemp==2 && switchdowntemp==1){
for(n=0;n<num;n++)
{
receive_buf1[n]=receive_data[n];
} //½ÓÊÕ5¸ö̽ͷÊý¾Ý
RX_Counter3++; //½ÓÊÕÊý×éλÖÃ+1
DMA_Cmd(DMA1_Channel3,ENABLE);
uart_receive_flag = 1;
}
}
|