Jump to content
  • 0

Chipkit uC32 change I2C speed


Roberto!

Question

Hello. I'm trying to change the speed of the I2C bus from the default (I think 100kHz) to 1.7MHz. In which file do I change the speed?

I found the following in DTWI.cpp (lines 136 - 141):

    // put a default of 100KHz
    // use F_CPU because __PIC32_pbClk is not set up yet
    // as constructor run before MPIDE Init; however, this would be the correct
    // value at this point as noone has the chance to change the clock freq
    // later we can use __PIC32_pbClk; which is used in masterStart
    ptwi->ixBrg.reg = (F_CPU/FQ100KHz/2) - (((F_CPU / 10000000) * 26) / 25) - 2;

 

Changing the 10000000 to a 40000000 (for 400kHz speed) did not seem to change the I2C bus speed. Is there another place the change needs to be made? Thanks. 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

Hi, I have the same issue.

I looked in the linked forum. I did learn that " The register I2CxBRG controls the I2C speed", but I have no enough knowledge to know what to do with that...

What line of code should I actually writte after "Wire.begin();" in order to change the I2C speed?

 

NB:

In "normal" arduino platforms, the I2C speed change is quite straightforward: https://www.arduino.cc/en/Reference/WireSetClock

In the uC32, the method SetClock seem to not have been implemented: https://github.com/chipKIT32/chipKIT-core/issues/225

I get 'class TwoWire' has no member named 'setClock' as an error message when trying to call " Wire.setClock(400000);"

 

Would a good heart please help?..

Thanks a lot :)

 

 

Link to comment
Share on other sites

Hi @Mejdi,

More information about your setup would be helpful. Are you using the Ardunio IDE? If you are using Ardunio IDE what version and are you using the ChipKit or Digilent cores? Are you using MPIDE? If you are using MPIDE Here is a chipkit forum thread that talks about changing the frequency for I2C in MPIDE.

cheers,

Jon

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...