Increase frequency clock i2c

Hi guys! I'm using an arduino m0 pro and I want to increase the frequency clock up to 800kHz. I looked around the internet and I found that I need to modify the file twi.h and delete the twi.o file in order to make the library to be recomplied. I can't find the .o file, do you know where can I find it?

Do you know another way to increase the frequency clock for the i2c communication?

Be very carefull as not many devices support 800KHz.

Do you have a specific sensor in mind.

No experience with the m0 pro, but can it be that the .o file is compiled again for every new project?
and stored in the temp folder of a sketch?

What I want to achieve is the generation of a sinewave having a frequency of 25kHz. I need to improve the i2c speed in order to output the values contained in the lookup table because I'm using a DAC to output the signal. How can I increase the speed? And how much can I increase it?

Do you have a datasheet of the DAC?

The M0 Pro has an analog output. Use that or a DAC with SPI interface.

You could start with this example for the Due and adapt it for the Zero (only 10-bit DAC): https://www.arduino.cc/en/Tutorial/DueSimpleWaveformGenerator

I doubt that you could adapt the DAC output frequency from DueSimpleWaveformGenerator since you can't modify the frequency of analogWrite() :slight_smile: .

However, with a direct register programming (a 12-bit DAC) on an arduino DUE, it's easy to specify DAC conversion rate. E.g if your sinewave is sampled 64 times per period and you want to output this sinewave at 25 KHz, you will have to program 1.6 MHz as the conversion frequency.

I already use the DAC pin of the arduino m0, I need another analog output that’s why I’m using the DAC.

ard_newbie:
I doubt that you could adapt the DAC output frequency from DueSimpleWaveformGenerator since you can’t modify the frequency of analogWrite() :slight_smile: .

However, with a direct register programming (a 12-bit DAC) on an arduino DUE, it’s easy to specify DAC conversion rate. E.g if your sinewave is sampled 64 times per period and you want to output this sinewave at 25 KHz, you will have to program 1.6 MHz as the conversion frequency.

I am already able to generate a sinewave through the timer interrupts, I’ll show you the piece of code in the loop to make you understand:

  if(flag){
    dac.setVoltage(pgm_read_word(&(sintable[i])), false);
    flag = 0;
  }

The flag variable is set in the interrupt routine that is executed with a frequency of 25kHz. The i2c clock is not fast enough to handle that frequency so I need to increase the frequency rate for the communication. The adafruit customer service told me:

25KHz is going to be impossible with a 100KHz i2c clock. 40 microseconds on the wire doesn’t even allow you to transmit the entire i2c address. You could try increasing the i2c clock to 400KHz. You might even get it to run at 800KHz.

I don’t get how to increase the i2c clock frequency.

robtillaart:
Do you have a datasheet of the DAC?

Yes, this is the link to the datasheet: https://cdn-shop.adafruit.com/datasheets/mcp4725.pdf

The flag variable is set in the interrupt routine that is executed with a frequency of 25kHz

Consequence : Your sine waveform has a frequency of 25 KHz/ Size of sintable ....far from 25 KHz !

I'm sorry, my mistake. The sinewave has a frequency of 100Hz but with a frequency of 25kHz a value of the lookup table has to be outputted.

void TCC0_Handler()                              // Interrupt Service Routine (ISR) for timer TCC0
{     
  // Check for overflow (OVF) interrupt
  if (TCC0->INTFLAG.bit.OVF && TCC0->INTENSET.bit.OVF)             
  { 
    flag = 1;
    i++;
    if(i==256)
      i=0;   
    REG_TCC0_INTFLAG = TC_INTFLAG_OVF;         // Clear the OVF interrupt flag
  }
}

This is the interrupt handler.

Make yourself a favor, buy a Due ( 2 builtin 12-bit DACs)~ 15 $ and your project is done.

Note that DACs output is not full swing but between 1/6 * 3.3V and 5/6 * 3.3V, however you can easily expand their range between 0V and 3.3V.