1
\$\begingroup\$

I'm using PMM240 power management board to control battery RRC-2054, and I have problem to use SMBus, please see the code I listed below, looks device is ready, but when you send something, it is always in busy(Master Data Transmission process is ongoing). Will this a matter of address problem, or a command problem, or others? anyway to get more info for this busy status?

if (HAL_SMBUS_IsDeviceReady(&hsmbus2, (uint16_t) PMM240_ADDRESS, 2, 2)
            != HAL_OK) {
        Error_Handler();//passed
    }
uint32_t test = HAL_SMBUS_GetState(&hsmbus2);
        if (test != HAL_SMBUS_STATE_READY) {
            Error_Handler();//passed. 
        }
        ret = HAL_SMBUS_Master_Transmit_IT(&hsmbus2,
                (uint16_t) PMM240_ADDRESS, &buffertx[0], 1,
                SMBUS_OTHER_FRAME_NO_PEC);

        if (ret != HAL_OK) {
            Error_Handler();//passed
        }
        // after enough time delay, 100 or 1000 ms
          HAL_Delay(100);//not useful for the following code.
       // inserting HAL_SMBUS_Init(&hsmbus2) could reset the busy status, but info lost, right?
        test = HAL_SMBUS_GetState(&hsmbus2);
        if (test != HAL_SMBUS_STATE_READY) {
            Error_Handler();//not passed
        }
\$\endgroup\$
2
  • \$\begingroup\$ Where are you waiting/testing for the SMBus operation to complete? Of course it is busy right after you start it. Or is that not the complete code? Which STM32 this is? \$\endgroup\$
    – Justme
    Commented Jun 25, 2019 at 19:56
  • \$\begingroup\$ "// after enough time delay in debug mode" so I just run step by step and there are a few seconds delay between each command, I am runing stm32cubeMX on L476RG \$\endgroup\$
    – adam
    Commented Jun 25, 2019 at 21:46

1 Answer 1

1
\$\begingroup\$

I am sure that the function HAL_SMBUS_IsDeviceReady() is not working correctly. I used a different solution to search for devices on the bus. Maybe this will be useful.

// produce Start 
HAL_result = HAL_SMBUS_Master_Transmit_IT(hsmbus, CheckingAddress, &value, 0, SMBUS_FIRST_FRAME);
//HAL_result = HAL_SMBUS_IsDeviceReady(hsmbus, CheckingAddress, 3, 100);
//while(HAL_SMBUS_GetState(hsmbus) != HAL_SMBUS_STATE_READY); // work without this line
if ( HAL_result == HAL_OK)
{
    //device is ready to connect
    .................. 
}
// finish transaction (may be not needed)
HAL_result = HAL_SMBUS_Master_Transmit_IT(hsmbus, CheckingAddress, &value, 0, SMBUS_LAST_FRAME_NO_PEC); 
\$\endgroup\$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.