Arduino Nano (clone) Wire library problem - only start condition set

I'm actually trying to send some data between two Arduino Nanos using I2C.

My bus master sets up the start condition on the bus, but doesn't transmit the slave adress nor any data.

I'm currently not using the Arduino IDE, but Sloeber for Eclipse. All projects to date worked fine.

Master code snippet

uint16_t asd = 0;
uint8_t array1[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint32_t CW1 = 6207;
uint8_t Wave1 = 7;
uint8_t subVolume1 = 127;
uint8_t Pulsewidth1 = 127;
uint8_t cutoff1 = 47;
uint8_t feedback1 = 0;
uint8_t volume1 = 255;

void setup()
{
	DDRB |= (1 << PB0);
	TCCR2A = (1 << WGM21);
	TCCR2B = (1 << CS22) | (1 << CS21) | (1 << CS20);
	OCR2A = 60;
	//enable timer 1 overflow interrupt
	Wire.begin(20);
	TWBR = 12;
	TIMSK2 = (1 << OCF2A);
}

ISR (TIMER2_COMPA_vect) {
	PORTB |= 0x01;

	array1[0] = CW1;
	array1[1] = (CW1 >> 8);
	array1[2] = (CW1 >> 16);
	array1[3] = (CW1 >> 24);
	array1[4] = Wave1;
	array1[5] = subVolume1;
	array1[6] = Pulsewidth1;
	array1[7] = cutoff1;
	array1[8] = feedback1;
	array1[9] = volume1;

	Wire.beginTransmission(10);
	for (int i = 0; i < 10; i++){
		Wire.write(array1[i]);
	}
	uint8_t err = Wire.endTransmission(true);

	asd +=1;
	asd &= 4095;

	volume1 = asd >> 4;

	PORTB &= 0xFE;
}

Port B is used as debug (CPU load), pin A4 is connected to A4, A5 to A5, both have 2k7 pullups.
When the ISR starts PB0 goes high, I2C bus outputs start condition and hangs.

What am I doing wrong?

OK, I found what was wrong after reading through the library code.

I was running my code from inside ISR - this disabled interrupts, while the library needs interrupts to work.

I modified the code so that timer interrupts are disabled, but the main loop waits for timer overflow flag, then after executing clears the flag.

void setup()
{
	DDRB |= (1 << PB0);
	TCCR2A = (1 << WGM21);
	TCCR2B = (1 << CS22) | (1 << CS21) | (1 << CS20);
	OCR2A = 60;
	//enable timer 1 overflow interrupt
	Wire.begin(20);
	TWBR = 12;
}

void loop()
{
	while(!(TIFR2 & 2));

	PORTB |= 0x01;

	sei();
	array1[0] = CW1;
	array1[1] = (CW1 >> 8);
	array1[2] = (CW1 >> 16);
	array1[3] = (CW1 >> 24);
	array1[4] = Wave1;
	array1[5] = subVolume1;
	array1[6] = Pulsewidth1;
	array1[7] = cutoff1;
	array1[8] = feedback1;
	array1[9] = volume1;

	Wire.beginTransmission(10);
	for (int i = 0; i < 10; i++){
		Wire.write(array1[i]);
	}
	uint8_t err = Wire.endTransmission(true);

	asd +=1;
	asd &= 4095;

	volume1 = asd >> 4;

	PORTB &= 0xFE;

	TIFR2 = 2;
}

I hope that this helps others that might have the same problem :slight_smile: