4 years ago
The Accelerometer control by using i2c
Posted bySean6660 points 3 repliesHi Dialog team,
I try to operate that add the Accelerometer control code to "ble_app_sleepmode".
I could initialize and read the Accelerometer value.
And, I added the Accelerometer control code to interrupt processing of "ble_app_sleepmode" as follows.
I was measured with a logic analyzer.
When I press the bottun, DA14580 did not send a I2C signal.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
static void user_app_button_press_cb(void)
{
arch_printf("user_app_button_press_cb\r\n");
uint8_t next_btn_event = 0;
// Read button state
if(GPIO_GetPinStatus(GPIO_BUTTON_PORT, GPIO_BUTTON_PIN))
{
app_sleep_env.custs1_btn_state = CUSTS1_BTN_STATE_RELEASED;
next_btn_event = WKUPCT_PIN_POLARITY_LOW;
}
else
{
app_sleep_env.custs1_btn_state = CUSTS1_BTN_STATE_PRESSED;
next_btn_event = WKUPCT_PIN_POLARITY_HIGH;
}
i2cMma8652ReadData(); \\←added the Accelerometer control code
// Update button characterstic
struct custs1_val_ntf_req *req = KE_MSG_ALLOC_DYN(CUSTS1_VAL_NTF_REQ,
TASK_CUSTS1,
TASK_APP,
custs1_val_ntf_req,
DEF_CUST1_BUTTON_STATE_CHAR_LEN);
req->conhdl = app_env->conhdl;
req->handle = CUST1_IDX_BUTTON_STATE_VAL;
req->length = DEF_CUST1_BUTTON_STATE_CHAR_LEN;
req->value[0] = app_sleep_env.custs1_btn_state;
ke_msg_send(req);
// Configure next button event
user_app_set_button_event(next_btn_event);
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
However, It stop when I push the button.
Could you tell me why does it stop...?
Development Environment:
* Board: DA14580DEVKT-B
* SDK: DA1458x_SDK_5.0.4
the Accelerometer:MMA8652
initialize processing of the Accelerometer control:
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
void i2c_mma8652_init(void) {
arch_printf("i2c_mma8652_init\r\n");
SetBits16(CLK_PER_REG, I2C_ENABLE, 1); // enable clock for I2C
SetWord16(I2C_ENABLE_REG, 0x0); // Disable the I2C controller
SetWord16(I2C_CON_REG, 0
| I2C_SLAVE_DISABLE
| I2C_RESTART_EN
| I2C_MASTER_MODE);
SetBits16(I2C_CON_REG, I2C_SPEED, I2C_STANDARD);
SetWord16(I2C_TAR_REG, I2C_MMA8652_DEVICE_ADDRESS); // Set Slave device address
// set bit rate for standard mode 100Kbit/sec
//when 16MHz sclk 1/16*(72(H)+8+79(L)+1)= 10 us
SetWord16(I2C_SS_SCL_HCNT_REG,72);
SetWord16(I2C_SS_SCL_LCNT_REG,79);
SetWord16(I2C_RX_TL_REG, 0x10);
SetWord16(I2C_TX_TL_REG, 0x10);
SetWord16(I2C_INTR_MASK_REG,0x200); // enable interrupt for stop bit
SetWord16(I2C_ENABLE_REG, 0x1); // Enable the I2C controller
WAIT_UNTIL_NO_MASTER_ACTIVITY(); // Wait for I2C master FSM to become IDLE
i2cMma8652Standby();
i2c_mma8652_write_byte(XYZ_DATA_CFG, 0x00); // +/-2g range with ~0.977mg/LSB
i2c_mma8652_write_byte(CTRL_REG2, 0x02); // High Resolution mode
i2c_mma8652_write_byte(CTRL_REG3, 0x08); // Push-pull, active low interrupt
i2c_mma8652_write_byte (CTRL_REG4 0 x05);/ /启用DRDY, MT interrupt
i2c_mma8652_write_byte(CTRL_REG5, 0x05); // DRDY, MT interrupt routed to INT1 - PTA5
i2c_mma8652_write_byte(FF_MT_CFG,
EVENT_LATCH_ENABLE | MOTION_DETECT | DETECTION_XYZ_ENABLE);
i2c_mma8652_write_byte(FF_MT_THS, 0x70);
i2c_mma8652_write_byte(FF_MT_COUNT, 0x10);
i2cMma8652WhoAmI();
i2cMma8652Active();
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
4 years ago
Hi, Gongyu_Dialog,
I could operate "i2cMma8652ReadData();" the result of adding "arch_force_active_mode();".
I'm going to consider about message handler function.
Thank you.
4 years ago
I guess you may need to add "arch_force_active_mode();" before "i2cMma8652ReadData(); \\←added the Accelerometer control code"
Also, generally it is not advisable to add "i2cMma8652ReadData(); “ in your current code position.
I may suggest to add in the message handler function.
Just like the call position for the function "user_app_enable_pwm" .