stm32h7的TIM2 DMA配置,数据不能传输

2019-07-14 18:05发布

我遇到的问题是无法在输入捕获事件上配置DMA以正常工作,数据不能传输并发生错误。
static void my_TIM2_initInputCaptureTimer(void) {

  // enable clock source for timer
  RCC->APB1LENR |= (0x1 << 0);
  // set prescaler to 200
  TIM2->PSC = 200 - 1;

  // choose TIM2_CH1 input
  TIM2->TISEL |= (0x0 << 0);
  // set channel 1 as input mapped on TI1
  TIM2->CCMR1 |= (0x1 << 0);
  // digital filter length (0)
  TIM2->CCMR1 |= (0x0 << 4);
  // rising & falling edge
  TIM2->CCER |= (0x1 << 1);
  TIM2->CCER |= (0x1 << 3);
  // prescaler to (0)
  TIM2->CCMR1 |= (0x0 << 2);
  // enable DMA interrupt & Capture/Compare interrupt
  TIM2->DIER |= (0x1 << 9) | (0x1 << 1);
  // capture enabled
  TIM2->CCER |= (0x1 << 0);
  // reset registers WARNING: need for preloading PSC  
  TIM2->EGR |= (0x1 << 0);

  // enable TIM3 timer
  TIM2->CR1 |= TIM_CR1_CEN;
  // enable interrupt request
  NVIC_EnableIRQ(TIM2_IRQn);
  // set priority
  NVIC_SetPriority(TIM2_IRQn, 1);

}
DMA配置:
static void my_DMA_init(void) {
  // enable DMA1 clocking
  RCC->AHB1ENR |= (0x1 << 0);
  // clear EN bit to 0
  DMA1_Stream0->CR &= ~(0x1 << 0);
  // safeguard EN bit reset
  while (DMA1_Stream0->CR & 0x1);
  // check LISR HISR registers
  if ((DMA1->HISR == 0) && (DMA1->LISR == 0))
    printf("status registers is clear ");
  else
    printf("status register is not clear -- DMA wont start ");
  // set peripheral addres
  DMA1_Stream0->PAR = TIM2_CCR1_Address;
  // set memory addres
  DMA1_Stream0->M0AR = (unsigned int)buffer;
  // set total number of data items
  DMA1_Stream0->NDTR = 10;

  // NOTE: configurate TIM2_CH1 interrupt route
  // set DMAMUX to route request (TIM2_CH1)
  DMAMUX1_Channel0->CCR |= 18U;

  // set DMA priority (very high)
  DMA1_Stream0->CR |= (0x3 << 16);
  // set memory data size (32)
  DMA1_Stream0->CR |= (0x2 << 13);
  // set peripheral data size (32)
  DMA1_Stream0->CR |= (0x2 << 11);
  // set memory addres increment  (enable)
  DMA1_Stream0->CR |= (0x1 << 10);
  // set peripheral addres increment (disable)
  DMA1_Stream0->CR |= (0x0 << 9);
  // set circular buffer mode (enable)
  DMA1_Stream0->CR |= (0x1 << 8);
  // set data transfer direction (peripheral to memory)
  DMA1_Stream0->CR |= (0x0 << 6);
  // set transfer complete interrupt
  DMA1_Stream0->CR |= (0x1 << 4);
  // set transfer error interrupt
  DMA1_Stream0->CR |= (0x1 << 2);
  // enable DMA1
  DMA1_Stream0->CR |= (0x1 << 0);
  // enable IRQ
  NVIC_EnableIRQ(DMA1_Stream0_IRQn);
  printf("DMA1_Stream0 %u ", (DMA1_Stream0->CR & 0x1));}
中断例程:
  1. void TIM2_IRQHandler(void) {

  2.   InCapTick = TIM2->CCR1;
  3.   // reset interrupt flag
  4.   TIM2->SR = 0;

  5.   tick = systick_ms;
  6.   flag++;
  7. }

  8. void DMA1_Stream0_IRQHandler(void) {

  9.   printf("within ");
  10.   printf("LISR: %u ", DMA1->LISR);
  11.   // clear interrupt flag
  12.   DMA1->LIFCR |= (0x1 << 3) | (0x1 << 5);

  13. }
复制代码
STM32h743zi-nucleo board)预期行为:(当你按下用户按钮(蓝 {MOD}的那个) - > PG0引脚得到SET(1)状态 - >所以输入捕获引脚(PA5,它们应该通过跳线连接)得到低 - 高当你释放按钮时,转换并捕获第一个值(通过com-port输出),输入捕获引脚获得高 - 低转换并捕获另一个值(通过com-port输出),但这些事件都没有启动DMA请求。




0条回答

一周热门 更多>