I have an external ADC with 2 parallel output pins. Each is 1 bit (2 bits total), with clk_out pin.
I am trying to read the parallel pins using a NUCLEO-H743ZI2 (480 Mhz). I followed the AN4666 example to receive the data. clk_out is connected to PA6 which is defined as a TIMER with input capture and it triggers the DMA to GPIO pins and saves it to memory.
Unfortunately my code reads the pins only once and I was expecting that it would read every falling edge of the clk_out. All I am trying to do is make the DMA read every falling edge.
Here is my code.
#include "main.h" /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ #define MAX_FRAME_SIZE 100 #define BUFFER_SIZE 20 #define HALF_BUFFER_SIZE BUFFER_SIZE/2 /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ volatile int LastITHalfComplete = 0; volatile int32_t FullDataIndex = 0; volatile int i = 0; volatile uint8_t transferComplete = 0; /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ TIM_HandleTypeDef htim1; DMA_HandleTypeDef hdma_tim1_ch1; UART_HandleTypeDef huart3; PCD_HandleTypeDef hpcd_USB_OTG_FS; /* USER CODE BEGIN PV */ static uint8_t aFull_Buffer[MAX_FRAME_SIZE] = {0}; static uint8_t aDST_Buffer[BUFFER_SIZE] = {0}; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART3_UART_Init(void); static void MX_USB_OTG_FS_PCD_Init(void); static void MX_TIM1_Init(void); static void MX_DMA_Init(void); /* USER CODE BEGIN PFP */ static void TransferComplete(DMA_HandleTypeDef *hdma_tim1_ch1); static void TransferError(DMA_HandleTypeDef *hdma_tim1_ch1); static void HalfTransferComplete(DMA_HandleTypeDef *hdma_tim1_ch1); /* USER CODE END PFP */ /* Private user code */ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART3_UART_Init(); MX_USB_OTG_FS_PCD_Init(); MX_TIM1_Init(); MX_DMA_Init(); /* USER CODE BEGIN 2 */ // Attach DMA callback functions htim1.hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = HalfTransferComplete; htim1.hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TransferComplete; htim1.hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TransferError; // Start DMA in interrupt mode, specify source and destination HAL_DMA_Start_IT(htim1.hdma[TIM_DMA_ID_CC1], (uint32_t) &GPIOC->IDR, (uint32_t) &aDST_Buffer, 1); // Enable timer to trigger DMA transfer - CC1DE bit __HAL_TIM_ENABLE_DMA(&htim1, TIM_DMA_CC1); // Enable timer input capture HAL_TIM_IC_Start(&htim1, TIM_CHANNEL_1); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ /* USER CODE BEGIN WHILE */ while (1) { //if (transferComplete) { //transferComplete = 0; // Transmit buffer to UART // Prepare data into buffer //HAL_UART_Transmit_IT(&huart3, buff, LEN); //} /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } The interrupts:
/* USER CODE BEGIN 4 */ static void HalfTransferComplete(DMA_HandleTypeDef *hdma_tim1_ch1) { int position = 0; LastITHalfComplete = 1; /*Copy the first part of the received buffer */ for (int i = 0; i < HALF_BUFFER_SIZE; i++) { aFull_Buffer[FullDataIndex] = aDST_Buffer[i+position]; FullDataIndex++; HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_1); } } static void TransferComplete(DMA_HandleTypeDef *hdma_tim1_ch1) { int position = HALF_BUFFER_SIZE; LastITHalfComplete = 0; /* Copy the second part of the received buffer */ for (int i = 0; i < HALF_BUFFER_SIZE; i++) { aFull_Buffer[FullDataIndex] = aDST_Buffer[i+position]; FullDataIndex++; HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0); } transferComplete = 1;} static void TransferError(DMA_HandleTypeDef *hdma_tim1_ch1) { HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_14); } void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart3) { // Enable again DMA for a new transfer HAL_DMA_Start_IT(htim1.hdma[TIM_DMA_ID_CC1], (uint32_t) &GPIOC->IDR, (uint32_t) aDST_Buffer, BUFFER_SIZE); }