I2C during ble advertising

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
22 posts / 0 new
Last post
mapart
Offline
Last seen:2 months 3 weeks ago
加入:2018-11-30 15:58
I2C during ble advertising

Hi,

We would like to read a sensor over i2c periodically, preferably when the da14585 wakes up to do the BLE advertising.
To read the sensor, we must first wake up the sensor by driving a pin high, wait ~1ms, then read 8 bytes of data over i2c.
This sequence works by itself, but when I try to do it in either the callback user_app_main_loop_callbacks.app_on_system_powered or user_app_main_loop_callbacks.app_before_sleep I get stuck somehow.

The sequence to initialize the i2c which is called from periph_init:

void init_acc_i2c(void)
{
SetBits16(CLK_PER_REG, I2C_ENABLE, 1); // enable clock for I2C
SetWord16(I2C_ENABLE_REG, 0x0); // Disable the I2C controller
SetWord16(I2C_CON_REG,0x0063); //12c master, 7bit slave address, 100kbit
SetWord16(I2C_TAR_REG,ACCELEROMETER_I2C_ADDR);

SetWord16(I2C_ENABLE_REG, 0x1); // Enable the I2C controller
}

The code to read the sensor data, which I try to call from the callback described above:

void read_sensor_sequentially(void)
{
int i;
uint8_t data[8];
GPIO_SetActive(ACCELEROMETER_ENABLE_PORT,ACCELEROMETER_ENABLE_PIN);
systick_wait(1000);
GLOBAL_INT_DISABLE();
SetWord16(I2C_DATA_CMD_REG,0x00);
for(i=0;i<7;i++)
{
WAIT_WHILE_I2C_FIFO_IS_FULL();
SetWord16(I2C_DATA_CMD_REG,0x0100);
}
GLOBAL_INT_RESTORE();

for(i=0;i<7;i++)
{
WAIT_FOR_RECEIVED_BYTE(); // Wait for received data
data[i]=(0xFF & GetWord16(I2C_DATA_CMD_REG)); // Get the received byte
}

GPIO_SetInactive(ACCELEROMETER_ENABLE_PORT,ACCELEROMETER_ENABLE_PIN);
WAIT_UNTIL_I2C_FIFO_IS_EMPTY(); // Wait until Tx FIFO is empty
WAIT_UNTIL_NO_MASTER_ACTIVITY(); // wait until no master activity

}

有可能使用任何回调的疼痛吗ive this?

Best regards
Martin

Device:
PM_Dialog
Offline
Last seen:3 days 7 hours ago
Staff
加入:2018-02-08 11:03
Hi mapart,

Hi mapart,

阅读传感器定期你的计谋ld use the app_easy_timer() API. Every time that the timer expired, the registered callback will be triggered, so you need to register the callback that you are reading the sensor. In case of reading the sensor every time that the DA1458, could you please share more details? The device enters the sleep mode between adverting or connection intervals. Did you configure it to enter the deep sleep mode, as it is demonstrated in the ble_app_sleepmode example of the SDK?

Thanks, PM_Dialog

mapart
Offline
Last seen:2 months 3 weeks ago
加入:2018-11-30 15:58
Hi,

Hi,

To provide some context:
SDK version, 6.0.10.511.
We've used ble_app_security as the base in this project, but configured it to use extended sleep mode. This makes the device enter sleep between advertising.
Ideally, we would like to read this sensor each time the da14585 wakes up to do the advertising.
If we would use the app_easy_timer(), the device would wake up from sleep just to do the sensor reading, correct?
The best for us would be to do the sensor reading when the device is already awake.

Best regards
Martin

PM_Dialog
Offline
Last seen:3 days 7 hours ago
Staff
加入:2018-02-08 11:03
Hi mapart,

Hi mapart,

With the usage of the use the app_easy_timer(), you could implement the periodically reading of the sensor. Your device is initially advertising and while it’s adverting the sensor should be read periodically by the application, After an amount of time, you stop adverting and when the device wakes up by configuring the wake up controller, the application should start reading again the sensor periodically. Is that correct? Or you would like to read the sensor in every advertising interval? Please let me know and share what you exactly want to accomplish. It would be very helpful in order to provide you the correct guidelines.

Thanks, PM_Dialog

mapart
Offline
Last seen:2 months 3 weeks ago
加入:2018-11-30 15:58
Hi,

Hi,
Yes I would like to read the sensor in every advertising interval (687.5 ms).
I think I managed to get this working by using the callback:
user_app_main_loop_callbacks.app_on_system_powered

Thank you for your help.
Best Regards
Martin

PM_Dialog
Offline
Last seen:3 days 7 hours ago
Staff
加入:2018-02-08 11:03
Hi mapart,

Hi mapart,

Glad the you figured you issue out and thanks for accepting the answer.

Thanks, PM_Dialog

rajucoolsuraj
Offline
Last seen:10 months 3 days ago
加入:2018-12-12 16:09
Hello Dialog,

Hello Dialog,
A similar example with another workflow -
Sensor >> i2c >> DA14586.
RTC >> GPIOx / WKUP interrupt >> DA14586

Normal operations of BLE would proceed for advertising as per sample applications provided with SDK.
When an interrupt is raised from RTC and BLE is still in Advertising mode -

Record time stamp; Record sensor data; store sensor data in flash;

When BLE is connected to peer -
Disable RTC interrupt; Transfer Flash data over BLE to a Central Device (Ususally smart phone);

Can you help me out with code insertion and handling for -
1. RTC interrupt handling (Active and sleep state)
2 . BLE transmission using DSPS from Dialog.

Thanks

PM_Dialog
Offline
Last seen:3 days 7 hours ago
Staff
加入:2018-02-08 11:03
Hi rajucoolsuraj,

Hi rajucoolsuraj,

If I am able to understand correctly you would like to wake the device up when getting an interrupt correct? So, the device will be in sleep mode and when you get the interrupt from RTC (please clarify what the RTC is) the device will wake up and start advertising. If you would like to follow this implementation, I would suggest you to have a look at the ble_app_sleepmode example of the SDK. The only difference is that in this example the DA14585/6 wakes up from an interrupt which is generated by a button pressing. Are you using the DSPS application code or you have developed a custom application? Please check the user_send_ble_data() from the DSPS application code. Also, I would recommend you to have a look at the DSPS user manual and check figure 6 & 7.

https://support.dialog-semiconductor.com/system/files/resources/UM-B-038%20DA14580%20Serial%20Port%20Service%20reference%20application_v2.0.pdf

Thanks, PM_Dialog

rajucoolsuraj
Offline
Last seen:10 months 3 days ago
加入:2018-12-12 16:09
Thanks Dialog,

Thanks Dialog,

I would like to evaluate and post back here.

I have also raised another post on I2C controller interface with sensor.

It seems that the controller does not send the salve device's register address after transmitting slave device address on SDA wire.

Can I get an assistance on that?

Thanks

Raju

HONEYWELL

PM_Dialog
Offline
Last seen:3 days 7 hours ago
Staff
加入:2018-02-08 11:03
Hi rajucoolsuraj,
rajucoolsuraj
Offline
Last seen:10 months 3 days ago
加入:2018-12-12 16:09
Thanks Dialog,

Thanks Dialog,
But, When I want a GPIO IRQ enabled without sleep modes.

When should I handle the interrupt before the connection with peer; when the periph is advertising?

THanks

Raju

PM_Dialog
Offline
Last seen:3 days 7 hours ago
Staff
加入:2018-02-08 11:03
Hi rajucoolsuraj,

Hi rajucoolsuraj,

You could enable the IRQ upon the initialization (.app_on_init) or in the user_app_adv_start. But be aware that you have to not use any of the sleep modes in order to detect the interrupt. If you would like to have any of the sleep mode configuration, you should use the wakeup controller.

Thanks, PM_Dialog

rajucoolsuraj
Offline
Last seen:10 months 3 days ago
加入:2018-12-12 16:09
Thanks Dialog,

Thanks Dialog,

I shall make use of WakeUp IRQ for both active and sleep modes. It seems better over GPIO.

If there are any erroneous encounters that might result of using WakeUp IRQ via GPIO, I would like to know of it

THanks

PM_Dialog
Offline
Last seen:3 days 7 hours ago
Staff
加入:2018-02-08 11:03
Hi rajucoolsuraj,

Hi rajucoolsuraj,

I would strongly recommend to have a look at the ble_app_sleepmode example of the SDK in order to understand how to use the wake-up controller.

Thanks, PM_Dialog

rajucoolsuraj
Offline
Last seen:10 months 3 days ago
加入:2018-12-12 16:09
Hello Dialog,

Hello Dialog,
The WakeUp controller usage upon connection in custom message handlers for button callback is the best usecase example.

I shall revert back incase of any logical breakdown during implementation.

Thanks

PM_Dialog
Offline
Last seen:3 days 7 hours ago
Staff
加入:2018-02-08 11:03
Hi rajucoolsuraj,

Hi rajucoolsuraj,

如果你想要任何的睡眠国防部es, the solution is to use the wake-up controller in order to detect the interrupt and wake up. Please check the app_button_enable() function which enables the wake-up controller before the device enters the sleep mode. You can select the GPIO that you could detect the wake-up interrupt with the wkupct_enable_irq() function. You can also configure the polarity and the debouncing time as well. Since the device goes into sleep and you send an interrupt to the wake-up controller, the callback function which is registered into wkupct_register_callback() will be triggered.

Thanks, PM_Dialog

rajucoolsuraj
Offline
Last seen:10 months 3 days ago
加入:2018-12-12 16:09
Hello Dialog,

Hello Dialog,

I have registered multiple callbacks using WakeUp controller callback registration, how are the interrupts from several GPIO's serviced ?

Is it the last one that triggered among the registered GPIO's ?

Thanks

Regards

Raju

PM_Dialog
Offline
Last seen:3 days 7 hours ago
Staff
加入:2018-02-08 11:03
Hi rajucoolsuraj,

Hi rajucoolsuraj,

Could you please clarify what you have done? If I am able to understand correctly, you configured the firmware to wake up from different GPIOs? If yes, the first on will wake your chip up.

Thanks, PM_Dialog

rajucoolsuraj
Offline
Last seen:10 months 3 days ago
加入:2018-12-12 16:09
Hello Dialog,

Hello Dialog,
Thanks.

Also, How to check for the GPIO pin source that triggered the interrupt via the WakeUp controller ?

Is there any register or any mechanism in the SDK that allows me to validate the interrupt source ?

Thanks

Raju

PM_Dialog
Offline
Last seen:3 days 7 hours ago
Staff
加入:2018-02-08 11:03
Hi rajucoolsuraj,

Hi rajucoolsuraj,

There is no register that will indicate the port/pin that the interrupt occurred, what you can do in order to check the source of the pulse is to read the status of the pin right after the device has been awaken. So, according to the pin status you will have to decide which callback function will be triggered. Please kindly try to not duplicate your questions on the forum, you have created a similar forum thread and I have replied you there:

https://support.dialog-semiconductor.com/forums/post/dialog-smartbond-bluetooth-low-energy-%E2%80%93-software/multiple-code-space-wkupenableirq

Thanks, PM_DIalog

rajucoolsuraj
Offline
Last seen:10 months 3 days ago
加入:2018-12-12 16:09
Hello Dialog,

Hello Dialog,

Sorry for the duplicates. Yes, thanks for the support.

Also, I have raised another concern on that thread.

Regards

Raju

PM_Dialog
Offline
Last seen:3 days 7 hours ago
Staff
加入:2018-02-08 11:03
Hi rajucoolsuraj,

Hi rajucoolsuraj,

No problem! Let’s continue the conversation in your other forum thread.

Thanks, PM_Dialog