summaryrefslogtreecommitdiff
path: root/tests/i2c-master/i2c-master.c
diff options
context:
space:
mode:
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