Interrupt Driven Communications

Although the in-line Seatalk communications routines worked well, it was decided to develop an interrupt-driven version so as to make their integration into complex programs simpler.  Although not needed for the initial scope of the project (a remote control) it looked like being an interesting thing to do.

The routines were designed around the same hardware, and to provide exactly the same functions, as the basic routines described on the previous page.  It was decided to retain the same strategy as those routines (ie. read single bytes, write entire datagrams).

If the main program is do any processing of received datagrams, it would be more convenient to have the receive routine assemble the datagram and flag the main program when this is complete.   Since the seatalk protocol incorporates the datagram length, this would be quite simple to do, but was not in fact done mainly to simplify the receive test routine that just echoes received bytes to the PC.
 

Software Design

The commented MPASM source code for this routine is given here.

The interrupt routine, which is driven by the Timer 2 interrupt (each 208us or 1 bit period at 4800 baud),  implements a state machine with 4 basic states, reflected by flags in INT_STATUS.  These states are:

Since all processing is done by the interrupt routines, it is transparent to the user program, which thus "sees" a very simple interface reflected by flag bits in TR_STATUS.

To read a byte:

To write a datagram:


The source listing also contains code to test the interrupt routine.  This just polls the RDR bit and echoes any received byte to the PC, and then polls the UART receive flag for a command byte which it incorporates into a "remote control" datagram and then sets the TXR flag.
 
 

Results and Comments

Testing followed the process described for the in-line routines with the same positive results.

Updates

17th March 2003 minor bugfixes: