I have a project where I'm using I2C inside a timer interrupt to control external hardware, basically using the microcontroller (ATMEGA328pb @ 12MHz) as a feedback PID controller. This timing interrupt fires every 10ms or so, and consumes about 5ms. Most of that time is spent dealing with I2C (400kHz, but many bits, waits, etc.)
All that works fine on its own.
The problem is adding high-speed UART communication; I'd like to use 57600bps, and I'm finding that writing too much, too fast to the UART from an external source causes my microprocessor to lock - and the watchdog isn't even helping (not sure why). I'm not running out of receive buffer, I think it's that the I2C interrupt is taking too much time. Typing-speed works fine, but sending scripts and such at full speed locks up the device.
I'm using Fleury's bit-banged I2C library.
What's the "right" way to do this: I'd like full-duplex UART and I2C running concurrently, and to preserve my timer ISR that contains all this i2c control stuff.
(I can't pull the I2C code out of the ISR, as it's critical. Is there a reliable I2C library that works inside interrupts, and plays nice with the UART?)