Danjel McGougan wrote: > The normal way to do interrupt driven RS232 reception is to have a > periodical interrupt running at 2 or 3 times the baud rate. > The interrupt samples the RX line and as soon as the start bit is > detected the interrupt changes the period to 1.25 or 4/3 respectively, > of the baud period. Not quite right! For 3X sampling, it stays at three times, for 2X it changes to four times the bit-rate until it has verified the *start* bit, then swaps to the actual bit-rate for the data bits *and stop*. This sets the sample time within the middle third (or half) of each data bit, and suppresses false starts. Note that when a false start is found, or a stop is received, it is ready to sample again 1/3 or ¸ bit time later, so a false start will not cause a true start to be missed, and a too-high bit-rate causing short stop bits can be tolerated. If you were really picky, you could use an interrupt-on-change to detect the start bit, and use timer interrupts thereafter. This is obviously what James originally intended, but there is absolutely no requirement for nested interrupts here. The timer is pre-loaded and its IRQ is cleared so that it *cannot* interrupt again for a pre-set interval, much more than enough to ensure that the current interrupt service completes. Next, the timer IRQ is enabled; superfluous if the current interrupt is a time-out of course, and then the IRQ routine exits. When however the stop bit has been checked, the timer IRQ can be disabled in favour of the interrupt-on-change. If the latter trips immediately (during the current interrupt service), then its interrupt will follow the interrupt return. Due care has to be taken as has been discussed before, with interrupt-on-change functions, so perhaps I should have spoken about the RB0/INT pin instead. The reason for using an interrupt to detect the initial start bit is simply efficiency; no data = no interrupts at all. OTOH, a continuous 3X bitrate interrupt polling the port for start bits is simpler to code, and suits continuous *or multiple* data streams. If the latter, there is in fact no alteration of the timer increment for which a suitable crystal is usually chosen. Data (and stop) bits are read each three interrupts using a counter, but alternate data streams may be sampled on different interrupts. Note previous references in the PICLIST to "vertical counters" for this purpose; four or eight ports may be serviced very efficiently. Well *that's* my say! Cheers, Paul B.