Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle repeated START condition correctly #18

Merged
merged 1 commit into from
May 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions firmware/twi-slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ static void TWI_Start_Transceiver( unsigned char ack ) {
}

/**
* Call this function to send (and wait for) a bus stop condition.
* Call this function to clear a bus error condition. Do NOT wait.
* ---------------------------------------------------------------------------------------------- */
static void TWI_Stop( void ) {
TWCR = _BV(TWEN)| // Enable TWI-interface and release TWI pins
_BV(TWIE)|_BV(TWINT)| // Enable TWI Interupt
_BV(TWEA)|_BV(TWSTO); // Send ACK after next reception, stop bus

while(TWCR&_BV(TWSTO));
}

/**
Expand Down Expand Up @@ -127,10 +125,11 @@ ISR(TWI_vect) {
break;

case TW_SR_STOP: // A STOP condition or repeated START condition has been received while still addressed as Slave
TWI_Stop();
// Either way, treat it as end of transmission
if (TWI_Rx_Data_Callback) {
TWI_Rx_Data_Callback(TWI_buf, TWI_bufPtr);
}
// Release the bus and re-enable reception in un-addressed mode
TWI_Start_Transceiver(1);
break;

Expand Down