Skip to content

Make Wire library error safe #2489

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 10 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update twi.c
  • Loading branch information
MauroMombelli committed Dec 2, 2014
commit 7c87e9b933cd80927e684920a7e8801a7ae89e3f
14 changes: 7 additions & 7 deletions libraries/Wire/utility/twi.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ uint8_t twi_readFrom_timeout(uint8_t address, uint8_t* data, uint8_t length, uin
// wait until twi is ready, become master receiver, or timeout
uint32_t start_us = micros();
while(TWI_READY != twi_state){
if (timeout){
if (timeout_us){
if (micros() - start_us > timeout_us){
twi_state = TWI_ERROR;
return 0;
Expand Down Expand Up @@ -169,9 +169,9 @@ uint8_t twi_readFrom_timeout(uint8_t address, uint8_t* data, uint8_t length, uin
TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTA);

// wait for read operation to complete, or timeout
uint32_t start_us = micros();
start_us = micros();
while(TWI_MRX != twi_state){
if (timeout){
if (timeout_us){
if (micros() - start_us > timeout_us){
twi_state = TWI_ERROR;
return 0;
Expand Down Expand Up @@ -222,7 +222,7 @@ uint8_t twi_writeTo_timeout(uint8_t address, uint8_t* data, uint8_t length, uint
// wait until twi is ready, become master transmitter, or timeout
uint32_t start_us = micros();
while(TWI_READY != twi_state){
if (timeout){
if (timeout_us){
if (micros() - start_us > timeout_us){
twi_state = TWI_ERROR;
return 5;
Expand Down Expand Up @@ -268,9 +268,9 @@ uint8_t twi_writeTo_timeout(uint8_t address, uint8_t* data, uint8_t length, uint
TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE) | _BV(TWSTA); // enable INTs

// wait for write operation to complete, or timeout
uint32_t start_us = micros();
start_us = micros();
while( wait && (TWI_MTX != twi_state) ){
if (timeout){
if (timeout_us){
if (micros() - start_us > timeout_us){
twi_state = TWI_ERROR;
return 5;
Expand Down Expand Up @@ -377,7 +377,7 @@ void twi_stop_timeout(uint32_t timeout_us)
// wait for stop condition to be exectued on bus, or timeout
// TWINT is not set after a stop condition!
while( TWCR & _BV(TWSTO) ){
if (timeout){
if (timeout_us){
if (micros() - start_us > timeout_us){
twi_state = TWI_ERROR;
return;
Expand Down