I2C speed not working...

I followed the instructions per my I2C DAC's datasheet to change it to fast mode, and upped the I2C frequency by adding this line to my code:

#define TWI_FREQ 1000000L

(1Mhz).

However, when timing data transfers with the micros() function, it still takes 8 microseconds, regardless of the frequency.

Thanks! baum

First, count the number of zeros. The value you specified does not match your comment.

Second, the micros() function increments in 4 microsecond increments. It makes a lousy timer for things that happen as rapidly as I2C.

I count 6 zeros (1,000,000), but thanks for the help with micros()! is there any other way of timing? Can I count the clk cycles a certain instruction takes?

baum

Can I count the clk cycles a certain instruction takes?

Nearly all AVR machine instructions take a single 62.5nsec clock cycle when running the chip at 16Mhz.

Lefty

Alright, but that doesn’t solve the problem… I can’t change the speed!

I thought the datasheet limits the I2C frequency to 400kHz?

I thought the datasheet limits the I2C frequency to 400kHz?

Yup.

My DAC supports "High-speed" mode, max. freq. 3.4Mhz. (http://www.sparkfun.com/datasheets/BreakoutBoards/MCP4725.pdf)

What datasheet are you talking about?

baum

The DAC may support higher speeds but the clock signal is generated from the master (Arduino) which only supports speeds up to 400kHz.

Oh... where does it say this?

page 215

OK. I'll keep it at 400khz, which will take 40us to transfer 2 bytes, max update frequency is 25khz... do you think this is fast enough for 22khz wav, or should I use a parallel DAC?

baum

I'll keep it at 400khz, which will take 40us to transfer 2 bytes, max update frequency is 25khz.

I make it more like 20kHz. Don't forget start and stop bits.

The DAC allows be to continuously clock out two bytes of data, no start and stop bits needed. Though I did forget about the Ack bit between each byte... I'll go with the parallel DAC, then.

Thanks for the help! baum