class TWBRemulation in WireKinetis.h when is it called?

Status
Not open for further replies.

DaQue

Well-known member
I'm trying to modify a copy of the Wire library I copied into my Sketches folder but I'm confused on how / when class TWBRemulation is used. I wan't to add a 20 Khz (or close) I2C clock speed for a project I have that I have to deal with an I2C bus with 10 nF caps on the clock and data lines. That's way over what appears to be the maximum (400 pf) I found listed in a few places thus the need for a slow clock. The modules I am talking to are 20 years old and the caps are under a metal shield and can't be changed for a number of reasons.

I'm confused on when class TWBRemulation is called. inline operator int () const __attribute__((always_inline) appears to "return" 12 the cpu clock is a standard speed 4 mhz or higher else it "returns" 72.

TWBRemulation appears to use inline operator int () const __attribute__((always_inline) and sets the clock to 100 khz (about) if its 72 else its 400 khz (about).

I cant find where inline operator TWBRemulation is actually called so I'm not sure if I need to modify it or not. To get the speed I want I need to set I2C0_F to 0x3A (for 72 Mhz CPU clock) in TwoWire::setClock(uint32_t frequency).

Can I get away with just modifying WireKinetis.cpp TwoWire::setClock(uint32_t frequency) to add a 20khz option for 72 Mhz?
 
how / when class TWBRemulation is used.

It's only used when AVR-specific code reads or writes the TWBR register to change the clock speed. Those strange constants are the specific numbers needed for AVR with 16 MHz clock.

Modern versions of the Wire library have setClock(), so this is rarely needed now. Still, it's there for compatibility with very old Arduino code.
 
PS My plan on dealing with the slow module is to init the Audio Adaptor at normal speed before I attach the module with its 10 nf caps using an adaptor board I am making then change the I2C to slow speed to talk to the module. As I understand it the I2C only needs to be at normal speed when the Audio adaptor starts up. Once the program runs the module is removed and returned to the end product.
 
It's only used when AVR-specific code reads or writes the TWBR register to change the clock speed. Those strange constants are the specific numbers needed for AVR with 16 MHz clock.

Modern versions of the Wire library have setClock(), so this is rarely needed now. Still, it's there for compatibility with very old Arduino code.

Thanks! I can't believe how you can remember all of these details. #impressed
 
Status
Not open for further replies.
Back
Top