aboutsummaryrefslogtreecommitdiff
path: root/libraries/Wire/src/utility/twi.c
diff options
context:
space:
mode:
authorPaolo Paolucci <p.paolucci@tiscali.it>2016-03-07 18:40:09 +0100
committerSandeep Mistry <s.mistry@arduino.cc>2016-03-09 15:47:55 -0500
commit7b2f6fc02881ec6a01a3b1d4ae248202232c4c6c (patch)
tree47af934bd7b435c2a1d7255b22eaa52ee15f1df5 /libraries/Wire/src/utility/twi.c
parentaa710ab682fd73ed8ea166ebbf24d103673c5ca6 (diff)
Fix Wire register
Move TWBR register from Wire.cpp to twi.c file.
Diffstat (limited to 'libraries/Wire/src/utility/twi.c')
-rw-r--r--libraries/Wire/src/utility/twi.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/libraries/Wire/src/utility/twi.c b/libraries/Wire/src/utility/twi.c
index 7efcc5a..f5d7d5b 100644
--- a/libraries/Wire/src/utility/twi.c
+++ b/libraries/Wire/src/utility/twi.c
@@ -119,6 +119,22 @@ void twi_setAddress(uint8_t address)
}
/*
+ * Function twi_setClock
+ * Desc sets twi bit rate
+ * Input Clock Frequency
+ * Output none
+ */
+void twi_setFrequency(uint32_t frequency)
+{
+ TWBR = ((F_CPU / frequency) - 16) / 2;
+
+ /* twi bit rate formula from atmega128 manual pg 204
+ SCL Frequency = CPU Clock Frequency / (16 + (2 * TWBR))
+ note: TWBR should be 10 or higher for master mode
+ It is 72 for a 16mhz Wiring board with 100kHz TWI */
+}
+
+/*
* Function twi_readFrom
* Desc attempts to become twi bus master and read a
* series of bytes from a device on the bus