使用STM32 DMA传输+空闲中断,实现任意长度数据接收,接收到从机设备发来的数据,始终第一个字节多一个0x00。各位大神,帮忙分析一下啊!
void USART1_IRQHandler(void)
{
uint8_t len = 0;
BaseType_t xHigherPriorityTaskWoken;
if(USART_GetITStatus(USART1,USART_IT_IDLE) != RESET) //
{
USART_ClearITPendingBit(USART1, USART_IT_IDLE);
len = USART1->SR;
len = USART1->DR;
DMA_Cmd(DMA2_Stream5,DISABLE);//1رսóêÕDMA
DMA_ClearFlag(DMA2_Stream5,DMA_FLAG_TCIF5);//Çå3yDMA′«êä±êÖ¾
len = Usart1_BufferSize - DMA_GetCurrDataCounter(DMA2_Stream5);//»ñ衽óêÕÖ¡3¤
Usart1_RxLength = len;
if(len > 0)
{
//·¢Ëíò»¸öDÅoÅá¿1y襣¬¾í¿éòÔ′|àíêy¾YáË
if(Usart1RxSemaphore != NULL)//DÅoÅá¿óDD§
{
xSemaphoreGiveFromISR(Usart1RxSemaphore,&xHigherPriorityTaskWoken);//êí·Å¶tÖμDÅoÅá¿
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
DMA_SetCurrDataCounter(DMA2_Stream5,Usart1_BufferSize);//éèÖÃêy¾Y′«êä3¤¶è
DMA_Cmd(DMA2_Stream5,ENABLE);//′ò¿aDMA
}
if(USART_GetITStatus(USART1, USART_IT_PE | USART_IT_FE | USART_IT_NE) != RESET)//3ö′í
{
USART_ClearITPendingBit(USART1, USART_IT_PE | USART_IT_FE | USART_IT_NE);
}
}
找到问题了,谢谢,485的A接了10K上拉,B接了10K下拉,A 、B之间接了120R,全部取了就好了,不知道是什么情况
这个怎么解释呢?
一周热门 更多>