I am using Atmega8 with 12MHz crystal, on my breadbord. I can use SDASDA and SCLSCL pins with default arduino library wire.hwire.h, and it works. But I want another pins to use I2C protocol.
I tried library, even on real SDASDA and SCLSCL pins, but it doesn't work.
I have pull up resistors, I tried with 10k and 4.7k without any success. ( ButBut those resistors worked with hardware I2C |TWI| TWI)
What am I doing wrong? ( AllAll connections is fine, because hardware TWI works but software not. ) Thank you for your help.
( FusesFuses are ok, because Atmega won't response if I remove the crystal oscillator, LED blinking duration is ok.)
What i want to run (that doesn't work):
what i want to run : ( that doesnt work )
#define SDA_PORT PORTC
#define SDA_PIN 4
#define SCL_PORT PORTC
#define SCL_PIN 5
//#define I2C_TIMEOUT 100
#include <SoftI2CMaster.h>
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);
}
WhatAnd the code with hardware twiTWI that works :
Schematic is the same as : https://www.arduino.cc/en/main/standalone.
except 16mhzExcept instead of 16MHz, iI use 12mhz12MHz and ch210x serial.
arduino'sArduino's bootloader works well, iI compiled it from source.