@@ -56,6 +56,7 @@ static volatile bool twi_timed_out_flag = false; // a timeout has been seen
56
56
static volatile bool twi_do_reset_on_timeout = false; // reset the TWI registers on timeout
57
57
58
58
static void (* twi_onSlaveTransmit )(void );
59
+ static void (* twi_onSlaveTransmitMore )(void );
59
60
static void (* twi_onSlaveReceive )(uint8_t * , int );
60
61
61
62
static uint8_t twi_masterBuffer [TWI_BUFFER_LENGTH ];
@@ -384,6 +385,17 @@ void twi_attachSlaveTxEvent( void (*function)(void) )
384
385
twi_onSlaveTransmit = function ;
385
386
}
386
387
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
+
387
399
/*
388
400
* Function twi_reply
389
401
* Desc sends byte or readys receive line
@@ -640,6 +652,10 @@ ISR(TWI_vect)
640
652
case TW_ST_DATA_ACK : // byte sent, ack returned
641
653
// copy data to output register
642
654
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
+ }
643
659
// if there is more to send, ack, otherwise nack
644
660
if (twi_txBufferIndex < twi_txBufferLength ){
645
661
twi_reply (1 );
0 commit comments