-
Notifications
You must be signed in to change notification settings - Fork 0
DPS310 I2C Pressure Sensor Interface #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Burke-Daniel
wants to merge
10
commits into
master
Choose a base branch
from
feature/ND/pressure-sensor-I2C-interface
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
09ff7cb
Begin implementing pressure sensor I2C interface
Burke-Daniel 0bb65f8
Continue defining methods for pressure sensor interface
Burke-Daniel e1d2821
Add interface lib files from vendor
Burke-Daniel 3116ab8
Compilation fixes
Burke-Daniel cef6293
Remove class qualifier in header
Burke-Daniel 1979886
Add pressure sensor instantiation to test
Burke-Daniel d28d9a0
Add driver and sensor src files to build config
Burke-Daniel 2c734a0
Add missing function definitions
Burke-Daniel a3710c2
code for reading sensors into ATMega and logging to serial
imprivatahackathon 3cb9b1a
builds on Mega, code to log sensors over serial
mjswen0923 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #ifndef DPSREGISTER_H_INCLUDED | ||
| #define DPSREGISTER_H_INCLUDED | ||
|
|
||
| #include <Arduino.h> | ||
|
|
||
| typedef struct | ||
| { | ||
| uint8_t regAddress; | ||
| uint8_t mask; | ||
| uint8_t shift; | ||
| } RegMask_t; | ||
|
|
||
| typedef struct | ||
| { | ||
| uint8_t regAddress; | ||
| uint8_t length; | ||
| } RegBlock_t; | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #ifndef DPS310_CONFIG_H_ | ||
| #define DPS310_CONFIG_H_ | ||
|
|
||
| #define DPS310_NUM_OF_REGMASKS 16 | ||
|
|
||
| enum Interrupt_source_310_e | ||
| { | ||
| DPS310_NO_INTR = 0, | ||
| DPS310_PRS_INTR = 1, | ||
| DPS310_TEMP_INTR = 2, | ||
| DPS310_BOTH_INTR = 3, | ||
| DPS310_FIFO_FULL_INTR = 4, | ||
| }; | ||
|
|
||
| namespace dps310 | ||
| { | ||
|
|
||
| enum Registers_e | ||
| { | ||
| PROD_ID = 0, | ||
| REV_ID, | ||
| TEMP_SENSOR, // internal vs external | ||
| TEMP_SENSORREC, //temperature sensor recommendation | ||
| TEMP_SE, //temperature shift enable (if temp_osr>3) | ||
| PRS_SE, //pressure shift enable (if prs_osr>3) | ||
| FIFO_FL, //FIFO flush | ||
| FIFO_EMPTY, //FIFO empty | ||
| FIFO_FULL, //FIFO full | ||
| INT_HL, | ||
| INT_SEL, //interrupt select | ||
| }; | ||
|
|
||
| const RegMask_t registers[DPS310_NUM_OF_REGMASKS] = { | ||
| {0x0D, 0x0F, 0}, // PROD_ID | ||
| {0x0D, 0xF0, 4}, // REV_ID | ||
| {0x07, 0x80, 7}, // TEMP_SENSOR | ||
| {0x28, 0x80, 7}, // TEMP_SENSORREC | ||
| {0x09, 0x08, 3}, // TEMP_SE | ||
| {0x09, 0x04, 2}, // PRS_SE | ||
| {0x0C, 0x80, 7}, // FIFO_FL | ||
| {0x0B, 0x01, 0}, // FIFO_EMPTY | ||
| {0x0B, 0x02, 1}, // FIFO_FULL | ||
| {0x09, 0x80, 7}, // INT_HL | ||
| {0x09, 0x70, 4}, // INT_SEL | ||
| }; | ||
|
|
||
| const RegBlock_t coeffBlock = {0x10, 18}; | ||
| } // namespace dps310 | ||
| #endif | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No newline at EOF |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
|
|
||
| #ifndef DPS_CONSTS_H_ | ||
| #define DPS_CONSTS_H_ | ||
| #include "DpsRegister.h" | ||
|
|
||
| /////////// DPS310 /////////// | ||
| #define DPS310__PROD_ID 0x00 | ||
| #define DPS310__SPI_WRITE_CMD 0x00U | ||
| #define DPS310__SPI_READ_CMD 0x80U | ||
| #define DPS310__SPI_RW_MASK 0x80U | ||
| #define DPS310__SPI_MAX_FREQ 1000000U | ||
|
|
||
| #define DPS310__OSR_SE 3U | ||
|
|
||
| // DPS310 has 10 milliseconds of spare time for each synchronous measurement / per second for asynchronous measurements | ||
| // this is for error prevention on friday-afternoon-products :D | ||
| // you can set it to 0 if you dare, but there is no warranty that it will still work | ||
| #define DPS310__BUSYTIME_FAILSAFE 10U | ||
| #define DPS310__MAX_BUSYTIME ((1000U - DPS310__BUSYTIME_FAILSAFE) * DPS__BUSYTIME_SCALING) | ||
|
|
||
| #define DPS310__REG_ADR_SPI3W 0x09U | ||
| #define DPS310__REG_CONTENT_SPI3W 0x01U | ||
|
|
||
| /////////// DPS422 /////////// | ||
| #define DPS422__PROD_ID 0x0A | ||
|
|
||
| /////////// common /////////// | ||
|
|
||
| // slave address same for 422 and 310 (to be proved for future sensors) | ||
| #define DPS__FIFO_SIZE 32 | ||
| #define DPS__STD_SLAVE_ADDRESS 0x77U | ||
| #define DPS__RESULT_BLOCK_LENGTH 3 | ||
| #define NUM_OF_COMMON_REGMASKS 16 | ||
|
|
||
| #define DPS__MEASUREMENT_RATE_1 0 | ||
| #define DPS__MEASUREMENT_RATE_2 1 | ||
| #define DPS__MEASUREMENT_RATE_4 2 | ||
| #define DPS__MEASUREMENT_RATE_8 3 | ||
| #define DPS__MEASUREMENT_RATE_16 4 | ||
| #define DPS__MEASUREMENT_RATE_32 5 | ||
| #define DPS__MEASUREMENT_RATE_64 6 | ||
| #define DPS__MEASUREMENT_RATE_128 7 | ||
|
|
||
| #define DPS__OVERSAMPLING_RATE_1 DPS__MEASUREMENT_RATE_1 | ||
| #define DPS__OVERSAMPLING_RATE_2 DPS__MEASUREMENT_RATE_2 | ||
| #define DPS__OVERSAMPLING_RATE_4 DPS__MEASUREMENT_RATE_4 | ||
| #define DPS__OVERSAMPLING_RATE_8 DPS__MEASUREMENT_RATE_8 | ||
| #define DPS__OVERSAMPLING_RATE_16 DPS__MEASUREMENT_RATE_16 | ||
| #define DPS__OVERSAMPLING_RATE_32 DPS__MEASUREMENT_RATE_32 | ||
| #define DPS__OVERSAMPLING_RATE_64 DPS__MEASUREMENT_RATE_64 | ||
| #define DPS__OVERSAMPLING_RATE_128 DPS__MEASUREMENT_RATE_128 | ||
|
|
||
| //we use 0.1 ms units for time calculations, so 10 units are one millisecond | ||
| #define DPS__BUSYTIME_SCALING 10U | ||
|
|
||
| #define DPS__NUM_OF_SCAL_FACTS 8 | ||
|
|
||
| // status code | ||
| #define DPS__SUCCEEDED 0 | ||
| #define DPS__FAIL_UNKNOWN -1 | ||
| #define DPS__FAIL_INIT_FAILED -2 | ||
| #define DPS__FAIL_TOOBUSY -3 | ||
| #define DPS__FAIL_UNFINISHED -4 | ||
|
|
||
| namespace dps | ||
| { | ||
|
|
||
| /** | ||
| * @brief Operating mode. | ||
| * | ||
| */ | ||
| enum Mode | ||
| { | ||
| IDLE = 0x00, | ||
| CMD_PRS = 0x01, | ||
| CMD_TEMP = 0x02, | ||
| CMD_BOTH = 0x03, // only for DPS422 | ||
| CONT_PRS = 0x05, | ||
| CONT_TMP = 0x06, | ||
| CONT_BOTH = 0x07 | ||
| }; | ||
|
|
||
| enum RegisterBlocks_e | ||
| { | ||
| PRS = 0, // pressure value | ||
| TEMP, // temperature value | ||
| }; | ||
|
|
||
| const RegBlock_t registerBlocks[2] = { | ||
| {0x00, 3}, | ||
| {0x03, 3}, | ||
| }; | ||
|
|
||
| /** | ||
| * @brief registers for configuration and flags; these are the same for both 310 and 422, might need to be adapted for future sensors | ||
| * | ||
| */ | ||
| enum Config_Registers_e | ||
| { | ||
| TEMP_MR = 0, // temperature measure rate | ||
| TEMP_OSR, // temperature measurement resolution | ||
| PRS_MR, // pressure measure rate | ||
| PRS_OSR, // pressure measurement resolution | ||
| MSR_CTRL, // measurement control | ||
| FIFO_EN, | ||
|
|
||
| TEMP_RDY, | ||
| PRS_RDY, | ||
| INT_FLAG_FIFO, | ||
| INT_FLAG_TEMP, | ||
| INT_FLAG_PRS, | ||
| }; | ||
|
|
||
| const RegMask_t config_registers[NUM_OF_COMMON_REGMASKS] = { | ||
| {0x07, 0x70, 4}, // TEMP_MR | ||
| {0x07, 0x07, 0}, // TEMP_OSR | ||
| {0x06, 0x70, 4}, // PRS_MR | ||
| {0x06, 0x07, 0}, // PRS_OSR | ||
| {0x08, 0x07, 0}, // MSR_CTRL | ||
| {0x09, 0x02, 1}, // FIFO_EN | ||
|
|
||
| {0x08, 0x20, 5}, // TEMP_RDY | ||
| {0x08, 0x10, 4}, // PRS_RDY | ||
| {0x0A, 0x04, 2}, // INT_FLAG_FIFO | ||
| {0x0A, 0x02, 1}, // INT_FLAG_TEMP | ||
| {0x0A, 0x01, 0}, // INT_FLAG_PRS | ||
| }; | ||
|
|
||
| } // namespace dps | ||
| #endif /* DPS_CONSTS_H_ */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No newline at EOF |
||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No newline at EOF