aboutsummaryrefslogtreecommitdiff
path: root/libraries/Wire
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2014-07-02 15:37:30 +0200
committerCristian Maglie <c.maglie@bug.st>2014-07-02 15:37:30 +0200
commitcb4ae51b425568c7d404798ec4010660c46a5638 (patch)
tree52db08fc0ff40d0d9eb90f1d0c5d957cfbc9ec65 /libraries/Wire
parente7c3527a99e44416e97fe22534875df1ca5df9c0 (diff)
parent5216e551a5b90f8744a4a7e18e531da16d1261ad (diff)
Merge pull request #1912 from Lauszus/issues440
Enable user to change the I2C clock frequency by calling setClock in the Wire library
Diffstat (limited to 'libraries/Wire')
-rw-r--r--libraries/Wire/Wire.cpp5
-rw-r--r--libraries/Wire/Wire.h5
-rw-r--r--libraries/Wire/keywords.txt1
3 files changed, 9 insertions, 2 deletions
diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp
index 4e7a17c..553add7 100644
--- a/libraries/Wire/Wire.cpp
+++ b/libraries/Wire/Wire.cpp
@@ -75,6 +75,11 @@ void TwoWire::begin(int address)
begin((uint8_t)address);
}
+void TwoWire::setClock(uint32_t frequency)
+{
+ TWBR = ((F_CPU / frequency) - 16) / 2;
+}
+
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop)
{
// clamp to buffer length
diff --git a/libraries/Wire/Wire.h b/libraries/Wire/Wire.h
index a93d0f5..732bdc3 100644
--- a/libraries/Wire/Wire.h
+++ b/libraries/Wire/Wire.h
@@ -49,6 +49,7 @@ class TwoWire : public Stream
void begin();
void begin(uint8_t);
void begin(int);
+ void setClock(uint32_t);
void beginTransmission(uint8_t);
void beginTransmission(int);
uint8_t endTransmission(void);
@@ -62,10 +63,10 @@ class TwoWire : public Stream
virtual int available(void);
virtual int read(void);
virtual int peek(void);
- virtual void flush(void);
+ virtual void flush(void);
void onReceive( void (*)(int) );
void onRequest( void (*)(void) );
-
+
inline size_t write(unsigned long n) { return write((uint8_t)n); }
inline size_t write(long n) { return write((uint8_t)n); }
inline size_t write(unsigned int n) { return write((uint8_t)n); }
diff --git a/libraries/Wire/keywords.txt b/libraries/Wire/keywords.txt
index 12f129b..ff31475 100644
--- a/libraries/Wire/keywords.txt
+++ b/libraries/Wire/keywords.txt
@@ -11,6 +11,7 @@
#######################################
begin KEYWORD2
+setClock KEYWORD2
beginTransmission KEYWORD2
endTransmission KEYWORD2
requestFrom KEYWORD2