@@ -56,6 +56,7 @@ static volatile bool twi_timed_out_flag = false; // a timeout has been seen
5656static volatile bool twi_do_reset_on_timeout = false; // reset the TWI registers on timeout
5757
5858static void (* twi_onSlaveTransmit )(void );
59+ static void (* twi_onSlaveTransmitMore )(void );
5960static void (* twi_onSlaveReceive )(uint8_t * , int );
6061
6162static uint8_t twi_masterBuffer [TWI_BUFFER_LENGTH ];
@@ -384,6 +385,17 @@ void twi_attachSlaveTxEvent( void (*function)(void) )
384385 twi_onSlaveTransmit = function ;
385386}
386387
388+ /*
389+ * Function twi_attachSlaveTxMoreEvent
390+ * Desc sets function called before a slave cont'd sequential data write operation
391+ * Input function: callback function to use
392+ * Output none
393+ */
394+ void twi_attachSlaveTxMoreEvent ( void (* function )(void ) )
395+ {
396+ twi_onSlaveTransmitMore = function ;
397+ }
398+
387399/*
388400 * Function twi_reply
389401 * Desc sends byte or readys receive line
@@ -640,6 +652,10 @@ ISR(TWI_vect)
640652 case TW_ST_DATA_ACK : // byte sent, ack returned
641653 // copy data to output register
642654 TWDR = twi_txBuffer [twi_txBufferIndex ++ ];
655+ // if the buffer emptied, request it to be topped up
656+ if (twi_txBufferIndex >= twi_txBufferLength ) {
657+ twi_onSlaveTransmitMore ();
658+ }
643659 // if there is more to send, ack, otherwise nack
644660 if (twi_txBufferIndex < twi_txBufferLength ){
645661 twi_reply (1 );
0 commit comments