Skip to content

Don't set TWSTO in tw_stop for slave transactions. This fixes non-working #27

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
17 changes: 16 additions & 1 deletion libraries/Wire/utility/twi.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,21 @@ void twi_stop(void)
twi_state = TWI_READY;
}

/*
* Function twi_stop_slv
* Desc relinquishes bus master status
* Input none
* Output none
*/
void twi_stop_slv(void)
{
// send stop condition
TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT);

// update twi state
twi_state = TWI_READY;
}

/*
* Function twi_releaseBus
* Desc releases bus control
Expand Down Expand Up @@ -414,7 +429,7 @@ SIGNAL(TWI_vect)
twi_rxBuffer[twi_rxBufferIndex] = '\0';
}
// sends ack and stops interface for clock stretching
twi_stop();
twi_stop_slv();
// callback to user defined callback
twi_onSlaveReceive(twi_rxBuffer, twi_rxBufferIndex);
// since we submit rx buffer to "wire" library, we can reset it
Expand Down
1 change: 1 addition & 0 deletions libraries/Wire/utility/twi.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
void twi_attachSlaveTxEvent( void (*)(void) );
void twi_reply(uint8_t);
void twi_stop(void);
void twi_stop_slv(void);
void twi_releaseBus(void);

#endif
Expand Down