TRISB1 needs to be set to 1 to configure RB1 (RX) as an input. I'm not sure what the default is, so it may be ok.
You need to clear the receive interrupt flag (RCIF) by reading the receive register (RCREG). In addition, since the receive register is doubled-buffered, you may need to read it more than once.
So your interrupt routine needs to look more like this:
extern interrupt isr(void)
{
while (RCIF)
{
char ch;
RB5 = 1;
ch = RCREG; // normally would go into an array and increment a counter
}
}
I don't know if that is your only problem, since you indicate you are not getting into the interrupt routine at all. But the above is the correct way to read the characters out of the receive buffer.
======================================
EDIT:
Don't know if this will help or not, but in this post, before enabling interrupts, the code clears out the FIFO first. (Their code also clears out the RCIF flag, but since it is readonly on your chip, that isn't needed.)
ch = RCREG; // clear FIFO
ch = RCREG;
ch = RCREG;
// then enable interruupts ...
There are several potential sources for noise in any circuit. Some of the most common include:
- Poorly regulated power supplies;
- Switching power supplies;
- Insufficient capacitive decoupling of the power rails near the MCU;
- Inductive coupling of nearby electromagnetic sources (including 50 or 60Hz from the mains power; even if the circuit is battery powered, it will experience this interference when close enough to a mains source);
- RF sources near the resonant frequency of a trace on the circuit board, or one of its harmonics;
- Routing of high-current traces on the circuit board near signal lines;
- Etc.
In addition (as @jippie mentioned), clock skew is a very common cause of errors in any type of serial communication that uses a predetermined data rate. If you're using an external crystal and interfacing to another system that can reasonably be expected to be accurate, it's less likely to cause problems. Internal oscillators, however, can have tolerances that are several orders of magnitude worse than crystals, and tend to vary more over temperature ranges.
There are several basic tests that can be performed on a running system to determine the basic noise (and skew) immunity of your interface, including:
- Freezing (cool the circuit to the minimum rating of its components);
- Baking (heat to the maximum rating);
- Exposure to EMI:
- Set the board on top of the power cord of a running space heater;
- Key a CB radio in the near vicinity of the board;
- Put the board next to your wireless router;
- Use long hookup wire (instead of a properly constructed serial cable) for the UART connection.
There are many others--in fact, there are large testing labs dedicated to EMC qualification.
In general, unless some minimal level of data loss is acceptable, it is always prudent to include some sort of error checking in your communications code. Even a simple checksum is better than nothing.
Best Answer
The main goal of the TX interrupt (really an END OF TX) is to send the content of a buffer (multiple bytes) automatically. When implemented in a proper way:
The exact behavior depends on the microcontroller. That is a general description.