Hi, I’m new to Arduino and working on a project that will bring in serial data from a sensor at 57600(I have no control over the rate setting), add in additional I2C sensor data, and re-output the combined data out another serial interface. I’ve been testing with a Nano and a Leonardo. The incoming sensor serial data comes in rapid bursts. In terms of total bps it is about 32768bps. I first tried the SoftSerial library to take in data since it has an inverse logic option which is great since I’ll eventually be inserting components that will inverse the logic coming in for the serial sensor data, and rather than have to add even more hardware, it would be great to just invert the logic in software.
So, anyhow, I was able to read the serial sensor data using the SoftwareSerial library, validate it, and re-output out the hardware serial interface without any problems. When I added in the code to read the I2C sensor, every time I read the data, I would lose data (I’m assuming it was on the RX since it wouldn’t make sense losing it on TX out the hardware serial). After doing some reading, I realized that combining SoftwareSerial with I2C is just not an option here because the I2C bus requires interrupts that get in the way.
My understanding of timing, interrupts, and UARTs is completely lacking, and I can’t find a good doc that answers all my questions regarding them – it seems that no one really has a good grasp that’s posted previously. So this is where I’m asking for some help. I’m also wondering what would be the difference behind the scenes if I switch to using the hardware serial port for data input (though I would lost the inverted logic option, and it’s going to make debugging harder). I’m not clear on the steps either way – if I RX using SoftwareSerial, and TX via hardware serial, or vice versa. If RX’ing with SoftwareSerial, what exactly happens during the process of reading on the I2C bus that can cause issues? If RX’ing with hardware serial, does the packet come in, cause an interrupt, get dropped into the pre-defined 64 byte buffer, then just waits until a codepoint gets reached for processing? What would happen if I’m in an I2C bus read at the time? How are interrupts prioritized in this case? What happens if we receive in interrupt while executing an interrupt handler?