So I am trying to understand bit banging and port operations. I'm developing a breakout board with an ADXL343 IMU read by an AtTiny44 via i2c. I adapted this code from MIT's How To Make Almost Anything which I also explained a bit here in this thread. Like I mentioned there, I got it working with the MIT code, and now have a basic sketch that works for my original board, where I define the pins like this.
#define SCL_pin (1 << PB0) #define SCL_pins PINB #define SCL_port PORTB #define SCL_direction DDRB #define SDA_pin (1 << PB1) #define SDA_pins PINB #define SDA_port PORTB #define SDA_direction DDRB
UNFORTUNATELY, I designed and fabricated a new board where the SCL and SDA pins are now PA3 and PA2 respectively. I tried to adjust the sketch by changing the defines to all be PORTA, DDRA, etc like this:
#define SCL_pin (1 << PA3) #define SCL_pins PINA #define SCL_port PORTA #define SCL_direction DDRA #define SDA_pin (1 << PA2) #define SDA_pins PINA #define SDA_port PORTA #define SDA_direction DDRA
Problem is, the tiny44 ceases to read from the IMU with the new pinout. The input/output functions in the program look like this:
#define output(directions,pin) (directions |= pin) // set port direction for output #define input(directions,pin) (directions &= (~pin)) // set port direction for input #define clear(port,pin) (port &= (~pin)) // clear port pin #define pin_test(pins,pin) (pins & pin) // test for port pin
The pi I am using is getting the initial values of data, so I know it is communicating fine with the tiny44
I realize the pin mapping changes depending on the core I'm using. I don't think that impacts the way the SDA_pin and SCL_pin are defined, because defining them PB0 and PB1 worked... Plus I tried about every pin name possible.
I have also tried the Damellis and Drazzy cores, and neither is working for me.
I tried using a few BitBang libraries like SoftWire, but with no luck.
I have tried a few boards as well, so I don't think it's hardware related.
I don't know what else to try. Any help would be much appreciated! Thanks!!