2
\$\begingroup\$

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)

\$\endgroup\$
2
  • \$\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
    Commented Apr 3, 2021 at 8:30
  • \$\begingroup\$ Check out my question. Maybe you can implement it for STM32F0. STM32G0 Stuck on SMBUS Slave \$\endgroup\$
    – devscg
    Commented Sep 15, 2022 at 21:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.