下面的IRQ处理程序会耗尽USART 3的32字节数据。第一个IRQ TC事件读取前6个字节,然后重新编程DMA引擎以读取最后24个字节。第二个TC将其重新编码以再次读取报头。此方法将允许使用DMA的可变长度消息。但是,我似乎无法更改DMA起始地址。我想能够存储在一个单独的缓冲区,但它只是在收到每个消息后,第一个缓冲区写的每一个消息。我做错了什么?微控制器是STM32F103 ze(Cortex-M3)。
void DMA1_Channel3_IRQHandler(void)
{
uint32_t tmpreg = 0;
/* Test on DMA1 Channel3 Transfer Complete interrupt */
if(DMA_GetITStatus(DMA1_IT_TC3))
{
if (rx3_dma_state == RECIEVE_HEADER )
{
DMA_Cmd(DMA1_Channel3, DISABLE);/* Disable DMA1_Channel2 transfer*/
// Now that have received the header. Configure the DMA engine to receive
// the data portion of the message
DMA_SetCurrDataCounter(DMA1_Channel3,26);
DMA_Cmd(DMA1_Channel3, ENABLE);
} else if ( rx3_dma_state == RECIEVE_MSG )
{
//CurrDataCounterEnd3 = DMA_GetCurrDataCounter(DMA1_Channel3);
DMA_Cmd(DMA1_Channel3, DISABLE);
/* Get Current Data Counter value after complete transfer */
USART3_Rx_DMA_Channel_Struct->CMAR = (uint32_t) RxBuffer3LookUp[rx_buffer_index];
DMA_SetCurrDataCounter(DMA1_Channel3, 6);
DMA_Cmd(DMA1_Channel3,ENABLE);
// Set up DMA to write into the next buffer slot (1 of 8)
++rx_buffer_index;
rx_buffer_index %= 8;
}
/* Clear DMA1 Channel6 Half Transfer, Transfer Complete and Global interrupt pending bits */
DMA_ClearITPendingBit(DMA1_IT_GL3);
}
// Update the state to read fake header of 6 bytes
// or to read the fake data section of the message 26 bytes
++rx3_dma_state;
rx3_dma_state %= 2;
isr_sem_send(dma_usart3_rx_sem);
}
字符串
1条答案
按热度按时间1l5u6lss1#
你就说:
...对DMA引擎重新编程,以读入最后24个字节。
但是你的代码说:
DMA_设置当前数据计数器(DMA 1_通道3,26);
是这样吗?是24还是26?