summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/accel.c
diff options
context:
space:
mode:
Diffstat (limited to 'stmhal/accel.c')
-rw-r--r--stmhal/accel.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/stmhal/accel.c b/stmhal/accel.c
index 339a93ea40..9890aa3c7f 100644
--- a/stmhal/accel.c
+++ b/stmhal/accel.c
@@ -12,6 +12,8 @@
#include "i2c.h"
#include "accel.h"
+#if MICROPY_HW_HAS_MMA7660
+
#define MMA_ADDR (0x98)
#define MMA_REG_X (0)
#define MMA_REG_Y (1)
@@ -33,7 +35,15 @@ void accel_init(void) {
}
STATIC void accel_start(void) {
- // start the I2C bus
+ // start the I2C bus in master mode
+ I2CHandle1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
+ I2CHandle1.Init.ClockSpeed = 400000;
+ I2CHandle1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
+ I2CHandle1.Init.DutyCycle = I2C_DUTYCYCLE_16_9;
+ I2CHandle1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
+ I2CHandle1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
+ I2CHandle1.Init.OwnAddress1 = PYB_I2C_MASTER_ADDRESS;
+ I2CHandle1.Init.OwnAddress2 = 0xfe; // unused
i2c_init(&I2CHandle1);
// turn off AVDD, wait 20ms, turn on AVDD, wait 20ms again
@@ -174,3 +184,5 @@ const mp_obj_type_t pyb_accel_type = {
.make_new = pyb_accel_make_new,
.locals_dict = (mp_obj_t)&pyb_accel_locals_dict,
};
+
+#endif // MICROPY_HW_HAS_MMA7660