HI, Dialog,
My I2C device has two part of program: initialiazing / operation.
I put it in project hrp_sensor.
The initialazing code is at function system_init: (RETARGET has been defined)
//----------------------------------------
static void system_init( void *pvParameters )
{
OS_TASK handle;
unsigned char d;
i2c_device dev;
#if defined CONFIG_RETARGET
extern void retarget_init(void);
# endif
....
....
#if defined CONFIG_RETARGET
retarget_init();
# endif
printf("BLE hrp demo" NEWLINE);
dev = ad_i2c_open(MAX30100); //---- I2C device initializing ----------------------
MAX30100_reset(dev);
d = MAX30100_read(dev,MAX30100_PART_ID);
printf(NEWLINE "PART ID=%02x",d); //--- this line works fine, and program is blocked at here
d = MAX30100_read(dev,MAX30100_REVISION_ID);
printf(NEWLINE "Revision ID=%02x",d);
// Set LED current
MAX30100_setLEDs(dev,i11, i8);
....
....
//----------------------------------------------------------------
When DA14681 runs, my UART terminal shows like this:
//------------------------------
'''' BLE hrp demo
PART ID =11
//------------------------------
the next output 'Revision ID=05' will go on when you connect this BLE device by mobile.
发生了什么在background?
How to improve my code?
Note: my I2C device is controlled by function ad_i2c_read(), ad_i2c_write() --- they works in async mode.
Thanks
Hi jamesleo-konka,
I am not able to tell why the rest of the printf() happened when the device has connected, i can't find any kind of logic behind this unless if you have related code in the main task function, also i am not able to replicate this, at least on my side with RETARGET enabled on the hrp_sensor using the ad_i2c_asynch_transact() directly or the plain i2c_transact or with an ad_i2c_read() and ad_i2c_write() on an I2C slave device, i am able to open the i2c module operate the transaction and print out the data on advertising. Having custom code in the system_init() function is something that its not generally recommended, please have any custom code in the dedicated task function, just before entering the for loop for your task.
Thanks MT_dialog