I2C problems on arduino mega

The I2C library can hang, because of its design, if an interrupt doesn't occur when it should. First I would install pull-up resistors (Eg. 4.7K for both SDA and SCL from each of them to 5V).

If that doesn't help try an alternative library which I believe is more resistant to hanging: