You need to log in to create posts and topics.

atmega328 i2c slave

Hi,
i try to use i2c slave mode using arduino lib Wire.h, but that don't work as expected.
Very simple programm :
 
#include <Wire.h>
const int8_t i2cAddress = 8;

void receiveEvent(int nbBytes)
{ 
	PORTD=Wire.read();
}

int main()
{
	DDRD=0xFF;
	Wire.begin(i2cAddress);
	Wire.onReceive(receiveEvent);
	sei();
	while(1)
	{
		_delay_us(100);
		//PORTD=TWDR;
	}
}

 

 
TWDR register contains right datas but callback function is not executed.
it seams TWSR register does not worked as expected. Il should take TW_SR_STOP  0xA0 value but only got TW_SR_DATA_ACK   0x80 and TW_SR_SLA_ACK   0x60
 
 

Hi.
Thanks for reporting and for the solution.

Indeed a Stop condition does not set the correct status value.
Solved at Rev 2255.

bjacquot has reacted to this post.
bjacquot

too late, I had just figured out how to solve this problem 🙂

thx.

 
arcachofo has reacted to this post.
arcachofo

it don't work as expected.
You should send TWI_SRX_STOP_RESTART only when the i2c message is for you :

if (m_addrMatch) setTwiState( TWI_SRX_STOP_RESTART );

Thanks, solution applied at Rev 2274.