How to read gpio using dma in Input Capture mode
Hi,
I want to configure the DMA so that it transfers data from the GPIO lines (8 bit data lines) to the RAM buffer upon receiving a trigger signal on the timer capture input channel TIM1_CHI (PE9) . I am using stm32f446ze.We nees to acquire data register on rising edge of clock.
''https://www.st.com/content/ccc/resource/technical/document/application_note/7a/88/df/e3/d3/36/40/29/DM00169730.pdf/files/DM00169730.pdf/jcr:content/translations/en.DM00169730.pdf''
Based on above datasheet ( 1.2.1 Data reception (using DMA) ) , configurations made are as follows
void DMA_Init()
{
/* TIM1_CH1 : Stream 6 Channel 0 */
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;
DMA2_Stream6->CR &= ~DMA_SxCR_EN;
DMA2_Stream6->CR &= ~DMA_SxCR_CHSEL; // Channel 0 selected
DMA2_Stream6->CR |= DMA_SxCR_MINC | DMA_SxCR_PL_1 | DMA_SxCR_CIRC | DMA_SxCR_TCIE;
// Memory address pointer is incremented after each data transfer
// Priority level high
// Circular mode enabled
// TC interrupt enabled
DMA2_Stream6->NDTR = 1;
DMA2_Stream6->PAR = (uint32_t)&GPIOC->IDR; /* Read fron GPIO input data register */
DMA2_Stream6->M0AR = (uint32_t)&GPIO_DATA; /* Send the data to the RAM buffer */
DMA2_Stream6->CR |= DMA_SxCR_EN; // Stream enabled
NVIC_EnableIRQ(DMA2_Stream6_IRQn); // DMA2 Stream 6 global interrupt
}
void Timer_InputCapture_Init()
{
/* TIM1 channel 1 pin (PE9) configuration */
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN;
GPIOE->MODER |= BIT(19);
GPIOE->MODER &= ~BIT(18);
GPIOE->AFR[1] = BIT(4);
/* Timer1 configurations */
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; // TIM4 clock enable
TIM1->CCMR1 |= TIM_CCMR1_CC1S_0 | TIM_CCMR1_IC1F_0 | TIM_CCMR1_IC1F_1; // CC1S = 01
// IC1F = 0011
TIM1->CCER |= TIM_CCER_CC1P | TIM_CCER_CC1E; // rising edge
// Capture enabled
TIM1->DIER |= TIM_DIER_CC1DE; // CC1 DMA request enabled
TIM1->CR1 |= TIM_CR1_CEN; // TIM enable counter
}
void DMA2_Stream6_IRQHandler(void)
{
GPIOA->ODR ^= BIT(2);
gpio_readdata = GPIO_DATA;
DMA2->LIFCR =0xffffffff;
DMA2->HIFCR =0xffffffff;
}
but we are not sure , whether the program enters the ISR on the rising edge of the external clock input.We are having this doubt because we tried toggling a pin in ISR and we found that the pin toggles on the falling edge of the Clock.
How can i verify this?Please reply asap......
