Go Down

Topic: I2C interface and TWI_FREQ (Read 2641 times) previous topic - next topic

spork

Hello,
I am interfacing a device that only functions at 32khz, so I have changed my twi.h file to have:

Code: [Select]

/*** twi.h ***/
 #ifndef TWI_FREQ
 #define TWI_FREQ 32000L  //changed from 100000L
 #endif


My sketch functions perfectly, but I would like to change the twi header back to it's original value (100000L). This is important so that I can distribute the code for use with unmodified headers. So I have tried writing:

Code: [Select]

/*** Spork's I2C sketch  ***/
 #define TWI_FREQ 32000L
 #include <Wire.h>


With the idea that the ifndef would let my value stay at 32000, but my communication fails when it is set this way, so I suspect that it's still running at 100000. Is there any way to fix this without editing the header file?

(Running arduino version 0017)


Spork

borref

Quote
Is there any way to fix this without editing the header file?


In your sketch, after the call to wire.begin, you can override speed as follows:

Code: [Select]

 TWBR = ((F_CPU / 32000l) - 16) / 2;


spork


Go Up