Struggling to receive messages on SMBUS
I am studying the SMBUS stack code to understand how it works. My system has a smart battery. The battery periodically emits two messages intended for the charger (charging voltage and charging current). My software is the host. Sending commands to the battery is working just fine. As an exercise I am trying to receive the two charger messages. Following (more or less) the ST code I do this:
- Set own address to the expected charger address
- Call HAL_SMBUS_EnableListen_IT()
- enables ADDR interrupt, I guess
- On ADDR interrupt, AddrCallback is called
- Call HAL_SMBUS_Slave_Receive_IT() to receive one byte (the command ID)
- On completion, SlaveRxCpltCallback() is called
- Call HAL_SMBUS_Slave_Receive_IT() to receive remaining bytes of the command
- On completion, SlaveRxCpltCallback() is called a second time
- Call HAL_SMBUS_EnableListen_IT() to set up for the next command
This apparently works perfectly for the first command. I get the ADDR interrupt, the command byte and the data bytes, and I see STOP on the bus. But then... For the second command, about 1s later, I don't see the ADDR interrupt. I can see that the bus is held low for a bit, stretching the clock, and then I get the error interrupt.
I'll have to add some code to log the register values upon each interrupt, but was hoping for some insight here. I realise this is a bit vague, but what might I be missing? I have looked at the reference manual and found the interaction of some of the control bits a little unclear. I note that the SBC bit has been set when it wasn't previously, but clearing it after the first command is done has no effect.
