Help with TWI module on ATmega128

Weird issue, but I can't receive data using the TWI module in the ATmega128. (Writing data is documented very well in the datasheet, reading data is not). The code I'm trying to use is below. It hangs while waiting for the final STOP to be sent. So it has sent SLA+R and read a byte off the device. The byte read appears to be correct, too.

I know the addresses, speed etc. are OK because I can write to the device concerned with no difficulty (it is an MCP23008 8-bit I/O expander).

Before I start grabbing packets with the scope, can someone see the obvious idiot mistake in my code? The mega128 datasheet is confusing; for the situation where data byte has been Rxed and ACK sent, it does not show a bit combination for the "next step" being a STOP.

Thanks for any advice.

// Set address counter TWCR = (1

Reply to
larwe
Loading thread data ...

Never mind. TWINT is not set after sending a STOP. I'll extinguish my crack pipe now.

Reply to
larwe

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.