I am making a large number of i2c calls. Sometimes this works okay, but often the bus will hang and the program gets stuck.
There should not be any gaps in the data below. My theory is that some interrupt is occuring, and if the interrupt occurs at some unfortunate moment, the i2c traffic gets messed up:

So I wanted to try protecting the i2c call by disabling unrelated interrupts, then reenabling them.
ENABLE_INTERRUPTS() and DISABLE_INTERRUPTS() set primask, which would not be good because the i2c still needs to function.
Then I thought I could use BASEPRI, but I am not sure how to set this through the SDK (or otherwise).
Related question - I was experimenting with blocking and non-blocking variants of the receive code.

I have blockng and non-blocking versions of both the send and the receive. If I understand correctly, the non-blocking still blocks the program in a sense, but gives you the option to do something inside the {} brackets while you're waiting.
I wonder if there is a safer way to handle this code. If anything happens to the bus, you will get stuck in the while busy loop forever. But if you use the blocking calls, and change the max wait time to something finite, you should return something to the calling function so they know to retry. is there a try/catch way to handle these i2c calls?