下面的IRQ处理程序会耗尽传入的32字节数据的USART3。第一个IRQ TC事件读取前6个字节,然后重新编程DMA引擎以读取最后24个字节。第二个TC将其重新编程以再次读取报头此方法将允许使用DMA的可变长度消息。不过,我似乎无法改变DMA的起始地址。我希望能够将每条消息存储在一个单独的缓冲区中,但是它只是在接收每条消息时在上面写入第一个缓冲区。我做错什么了?微控制器是一个STM32F103ze(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);
}

最佳答案

你说:
…重新编程DMA引擎以读取最后24个字节。
但你的密码说:
DMA_SetCurrDataCounter(DMA1_Channel3,26);
对吗?是24点还是26点?

10-07 13:37