Hello Team Dialog,
I have been struggling setting up BMI270 over I2C interface. Bosh BMI 270 IMU provides an API which can be retrived from
https://github.com/BoschSensortec/BMI270-Sensor-API
For DA14585, I followed the i2c_eeprom project instruction. I will greatly appreciate if samples of the functions below can can be illustrated with examples.
Best Regards
* @brief Function for writing the sensor's registers through I2C bus.
*
* @param[in] i2c_addr : sensor I2C address.
* @param[in] reg_addr : Register address.
* @param[in] reg_data : Pointer to the data buffer whose value is to be written.
* @param[in] length : No of bytes to write.
*
* @return Status of execution
* @retval 0 -> Success
* @retval >0 -> Failure Info
*
*/
int8_t i2c_reg_write(uint8_t i2c_addr, uint8_t reg_addr, const uint8_t *reg_data, uint16_t length)
{
/* Write to registers using I2C. Return 0 for a successful execution. */
return 0;
}
/*!
* @brief Function for reading the sensor's registers through I2C bus.
*
* @param[in] i2c_addr : Sensor I2C address.
* @param[in] reg_addr : Register address.
* @param[out] reg_data : Pointer to the data buffer to store the read data.
* @param[in] length : No of bytes to read.
*
* @return Status of execution
* @retval 0 -> Success
* @retval >0 -> Failure Info
*
*/
int8_t i2c_reg_read(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length)
{
/* Read from registers using I2C. Return 0 for a successful execution. */
return 0;
}
Hi cripsly,
We have recently published an example that shows how to interface with the Bosch BMP388:
//www.xmece.com/sites/default/files/da14531_ble_pre...
This example is for the DA14531, however the DA14585 shares the same SDK and so example this should give you the API examples you are looking for.
Best regards
IM_Dialog
我建议使用API i2c BMP388 p的函数roject. However, I did not get any bus transaction on the i2c bus. Kindly let me know what I might be doing wrong.
Thanks in advance.
int8_t i2c_init(void)
{
GPIO_ConfigurePin(I2C_GPIO_PORT, I2C_SCL_PIN, INPUT, PID_I2C_SCL, false);
GPIO_ConfigurePin(I2C_GPIO_PORT, I2C_SDA_PIN, INPUT, PID_I2C_SDA, false);
SetBits16(CLK_16M_REG, XTAL16_BIAS_SH_ENABLE, 1);
cfg->clock_cfg.ss_hcnt = I2C_SS_SCL_HCNT_REG;
cfg->clock_cfg.ss_lcnt = I2C_SS_SCL_LCNT_REG;
cfg->clock_cfg.fs_hcnt = I2C_FS_SCL_HCNT_REG;
cfg->clock_cfg.fs_lcnt = I2C_FS_SCL_LCNT_REG;
cfg->speed = I2C_SPEED_FAST;
cfg->mode = I2C_MODE_MASTER;
cfg->addr_mode = I2C_ADDRESSING_7B;
cfg->address = 0x68;
cfg->tx_fifo_level = cfg->rx_fifo_level = 32;
GLOBAL_INT_DISABLE();
//Enable i2c clock to R/W i2c registers
i2c_set_clock_status(I2C_CLOCK_ENABLE);
// Enable interrupts
GLOBAL_INT_RESTORE();
i2c_set_controller_status(I2C_CONTROLLER_DISABLE);
while(i2c_get_controller_status() != I2C_CONTROLLER_DISABLE);
i2c_set_int_mask(0x0000);
/ / sci时钟设置
SetWord16(&i2c->I2C_SS_SCL_HCNT_REGF, cfg->clock_cfg.ss_hcnt);
SetWord16(&i2c->I2C_SS_SCL_LCNT_REGF, cfg->clock_cfg.ss_lcnt);
SetWord16(&i2c->I2C_FS_SCL_HCNT_REGF, cfg->clock_cfg.fs_hcnt);
SetWord16(&i2c->I2C_FS_SCL_LCNT_REGF, cfg->clock_cfg.fs_lcnt);
// Set speed mode
// SetBits16(&i2c->I2C_CON_REGF, I2C_SPEED, cfg->speed);
SetBits16(&i2c->I2C_CON_REGF, I2C_SPEED, I2C_SPEED_FAST);
// Set fifo levels
ASSERT_WARNING(32 != 0);
ASSERT_WARNING(32 != 0);
SetBits16(&i2c->I2C_TX_TL_REGF, RX_TL, 32- 1);
SetBits16(&i2c->I2C_RX_TL_REGF, RX_TL, 32 - 1);
// Setup I2C master
i2c_setup_master(I2C_RESTART_ENABLE, I2C_ADDRESSING_7B, 0x68);
i2c_set_controller_status(I2C_CONTROLLER_ENABLE);
// There is a two ic_clk delay when enabling or disabling the controller
while ((i2c_get_controller_status() != I2C_CONTROLLER_ENABLE));
// Set the priority of I2C interrupt to level 2
NVIC_SetPriority(I2C_IRQn, 2);
// Enable I2C interrupt
NVIC_EnableIRQ(I2C_IRQn);
/* Implement I2C bus initialization according to the target machine. */
return 0;
}
int8_t reg_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
/* Write to registers using I2C. Return 0 for a successful execution. */
int ret = 0;
uint16_t bytes_written;
i2c_abort_t abrt_code;
uint32_t flags = I2C_F_NONE;
/* Each I2C device on the bus has a unique address, set this before we communicate */
set_dev_addr(reg_addr);
/* Perform blocking write */
bytes_written = i2c_master_transmit_buffer_sync(reg_data, length, &abrt_code, flags);
if ((I2C_ABORT_NONE != abrt_code) || (bytes_written != length)) {
ret = -1;
}
return ret;
}
int8_t i2c_reg_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
int ret =0;
uint16_t bytes_read;
i2c_abort_t abrt_code;
uint32_t flags = I2C_F_NONE;
set_dev_addr(reg_addr);
bytes_read =我2c_master_receive_buffer_sync(reg_data, length, &abrt_code, flags);
if ((abrt_code != I2C_ABORT_NONE) || (bytes_read != length)) {
ret = -1;
}
return ret;
}
我建议使用API i2c BMP388 p的函数roject. However, I did not get any bus transaction on the i2c bus. Kindly let me know what I might be doing wrong.
Thanks in advance.
int8_t i2c_init(void)
{
GPIO_ConfigurePin(I2C_GPIO_PORT, I2C_SCL_PIN, INPUT, PID_I2C_SCL, false);
GPIO_ConfigurePin(I2C_GPIO_PORT, I2C_SDA_PIN, INPUT, PID_I2C_SDA, false);
SetBits16(CLK_16M_REG, XTAL16_BIAS_SH_ENABLE, 1);
cfg->clock_cfg.ss_hcnt = I2C_SS_SCL_HCNT_REG;
cfg->clock_cfg.ss_lcnt = I2C_SS_SCL_LCNT_REG;
cfg->clock_cfg.fs_hcnt = I2C_FS_SCL_HCNT_REG;
cfg->clock_cfg.fs_lcnt = I2C_FS_SCL_LCNT_REG;
cfg->speed = I2C_SPEED_FAST;
cfg->mode = I2C_MODE_MASTER;
cfg->addr_mode = I2C_ADDRESSING_7B;
cfg->address = 0x68;
cfg->tx_fifo_level = cfg->rx_fifo_level = 32;
GLOBAL_INT_DISABLE();
//Enable i2c clock to R/W i2c registers
i2c_set_clock_status(I2C_CLOCK_ENABLE);
// Enable interrupts
GLOBAL_INT_RESTORE();
i2c_set_controller_status(I2C_CONTROLLER_DISABLE);
while(i2c_get_controller_status() != I2C_CONTROLLER_DISABLE);
i2c_set_int_mask(0x0000);
/ / sci时钟设置
SetWord16(&i2c->I2C_SS_SCL_HCNT_REGF, cfg->clock_cfg.ss_hcnt);
SetWord16(&i2c->I2C_SS_SCL_LCNT_REGF, cfg->clock_cfg.ss_lcnt);
SetWord16(&i2c->I2C_FS_SCL_HCNT_REGF, cfg->clock_cfg.fs_hcnt);
SetWord16(&i2c->I2C_FS_SCL_LCNT_REGF, cfg->clock_cfg.fs_lcnt);
// Set speed mode
// SetBits16(&i2c->I2C_CON_REGF, I2C_SPEED, cfg->speed);
SetBits16(&i2c->I2C_CON_REGF, I2C_SPEED, I2C_SPEED_FAST);
// Set fifo levels
ASSERT_WARNING(32 != 0);
ASSERT_WARNING(32 != 0);
SetBits16(&i2c->I2C_TX_TL_REGF, RX_TL, 32- 1);
SetBits16(&i2c->I2C_RX_TL_REGF, RX_TL, 32 - 1);
// Setup I2C master
i2c_setup_master(I2C_RESTART_ENABLE, I2C_ADDRESSING_7B, 0x68);
i2c_set_controller_status(I2C_CONTROLLER_ENABLE);
// There is a two ic_clk delay when enabling or disabling the controller
while ((i2c_get_controller_status() != I2C_CONTROLLER_ENABLE));
// Set the priority of I2C interrupt to level 2
NVIC_SetPriority(I2C_IRQn, 2);
// Enable I2C interrupt
NVIC_EnableIRQ(I2C_IRQn);
/* Implement I2C bus initialization according to the target machine. */
return 0;
}
int8_t reg_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
/* Write to registers using I2C. Return 0 for a successful execution. */
int ret = 0;
uint16_t bytes_written;
i2c_abort_t abrt_code;
uint32_t flags = I2C_F_NONE;
/* Each I2C device on the bus has a unique address, set this before we communicate */
set_dev_addr(reg_addr);
/* Perform blocking write */
bytes_written = i2c_master_transmit_buffer_sync(reg_data, length, &abrt_code, flags);
if ((I2C_ABORT_NONE != abrt_code) || (bytes_written != length)) {
ret = -1;
}
return ret;
}
int8_t i2c_reg_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
int ret =0;
uint16_t bytes_read;
i2c_abort_t abrt_code;
uint32_t flags = I2C_F_NONE;
set_dev_addr(reg_addr);
bytes_read =我2c_master_receive_buffer_sync(reg_data, length, &abrt_code, flags);
if ((abrt_code != I2C_ABORT_NONE) || (bytes_read != length)) {
ret = -1;
}
return ret;
}
Hi cripsly,
Check that the GPIO you are using for the I2C intereface are correctly configured in the set_pad_functions function found in the user_periph_setup.c file.
Best regards
IM_Dialog
Hello Dialog,
Sorry for any inconvenience. I have checked this setting. I'm still unable to get it to work....
I only need to use these 3 functions
* @brief Function for writing the sensor's registers through I2C bus.
*
* @param[in] i2c_addr : sensor I2C address.
* @param[in] reg_addr : Register address.
* @param[in] reg_data : Pointer to the data buffer whose value is to be written.
* @param[in] length : No of bytes to write.
*
* @return Status of execution
* @retval 0 -> Success
* @retval >0 -> Failure Info
*
*/
int8_t i2c_reg_write(uint8_t i2c_addr, uint8_t reg_addr, const uint8_t *reg_data, uint16_t length)
{
/* Write to registers using I2C. Return 0 for a successful execution. */
return 0;
}
/*!
* @brief Function for reading the sensor's registers through I2C bus.
*
* @param[in] i2c_addr : Sensor I2C address.
* @param[in] reg_addr : Register address.
* @param[out] reg_data : Pointer to the data buffer to store the read data.
* @param[in] length : No of bytes to read.
*
* @return Status of execution
* @retval 0 -> Success
* @retval >0 -> Failure Info
*
*/
int8_t i2c_reg_read(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length)
{
/* Read from registers using I2C. Return 0 for a successful execution. */
return 0;
}
Hi cripsly,
Could you please use a logic analyzer, probe the I2C signals and share a snapshot?
Did you follow the example that IM_Dialog has already suggested?
Thanks, PM_Dialog