Hi Dialog,
One week has gone, but I can't add I2C in hrp_sensor project.
At beginning, I study the peripherals_demo and get know something about dg_configUSExxx and file system of a project.
这n I moved to hrp_sensor project because it enable the ble function, that's my goal.
It's not easy to get understood the project peripherals_demo, files nested deeply, main.c -> periph_setup.c --> demo_i2c.c .....
这project hrp_sensor is simple, only 2 files.
But, the simple work for adding I2C into hrp_sensor is stucked.
这se is the steps I followed:
1. in custom_config_qspi.h
#define dg_configuse_hw_i2c 1
#define dg_configI2C_ADAPTER 1
从platform_device.h迁移代码,如下所示:
// -------------------------------------------------------
#if dg_configI2C_ADAPTER
I2C_BUS(I2C1)
i2c_slave_device(i2c1,“max30100”,0xae,hw_i2c_addressing_7b,hw_i2c_speed_standard);
I2C_BUS_END
#endif /* dg_configI2C_ADAPTER */
// ---------------------------------------------------------
include "ad_i2c.h" //---this define the I2C_BUS()
2.在Main.c
注释出platform_device.h - 这是每个项目的一个通用文件,并定位:\ sdk \适配器\包含
//#包含“platform_devices.h”
#include "hw_i2c.h"
add I2C init code in periph_init fuction
// ----------------------------------------------------------------
//----hw init for I2C---
/*
* Initialize I2C controller in master mode with standard communication speed (100 kb/s) and
* transfer in 7-bit addressing mode.
*/
静态const i2c_config cfg = {
.speed = HW_I2C_SPEED_STANDARD,
.mode = HW_I2C_MODE_MASTER,
.addr_mode = HW_I2C_ADDRESSING_7B,
};
hw_i2c_init(HW_I2C1, &cfg);
srand(os_get_tick_count());//?
hw_i2c_disable(HW_I2C1);
hw_i2c_set_target_address(hw_i2c1,0x7e);// max30100.
hw_i2c_enable(HW_I2C1);
/*
* Setting address in our case means we'll start some transfer with new device. For this
* reason it's good to reset abort source in order to start in clean state (to avoid having
* abort source set by previous transfer to other device), otherwise we need to remember
* about this before every transfer separately.
*/
hw_i2c_reset_abort_source(HW_I2C1);
//---------------------------------
When build this project , there is a error: can't find 'ad_i2c.h' ! --- but in the Includes, the file ad_i2c.h is there : Includes->hrp_sensor/sdk/adapters/include
What's wrong?
Is there a guide/manual for adding I2C periperal step by step?
Would you please send me a project based on hrp_sensor with I2C extended ?
Thanks
Hi jamesleo-konka,
1)在Custom_config_qspi.h文件中启用允许是正确的,因此您可以使用QSPI的HW和适配器。
2) Regarding the platform_devices.h file as i ve mentioned to your other post, if you have a custom one this will be used and not the default one.
3)支持站点上没有上传的文件,尽管如此,您不必调用在Periph_setup()函数中提到的函数。这
periph_init function is essentially a callback where the periph_setup() function is stored and gets invoked if the pointer that function is not NULL. So in the
periph_setup() function you will have to configure your pins for the I2C functionallity, normally the hw_gpio_configure() is used with an gpio_config array passed
as a parameter with the conifguration of each pin, the HW_GPIO_PINCONFIG MACRO is used. The initialization of the I2C hw will be done by the i2c adapter so you
在外围设备遗失期间,不需要明确地执行此操作(如果您在Platform_Devices.h文件中正确定义了外部设备)
When the hw_i2c_set_target_address() is invoke, that doesn't mean that an i2c transaction is starting, you are just setting the target register of the I2C module,
使用API可用启动交易,模块将在开始事务时立即启动总线上的数据输出。例如,在Periph_setup()函数中设置引脚并在platform_devices中声明您的设备和违反您启用的I2C适配器和驱动程序,您开始事务,例如,从传感器中读取包含以下传感器的字节命令your_device's_handle = ad_i2c_open(your_device),然后是ad_i2c_transact(your_device's_handle,address_to_read,size,Out_buffer,size)。
Regarding the ad_i2c.h file that the compiler doesn't find it i am not able to replicate that, eclipse finds the ad_i2c.h file as soon as i add it to the hrp_sensor_task.c file, is the directory sdk/adapters/include in the include paths ?
Regarding the project request, i am sorry but there is no heart rate project based on a I2C sensor.
Thanks MT_dialog
Hi MT_Dialog,
Thanks for your kind reply.
According to the method of Dialog's engineer, I tried to init I2C adapter in custom_config_qspi.h but failed at the 'ad_i2c.h'.
It's strange that the 'ad_i2c.h' can't be included in custom_config_qspi.h, but is ok if used in main.c !
So I moved the code into main.c, it passed building.
在Project Peripherals_demo中,GPIO端口/引脚已在Periph_setup()中初始化,也是I2C:Demo_i2c_init()
//-------------------------------------
void demo_i2c_init(void)
{
/*
* Initialize I2C controller in master mode with standard communication speed (100 kb/s) and
* transfer in 7-bit addressing mode.
*/
静态const i2c_config cfg = {
.speed = HW_I2C_SPEED_STANDARD,
.mode = HW_I2C_MODE_MASTER,
.addr_mode = HW_I2C_ADDRESSING_7B,
};
hw_i2c_init(HW_I2C1, &cfg);
srand(os_get_tick_count());
}
// ------------------------------------
It seems like no GPIO port/pins need to be initialized.
BTW,最后行的函数是什么:srand(os_get_tick_count());?
I'll check the I2C's adater code, like ad_i2c_open (i2c_device_id dev_id), ad_i2c_transact ,...
Thanks
Hi jamesleo-konka,
You dont need that, this is used in the peripherals demo since it uses the rand() function in order to populate random data in its write buffer (it writes random data into the EEPROM).
Thanks MT_dialog