I working on a project that uses a DAC and I need to change the address for the I2C to the chip, the datasheet is very simple, you write to the original address, send a command, set one pin on the chip low, write a new address, confirm the address and put the pin high. I normally work on Atmel Studio, but for this very simple process I decided to use Arduino, so I made the following program:
#include <Wire.h>
void setup() {
// put your setup code here, to run once:
Wire.begin();
Serial.begin(9600);
pinMode(12,OUTPUT);
digitalWrite(12,HIGH);
Serial.println("Setting up Address");
Wire.beginTransmission(0x60);
Wire.write(0x61);
digitalWrite(12,LOW);
Wire.write(0x66);
Wire.write(0x67);
Wire.endTransmission();
digitalWrite(12,HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
}
It cannot be simpler, but didn't work, the chip still have the old address. I stared at the program for quite a while could not see any problem. I pulled my digital analyzer and saw what is in picture i2c-1. The pin is pulled down before the start of the I2C communication and the chip doesn't AKC the request. This is weird as I clearly have the pulled down after the command 0x61.
I did the following test, I comment out the digital low for the pin and I got was is in picture i2c-2. Now the chip ACK the command to change address, but NAK the change request because the pin is not low.
It appears to me that the pre-compiler is arranging some commands, is this possible? or am I missing something on my code? Ideas?