summaryrefslogtreecommitdiff
path: root/tests/i2c-master/i2c-master.c
diff options
context:
space:
mode:
authorKarl Palsson <karlp@tweak.net.au>2017-02-21 23:11:43 +0000
committerKarl Palsson <karlp@tweak.net.au>2017-02-21 23:11:43 +0000
commit65301e5a0b382585887ea7b13e4eb9b0cb26c60f (patch)
tree7c6cf4cb70575c4dfa144e7894f05352207fc01b /tests/i2c-master/i2c-master.c
parent115b771e56aba7e7d066c8a58819d61d51009116 (diff)
downloadolsndot-65301e5a0b382585887ea7b13e4eb9b0cb26c60f.tar.gz
olsndot-65301e5a0b382585887ea7b13e4eb9b0cb26c60f.tar.bz2
olsndot-65301e5a0b382585887ea7b13e4eb9b0cb26c60f.zip
i2c-master: start progressing to extracting common i2c code
Diffstat (limited to 'tests/i2c-master/i2c-master.c')
-rw-r--r--tests/i2c-master/i2c-master.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/i2c-master/i2c-master.c b/tests/i2c-master/i2c-master.c
new file mode 100644
index 0000000..64c9cfe
--- /dev/null
+++ b/tests/i2c-master/i2c-master.c
@@ -0,0 +1,23 @@
+/*
+ * Feb 2017, Karl Palsson <karlp@tweak.net.au>
+ */
+
+#include <libopencm3/stm32/i2c.h>
+#include <libopencm3/stm32/rcc.h>
+#include "hw.h"
+#include "i2c-master.h"
+
+
+void i2cm_init(void) {
+ rcc_periph_clock_enable(hw_details.periph_rcc);
+ rcc_periph_reset_pulse(hw_details.periph_rst);
+ i2c_set_standard_mode(hw_details.periph);
+ i2c_enable_ack(hw_details.periph);
+ //i2c_set_dutycycle(hw_details.periph, I2C_CCR_DUTY_DIV2); /* default, no need to do this really */
+ i2c_set_clock_frequency(hw_details.periph, I2C_CR2_FREQ_42MHZ);
+ /* 42MHz / (100kHz * 2) */
+ i2c_set_ccr(hw_details.periph, 210);
+ /* standard mode, freqMhz+1*/
+ i2c_set_trise(hw_details.periph, 43);
+ i2c_peripheral_enable(hw_details.periph);
+} \ No newline at end of file