-
Notifications
You must be signed in to change notification settings - Fork 121
Request Callback is not triggered #43
Description
Using the libary following the examples, I saw that request callback is not triggered, so the slave never sends data to the master.
usiTwiSlave.c
`case USI_SLAVE_CHECK_REPLY_FROM_SEND_DATA:
// Execute request callback for each byte requested, as this is the intended
// behavior of this library
USI_REQUEST_CALLBACK();
if ( USIDR )
{
// if NACK, the master does not want more data
SET_USI_TO_TWI_START_CONDITION_MODE( );
finished = 1;
break;
}
// from here we just drop straight into USI_SLAVE_SEND_DATA if the
// master sent an ACK
// copy data from buffer to USIDR and set USI to shift byte
// next USI_SLAVE_REQUEST_REPLY_FROM_SEND_DATA
case USI_SLAVE_SEND_DATA:
// Get data from Buffer
if ( txCount )
{
USIDR = txBuf[ txTail ];
txTail = ( txTail + 1 ) & TWI_TX_BUFFER_MASK;
txCount--;
overflowState = USI_SLAVE_REQUEST_REPLY_FROM_SEND_DATA;
SET_USI_TO_SEND_DATA( );
}
else
{
// the buffer is empty
SET_USI_TO_READ_ACK( ); // This might be neccessary sometimes see http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=805227#805227
SET_USI_TO_TWI_START_CONDITION_MODE( );
} // end if
break;
`
When I look at the code USI_REQUEST_CALLBACK is called when the overflow state is: USI_SLAVE_CHECK_REPLY_FROM_SEND_DATA, but this state will never come, because in overflow state: USI_SLAVE_SEND_DATA txCount is zero, because no data is add to the transmit buffer.. so the overlowState variable will not change to the correct state..