2021-09-01 05:24 AM
I work on basic i2c example with DMA using HAL library. When i observed data in the debug section that data read correctly but DMA did not rise flag TCIF(transfer complete flag). What might be reason ?
void DMA1_Channel1_IRQHandler(void) {
if(__HAL_DMA_GET_FLAG(&hdma_i2c2_rx,DMA_FLAG_TC1)){
HAL_GPIO_TogglePin(LED_COM_BLUE_GPIO_Port, LED_COM_BLUE_Pin);
sprintf(prnt, "Id:%.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\r", Id[7], Id[6],
Id[5], Id[4], Id[3], Id[2], Id[1], Id[0]);
HAL_UART_Transmit(&huart1, (uint8_t*) prnt, strlen(prnt), 1000);
__HAL_DMA_CLEAR_FLAG(&hdma_i2c2_rx,DMA_FLAG_TC1);
}
}
#include "main.h"
#include <string.h>
#include <stdio.h>
I2C_HandleTypeDef hi2c2;
DMA_HandleTypeDef hdma_i2c2_rx;
UART_HandleTypeDef huart1;
uint8_t Id[8];
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_I2C2_Init(void);
static void MX_DMA_Init(void);
static void MX_USART1_UART_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_I2C2_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_Delay(1000);
HAL_I2C_Mem_Read_DMA(&hi2c2, 0xAE, 0x0018, 0x2,Id, sizeof(Id)/sizeof(Id[0]));
}
}
static void MX_I2C2_Init(void)
{
hi2c2.Instance = I2C2;
hi2c2.Init.Timing = 0x10707DBC;
hi2c2.Init.OwnAddress1 = 0;
hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c2.Init.OwnAddress2 = 0;
hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c2) != HAL_OK)
{
Error_Handler();
}
/** Configure Analogue filter
*/
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
{
Error_Handler();
}
/** Configure Digital filter
*/
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN I2C2_Init 2 */
// __HAL_DMA_ENABLE_IT(&hdma_i2c2_rx,DMA_IT_TC1);
__HAL_DMA_ENABLE_IT(&hdma_i2c2_rx,DMA_IT_TC);
hi2c2.Instance->CR1 |= I2C_CR1_RXDMAEN;
DMA1_Channel1->CNDTR=8;
/* USER CODE END I2C2_Init 2 */
}
static void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA1_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Channel1_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
2021-09-01 12:11 PM
Cube's interrupt handler might have already cleared TCIF. Instrument the real interrupt service routine (i.e. not the callback).
JW
2021-09-01 10:53 PM
I updated codes above. I also try like this and the problem is interrupt occurs 1 time and when i clear the flag , interrupt did not occurs any time .