Skip to content

Commit

Permalink
Added BMM150 API
Browse files Browse the repository at this point in the history
  • Loading branch information
BST-Github-Admin committed Sep 12, 2017
0 parents commit c7774c9
Show file tree
Hide file tree
Showing 6 changed files with 3,256 additions and 0 deletions.
198 changes: 198 additions & 0 deletions Interrupt_settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
## Steps to configure BMM150 Interrupts
1. Set the value of "desired_settings" from the list of macros from **TABLE 1.0-Macros for enabling the desired_settings**
to enable the configuration of the selected settings. (Multiple settings can be set by bitwise OR-ing of the macros)
> Ex. desired_settings = BMM150_DRDY_PIN_EN_SEL | BMM150_DRDY_POLARITY_SEL;

2. Set the desired configuration in the dev structure using macros from the **TABLE 1.1-Interrupt configuration settings**.
> NOTE : Configuration settings will be set only when we set the corresponding "desired_settings" which enables the settings.
``` c
/* Select the DRDY pin and polarity settings */
desired_settings = BMM150_DRDY_PIN_EN_SEL | BMM150_DRDY_POLARITY_SEL;
/* Set the desired configurations of DRDY pin and its polarity */
dev->settings.int_settings.drdy_pin_en = BMM150_INT_ENABLE;
dev->settings.int_settings.drdy_polarity = BMM150_ACTIVE_LOW_POLARITY;
```
3. Invoke the "bmm150_set_sensor_settings" API after setting the desired configuration in dev structure and enabling the corresponding "desired_settings" value,

4. Invoke the "bmm150_get_interrupt_status" API to get the interrupt status value in the dev->int_status.

The value of dev->int_status is taken and a bitwise AND operation is performed with predefined interrupt status macros (listed below) to find the interrupt status which is either set or reset.

- BMM150_LOW_THRESHOLD_INT_X
- BMM150_LOW_THRESHOLD_INT_Y
- BMM150_LOW_THRESHOLD_INT_Z
- BMM150_HIGH_THRESHOLD_INT_X
- BMM150_HIGH_THRESHOLD_INT_Y
- BMM150_HIGH_THRESHOLD_INT_Z
- BMM150_DATA_OVERFLOW_INT
- BMM150_DATA_OVERRUN_INT
- BMM150_DATA_READY_INT

``` c
/* Example for checking interrupt status*/
if (dev->int_status & BMM150_DATA_READY_INT) {
/*Occurrence of data ready interrupt */
printf("\n Interrupt asserted");
} else {
/* No interrupt occurred */
printf("\n Interrupt not asserted");
}
```
> NOTE : The interrupt configuration settings which are set can be read from the sensor by invoking the "bmm150_get_sensor_settings" API.
> NOTE : In BMM150 the interrupt pin INT is in default latched state and the polarity of INT and DRDY pins in default is active high.
> NOTE : The macros mentioned below are present in the bmm150_defs.h file for setting the desired user configuration.
### TABLE 1.0-Macros for enabling the desired_settings
Macros to set for "desired_settings" | Settings which can be enabled/Disabled
-------------------------------------|----------------------------------------------------------
BMM150_DRDY_PIN_EN_SEL | Data ready interrupt mapping to DRDY PIN
BMM150_INT_PIN_EN_SEL | Low-Threshold, High-Threshold and Overflow interrupts mapping to INT PIN
BMM150_DRDY_POLARITY_SEL | Polarity of DRDY pin
BMM150_INT_LATCH_SEL | Latch settings of INT pin
BMM150_INT_POLARITY_SEL | Polarity of INT pin
BMM150_DATA_OVERRUN_INT_SEL | Data overrun interrupt setting
BMM150_OVERFLOW_INT_SEL | Data overflow interrupt setting
BMM150_HIGH_THRESHOLD_INT_SEL | High threshold interrupt setting
BMM150_LOW_THRESHOLD_INT_SEL | Low threshold interrupt setting
BMM150_LOW_THRESHOLD_SETTING_SEL | Setting Low threshold value to trigger interrupt
BMM150_HIGH_THRESHOLD_SETTING_SEL | Setting High threshold value to trigger interrupt
### TABLE 1.1-Interrupt configuation settings
|User configration in the dev structure |Macros which can be assigned| Significance
|-------------------------------------------|--------------------------- |-----------------------------------------------
|dev->settings.int_settings.drdy_pin_en | BMM150_INT_ENABLE | Maps the data ready interrupt to the DRDY pin of sensor
|^ | BMM150_INT_DISABLE | Disables the mapping of data ready interrupt signal to the DRDY pin
||||
|dev->settings.int_settings.int_pin_en | BMM150_INT_ENABLE | Enables the mapping of Low-Threshold, High-Threshold and Overflow interrupts to INT (interrupt) pin
|^ | BMM150_INT_DISABLE | Disables the interrupt mapping to the INT pin
||||
|dev->settings.int_settings.drdy_polarity | BMM150_ACTIVE_HIGH_POLARITY| Sets the interrupt signal polarity in DRDY pin as active high
|^ | BMM150_ACTIVE_LOW_POLARITY | Sets the interrupt signal polarity in DRDY pin as active low
||||
|dev->settings.int_settings.int_polarity | BMM150_ACTIVE_HIGH_POLARITY| Sets the interrupt signal polarity in INT pin as active high
|^ | BMM150_ACTIVE_LOW_POLARITY | Sets the interrupt signal polarity in INT pin as active low
||||
|dev->settings.int_settings.int_latch | BMM150_LATCHED | Sets the interrupt signal in INT pin in latched mode
|^ | BMM150_NON_LATCHED | Sets the interrupt signal in INT pin in non - latched mode
||||
|dev->settings.int_settings.data_overrun_en | BMM150_INT_ENABLE | Enables the data overrun interrupt
|^ | BMM150_INT_DISABLE | Disables the data overrun interrupt
||||
|dev->settings.int_settings.overflow_int_en | BMM150_INT_ENABLE | Enables the overflow interrupt
|^ | BMM150_INT_DISABLE | Disables the overflow interrupt
||||
|dev->settings.int_settings.high_int_en | BMM150_THRESHOLD_X | Enables the threshold interrupt detection for X axis
|dev->settings.int_settings.high_int_en | BMM150_THRESHOLD_Y | Enables the threshold interrupt detection for Y axis
|^ | BMM150_THRESHOLD_Z | Enables the threshold interrupt detection for Z axis
|^ |(BMM150_THRESHOLD_X & BMM150_THRESHOLD_Y) | Enables the threshold interrupt detection for x,y axes
|^ |(BMM150_THRESHOLD_X & BMM150_THRESHOLD_Y & BMM150_THRESHOLD_Z) | Enables the threshold interrupt interrupt detection for all 3 X,Y and Z axes
### Configuring and handling BMM150 Interrupts
#### Example for using high threshold interrupt
> Configuring the high threshold interrupt
``` c
int8_t high_threshold_interrupt(struct bmm150_dev *dev)
{
int8_t rslt;
uint16_t desired_settings;
/* Enable the desired settings to be set in the sensor */
desired_settings = BMM150_HIGH_THRESHOLD_INT_SEL | BMM150_HIGH_THRESHOLD_SETTING_SEL |
BMM150_INT_PIN_EN_SEL | BMM150_INT_POLARITY_SEL | BMM150_INT_LATCH_SEL;
/* Set the desired configuration */
/* Enable the mapping of interrupt to the interrupt pin*/
dev->settings.int_settings.int_pin_en = BMM150_INT_ENABLE;
/* Set the interrupt in non latched mode */
dev->settings.int_settings.int_latch = BMM150_NON_LATCHED;
/* Set the interrupt polarity as active high */
dev->settings.int_settings.int_polarity = BMM150_ACTIVE_HIGH_POLARITY;
/* Set the threshold value as 0x0A (10*6 = 60 micro-tesla)*/
dev->settings.int_settings.high_threshold = 0x0A;
/* Set the high threshold detection for all 3 axis */
dev->settings.int_settings.high_int_en = BMM150_THRESHOLD_X & BMM150_THRESHOLD_Y & BMM150_THRESHOLD_Z;
/* Set the configurations in the sensor */
rslt = bmm150_set_sensor_settings(desired_settings, dev);
return rslt;
}
```
> Read the interrupt status continuously to check for interrupt assertion (Polling method)
``` c
int8_t high_threshold_interrupt_handling(struct bmm150_dev *dev)
{
int8_t rslt;

rslt = bmm150_get_interrupt_status(dev);
if (rslt == BMM150_OK) {
if (dev->int_status & BMM150_HIGH_THRESHOLD_INT_X) {
printf("\n HIGH THRESHOLD INTERRUPT ON X AXIS ");
}
if (dev->int_status & BMM150_HIGH_THRESHOLD_INT_Y) {
printf("\n HIGH THRESHOLD INTERRUPT ON Y AXIS ");
}
if(dev->int_status & BMM150_HIGH_THRESHOLD_INT_Z) {
printf("\n HIGH THRESHOLD INTERRUPT IN Z AXIS ");
}
}

return rslt;
}
```
#### Example for using multiple interrupts (data ready and overflow interrupts)
> Configuring the overflow and data ready interrupts and interrupt pins and latch settings
``` c
int8_t drdy_overflow_int_setting(struct bmm150_dev *dev)
{
int8_t rslt;
uint16_t desired_settings;
/* Enable the desired settings to be set in the sensor */
desired_settings = BMM150_DRDY_PIN_EN_SEL | BMM150_OVERFLOW_INT_SEL |
BMM150_INT_PIN_EN_SEL | BMM150_INT_LATCH_SEL;
/* Set the desired configuration */
/* Enable the drdy interrupt */
dev->settings.int_settings.drdy_pin_en = BMM150_INT_ENABLE;
/* Enable the mapping of interrupt to the interrupt pin */
dev->settings.int_settings.int_pin_en = BMM150_INT_ENABLE;
/* Enable the overflow interrupt */
dev->settings.int_settings.overflow_int_en = BMM150_INT_ENABLE;
/* Set the interrupt in non latched mode */
dev->settings.int_settings.int_latch = BMM150_NON_LATCHED;
/* Set the configurations in the sensor */
rslt = bmm150_set_sensor_settings(desired_settings, dev);
}
```

> Read the interrupt status continuously to check for interrupt assertion (Polling method)
``` c
int8_t drdy_overflow_int_handling(struct bmm150_dev *dev)
{
int8_t rslt;

rslt = bmm150_get_interrupt_status(dev);
if (rslt == BMM150_OK) {
/* Multiple interrupt assertion can be checked as follows */
if ((dev->int_status & BMM150_DATA_READY_INT) ||
(dev->int_status & BMM150_DATA_OVERFLOW_INT)) {
/* Either data ready or overflow has occurred */
printf("\n Interrupt asserted ");
} else {
printf("\n Interrupt not asserted ");
}
}

return rslt;
}
```
Loading

0 comments on commit c7774c9

Please sign in to comment.