用的是f205,因为系统需要50ms接收一次串口数据,所以使用中断的话,暂用硬件资源,没用操作系统。
问个问题,很奇怪,我使用的是DMA串口接收,加空闲中断。
结果我调试过程中,发送n次数据,只有第一次进入if(temp),求解?也就是说DMA没接收到数据?
[mw_shl_code=c,true]void USART2_IRQHandler(void)
{
uint16_t temp=0;
uint16_t i;
if(USART_GetITStatus(USART2, USART_IT_IDLE) != RESET)
{
DMA_Cmd(DMA1_Stream5, DISABLE);
temp = 256 - DMA_GetCurrDataCounter(DMA1_Stream5);
if(temp) //次数只进入一次
{
SysPostStack(uart2_receive_stack, (uint8_t*)USART2_RECEIVE_DATA, temp);
}
DMA_SetCurrDataCounter(DMA1_Stream5, 256);
DMA_Cmd(DMA1_Stream5, ENABLE);
i = USART1->SR;//????idle
i = USART1->DR;
}
//USART_ClearITPendingBit(USART2, USART_IT_IDLE);
}[/mw_shl_code]
我的DMA配置代码,如下:
[mw_shl_code=c,true]/* DMA1 Stream5 channe4 configuration USART2_RX*/[/mw_shl_code]
[mw_shl_code=c,true] RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
DMA_DeInit(DMA1_Stream5);
DMA_InitStructure.DMA_Channel = DMA_Channel_4;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)0x40004404;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)USART2_RECEIVE_DATA;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = 256;
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_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA1_Stream5, &DMA_InitStructure);
USART_DMACmd(USART2, USART_DMAReq_Rx, ENABLE);
DMA_Cmd(DMA1_Stream5, ENABLE);[/mw_shl_code]
|