bitbank2 / BitBang_I2C

A software I2C implementation to run on any GPIO pins on any system
GNU General Public License v3.0
235 stars 31 forks source link

No activity on Attiny85 #6

Closed oomek closed 4 years ago

oomek commented 4 years ago

I've started experimenting with your library today, but so far I haven't managed to get any output, even as simple code as this does not show any activity on the logic analyzer.

#include <Arduino.h>
#include <BitBang_I2C.h>

BBI2C bbi2c;
uint8_t test[4] = {1,2,3,4};

void setup()
{
    memset(&bbi2c, 0, sizeof(bbi2c));
    bbi2c.bWire = 0;
    bbi2c.iSDA = PB0;
    bbi2c.iSCL = PB2;
    I2CInit(&bbi2c, 400000L);
    delay(100);
}

void loop()
{
    // This works
    // pinMode(PB0, OUTPUT);
    // pinMode(PB2, INPUT);
    // delay(100);
    // pinMode(PB0, INPUT);
    // pinMode(PB2, OUTPUT);

    // This does not
    I2CWrite(&bbi2c, 0x46, test, 4);
    delay(1000);
}

Am I doing something wrong?

bitbank2 commented 4 years ago

As it says in the readme, you need to specify the pin numbers differently for AVR to use the fast code. PB0 should be passed as 0xB0 PB2 should be passed as 0xB2

oomek commented 4 years ago

Sorry, I must have missed that. The waveform looks nice, although the PWM is very wide in low speeds. I've had to set I2CInit(&bbi2c, 1600000L); to get 400kHz on Attiny85 btw.

bitbank2 commented 4 years ago

I wasn't accurate with the timing because this library was really aimed at pushing the SSD1306 to go as fast as possible. Most I2C devices are pretty forgiving with the waveform shape and timing.