c - 使用 STM32F103 微 Controller (Cortex-M3) 重新编程 DMA 起始地址

标签 c linked-list microcontroller cortex-m3 dma

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

最佳答案

你说:

...reprograms the DMA engine to read in the last 24 bytes.

但是你的代码说:

DMA_SetCurrDataCounter(DMA1_Channel3,26);

是吗?是 24 还是 26?

关于c - 使用 STM32F103 微 Controller (Cortex-M3) 重新编程 DMA 起始地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7799891/

相关文章:

c - 为什么我在第二次搜索文件时收到段错误错误?

C 基于用户输入的每行字符缩进

java - 反转链表中的 K 个节点

c - atmega8a 熔断外部晶振 16MHz

c - 将字母定义为字符

c - 在 C 中 move 当前堆栈帧

c - 尝试使用 Sublime Text 2 编译 C 但无法使用 scanf 输入任何内容

c++ - 将链表的大小从 '__int64' 截断为 'size_t

c - PIC单片机如何添加两个超声波传感器

c - 我怎么知道编译器是否会优化一个变量?