cancel
Showing results for 
Search instead for 
Did you mean: 

In my I2C Slave program the Callbacks are not being called.

KiptonM
Lead

I am using HAL_I2C_Slave_Receive_DMA() function and am putting flags in each of the Callbacks which I have redefined in my code from the weak ones in stm32g0xx_hal_i2c.c.

I have also tried putting breakpoints in the callback functions to see if it foes there.

There is no indication that it is.

My HAL_UART_Transmit_DMA() function is working. And it is calling the HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) function.

So I know interrupts are turned on. I did not have to enable anything in the interrupts the HAL took care of that.

I went into stm32g0xx_hal_conf.c and modified the line

#define USE_HAL_I2C_REGISTER_CALLBACKS  1u

So it used all the callbacks.

Looking at the hi2c1 structure, there are valid addresses in each of the callback pointers. Right now I cannot verify whether they are using the default weak ones or mine. But according to the documentation if I define them they should override the weak ones.

When I use the HAL_I2C_Mem_Write_DMA() in the master STM32G031K8 the data shows up correctly in the slave, but I cannot see that any of the callbacks were executed.

When I use the HAL_I2C_Mem_Read_DMA() in the master the written data shows up correctly in the slave buffer until after the restart, where it hangs because I have no indication from any callback that I need to do anything, like read the data and write back the results.

That tells me that the I2C device is enabled. But nothing is happening.

With the UART I did not have to go into the configuration register and enable the individual interrupts, the HAL did that. Is that not the case for the I2C?

I am using the HAL_Delay() function. So I made the UART, and I2C interrupts level 3 priority.

I made the DMA interrupts level 2 priority.

I made the sys_tick interrupt level 1.

The rest are left at the defaut 0.

I am only using the UART and I2C at present. No ADC and no timers. No other peripheral interrupts.

On Page 341/2202 of UM2319 Rev 2 it says "Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx or Rx Channel. "

I set the priorities, as I mentioned above. I enabled the interrupts and set the priorities in the MX program. Do I have to do something else? The documentation is very sparse about the details.

Is the HAL_I2C_Slave_Receive_DMA() function the one I should be using while waiting for data with my device address to show up on the bus? Or Should I be using HAL_I2C_Slave_Seq_Receive_DMA()? The documentation is not very clear the plusses and minuses of either function.

While searching for how to fix this, I found another example that used the AddrCallback() to see if the device was accessed. Then they did something based on the address and the direction. Mine is simpler. In most cases it looks like a 16-bit memory location they send a 16-bit address, and get a 16-bit response. So I know they will always send me at least two bytes. And if it is a write it could be 2 more. If it is a read, then they will send a restart, and the address with a read. What interrupt should happen then to let me know I should send something?

Back to the original question, what could I be missing to prevent the callbacks from being executed?

Thanks,

Kip

11 REPLIES 11

I went with the implementing the same functions with the exact same names to let the linker favor the non-weak names. Thanks. It is working now.

Great. Note that your mods in stm32g0xx_hal_conf.h will be overwritten by the next code generation. There is a tab for it in the .ioc Project Manager > Advanced Settings

hth

KnarfB