Software I2C - ATmega8 I am using ATmega8 with 12MHz crystal, on my breadboard. I can use SDA and SCL pins with default arduino library wire.h, and it works. But I want another pins to use I2C protocol.

I tried this library, even on real SDA and SCL pins, but it doesn't work.

I have pull up resistors, I tried with 10k and 4.7k without any success. (But those resistors worked with hardware I2C | TWI)

What am I doing wrong? (All connections is fine, because hardware TWI works but software does not.) Thank you for your help.

(Fuses are ok, because the Atmega won't respond if I remove the crystal oscillator, the LED blinking duration is ok.)

What i want to run (that doesn't work):

#define SDA_PORT PORTC
#define SDA_PIN 4
#define SCL_PORT PORTC
#define SCL_PIN 5

//#define I2C_TIMEOUT 100

#include &lt;SoftI2CMaster.h&gt;


uint8_t ADDR  = 0x68;

void setup(void) {

  Serial.begin(19200);
  Serial.println("Initializing ...");
  i2c_init();

  if (!i2c_start(ADDR | I2C_WRITE)) Serial.println(F("Device does not respond"));
  if (!i2c_write(0x00)) Serial.println(F("Cannot address reg 0"));
  i2c_stop();
}  

void loop (void) {
  unsigned int low0, high0, low1, high1;
  unsigned int chan0, chan1;
  unsigned int lux;
  int state1;
  int state2;

  delay(1000);
  i2c_start(ADDR | I2C_WRITE);
  i2c_write(0x00);
  i2c_rep_start(ADDR | I2C_READ);
  low0 = i2c_read(false);
  high0 = i2c_read(false);
  low1 = i2c_read(false);
  high1 = i2c_read(true);
  i2c_stop();
  Serial.print(low0);
}


And the code with hardware TWI that works:

#include "Wire.h"
#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(19200);
  pinMode(13, OUTPUT);
  pinMode(5, INPUT);
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() &amp; 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() &amp; 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}


Schematic is the same as: https://www.arduino.cc/en/main/standalone.

Except instead of 16MHz, I use a 12MHz and ch210x serial.

Arduino's bootloader works well, I compiled it from source.
OK let me cry till morning...

i was having this issue during day, but the solution was sooo easy

i need to pay attention more ...


  i2c_start(addr | R/W-bit)
  Initiates a transfer to the slave device with the (8-bit) I2C address addr. 


what i was trying is to push 7 bit address.

i hope this might help some others.

Thank you for help.