Any example code available to implement smbus(master and slave) interrupt mode on stm32f091rc ? Tried using the HAL functions was not successful?

In Master mode to transmit I use

while(1) { while(HAL_SMBUS_Master_Transmit_IT(hsmbus,sladd ,command_code,THREE_BYTE,SMBUS_LAST_FRAME_NO_PEC)!= HAL_OK); HAL_SMBUS_Master_Transmit_IT(hsmbus, sladd, command_code , THREE_BYTE,SMBUS_LAST_FRAME_NO_PEC); } sladd is slave address. command code is 3 byte array.

In Slave Mode to receive on 2nd MCU(same as master controller ) Also I am calling HAL_SMBUS_EnableListen_IT(&hsmbus1); to set the state in listening mode,because the Interrupt would only be enabled if smbus state was in listening mode, again this is not very clear in HAL user manual. while(1) { while(HAL_SMBUS_Slave_Receive_IT(&hsmbus1, receive_buffer, 3, SMBUS_FIRST_AND_LAST_FRAME_NO_PEC )!= HAL_OK); HAL_SMBUS_Slave_Receive_IT(&hsmbus1, receive_buffer, 3, SMBUS_FIRST_AND_LAST_FRAME_NO_PEC ); } Actually I am not sure about where to call transmit and receive function(in while(1) or outside) since it is interrupt based we shouldn't be calling function in while(1) let me know if I am right or wrong? Also wanted to know the procedure to receive and transmit messages in Smbus on stm32f091rc?(using HAL libraries)

  • \$\begingroup\$ Welcome to electronics.stackexchange.com. Would you mind formatting your question such that the code is displayed in a better readable format? \$\endgroup\$ – Codo Apr 3 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.