I tried I2C with the new AVR MCUs. For the master MCU it works fine.
But strangely the slave will pull down SDA and SCL after initialization (TWCR = (1<<TWEA)|(1<<TWEN)|(1<<TWIE)).
For the slave the pins should stay an input at high impedance.
It looks like TWSTA was set, but i haven't seen (and didn't toggle) the bit in TWCR.
![I2C Slave with new AVR MCUs pulls SDA / SCL to LOW I2c_si10](https://i.servimg.com/u/f57/20/25/17/30/i2c_si10.jpg)
But strangely the slave will pull down SDA and SCL after initialization (TWCR = (1<<TWEA)|(1<<TWEN)|(1<<TWIE)).
For the slave the pins should stay an input at high impedance.
It looks like TWSTA was set, but i haven't seen (and didn't toggle) the bit in TWCR.
![I2C Slave with new AVR MCUs pulls SDA / SCL to LOW I2c_si10](https://i.servimg.com/u/f57/20/25/17/30/i2c_si10.jpg)
- Code:
#define F_CPU 8000000UL
#define F_SCL 100000L //100 kHz
// Include of Header-files
#include <avr/interrupt.h>
// constants
#define SET_BIT(PORT, BIT) ((PORT) |= (1 << (BIT))) // set Port-Bit
#define TGL_BIT(PORT, BIT) ((PORT) ^= (1 << (BIT))) // toggle Port-Bit
int Address = 0b0001010;
int main(void)
{
SET_BIT(DDRD, PORTD1); // define debug pin
TWSR = 0x00; // clears status code register and all prescalers.
TWBR = ((F_CPU/F_SCL)-16)/2; // sets bit rate
TWAR = (Address<<1) + 0; // sets address
TWAMR = 0b11111110; // sets address mask
TWCR = (1<<TWEA)|(1<<TWEN)|(1<<TWIE); // enable acknowledge, enable TWI, enable interrupt
// with TWEN=1 SDA and SCL are pulled to low
while (1)
{
TGL_BIT(PORTD, PORTD1); // just for debugging
}
}