Download avr-libc Reference Manual
Transcript
7.12 Example using the two-wire interface (TWI)
case TW_MT_DATA_ACK:
rv++;
break;
default:
goto error;
}
}
quit:
TWCR = _BV(TWINT) | _BV(TWSTO) | _BV(TWEN); /* send stop condition */
return rv;
error:
rv = -1;
goto quit;
}
/*
* Wrapper around ee24xx_write_page() that repeats calling this
* function until either an error has been returned, or all bytes
* have been written.
*/
int
ee24xx_write_bytes(uint16_t eeaddr, int len, uint8_t *buf)
{
int rv, total;
total = 0;
do
{
#if DEBUG
printf("Calling ee24xx_write_page(%d, %d, %p)",
eeaddr, len, buf);
#endif
rv = ee24xx_write_page(eeaddr, len, buf);
#if DEBUG
printf(" => %d\n", rv);
#endif
if (rv == -1)
return -1;
eeaddr += rv;
len -= rv;
buf += rv;
total += rv;
}
while (len > 0);
return total;
}
void
error(void)
{
Generated on Mon Mar 8 22:25:10 2004 for avr-libc by Doxygen
164