2016-07-03 01:49 AM
Hello,
I generated the code using the STM32CubeMx.I'm trying to I2C communication between STM32F4(master) and IC(slave, 7bit address).I tested to two functions for I2C communication.HAL_I2C_Mem_Write is OK, but HAL_I2C_Mem_Write_DMA is fail.Test condition and setting parameters are same only except the function.please let me know why HAL_I2C_Mem_Write_DMA() is didn't work.thank you.==================================================================//test code/* I2C1 init function */static void MX_I2C1_Init(void){ hi2c1.Instance = I2C1; hi2c1.Init.ClockSpeed = 100000; hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; hi2c1.Init.OwnAddress1 = 0; hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; hi2c1.Init.OwnAddress2 = 0; hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; if (HAL_I2C_Init(&hi2c1) != HAL_OK) { Error_Handler(); }}static void MX_DMA_Init(void) { /* DMA controller clock enable */ __HAL_RCC_DMA1_CLK_ENABLE(); /* DMA interrupt init */ /* DMA1_Stream0_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn); /* DMA1_Stream2_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA1_Stream2_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DMA1_Stream2_IRQn); /* DMA1_Stream4_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA1_Stream4_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DMA1_Stream4_IRQn); /* DMA1_Stream6_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA1_Stream6_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DMA1_Stream6_IRQn);}void main(void){ uint8_t error; uint8_t data[3]; data[0] = 0x47; error = HAL_I2C_Mem_Write(&hi2c1, 0x82, 0x3f, 1, data, 1,100); //succeed error = LT_I2C_Write_DMA(<_i2c1_, 0x82, 0x3f, data, 1); //fail}success: HAL_I2C_Mem_Write(Dev Add: 0x82, Mem Add: 0x3f, data: 0x47)
FAIL: HAL_I2C_Mem_Write_DMA(Dev Add: 0x82, Mem Add: 0x3f, data: 0x47)2018-10-31 09:04 AM
Hi Sergei. Can you tell how you fix it problem please. Is it true to add the following code to main.c
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c)
{
if(hi2c->Instance==hi2c1.Instance)
{
I2C_MasterTransmit_BTF(hi2c);
}
}
2018-10-31 09:08 AM
Hi. Can you tell how you fix it problem please. Is it true to add the following code to main.c
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c)
{
if(hi2c->Instance==hi2c1.Instance)
{
I2C_MasterTransmit_BTF(hi2c);
}
}
2019-09-27 11:05 PM
Hello dspark, i want to ask you one thing that you given data=0x47,what does it mean,means which data?