Hello
Hope you are well.
The status of the function is read through a variable type status_t. Adding a small delay when the function is called could solve the problem.
Besides moving the methods of the function to a while are doing another change to the function. A more detailed description of the function might help.
Let me know if this solves the problem, if you have more questions do not hesitate to ask me.
Best regards,
Omar