-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from asterics/RP2040
FLipMouse3
- Loading branch information
Showing
139 changed files
with
385,029 additions
and
232,990 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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,137 @@ | ||
/* | ||
FLipWare - AsTeRICS Foundation | ||
For more info please visit: https://www.asterics-foundation.org | ||
|
||
Module: NAU7802.h - register definitions for the NAU7802 sensor chip | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; See the GNU General Public License: | ||
http://www.gnu.org/licenses/gpl-3.0.en.html | ||
|
||
*/ | ||
|
||
#ifndef _NAU7802_H_ | ||
#define _NAU7802_H_ | ||
|
||
/** fwd declarations */ | ||
static inline uint8_t readNAURegister(uint8_t reg_addr); | ||
static inline uint32_t readNAUADC(); | ||
static inline void writeNAURegister(uint8_t reg_addr, uint8_t val); | ||
|
||
static inline uint8_t readNAURegister(uint8_t reg_addr) | ||
{ | ||
Wire.beginTransmission(i2c_addr); | ||
Wire.write(reg_addr); | ||
Wire.requestFrom(i2c_addr,1); | ||
Wire.endTransmission(); | ||
delayMicroseconds(100); | ||
return Wire.read(); | ||
} | ||
|
||
static inline uint32_t readNAUADC() | ||
{ | ||
Wire.beginTransmission(i2c_addr); | ||
Wire.write(NAU7802_OUTPUT); | ||
Wire.requestFrom(i2c_addr,3); | ||
Wire.endTransmission(); | ||
delayMicroseconds(100); | ||
uint32_t val = Wire.read(); | ||
val |= Wire.read() << 8; | ||
val |= Wire.read() << 16; | ||
return val; | ||
} | ||
|
||
static inline void writeNAURegister(uint8_t reg_addr, uint8_t val) | ||
{ | ||
Wire.beginTransmission(i2c_addr); | ||
Wire.write(reg_addr); | ||
Wire.write(val); | ||
Wire.endTransmission(); | ||
} | ||
|
||
//NAU7802 startup sequence | ||
writeNAURegister(NAU7802_PU_CTRL,1); //set register reset | ||
delay(10); | ||
writeNAURegister(NAU7802_PU_CTRL,0); //clear register reset | ||
delayMicroseconds(200); //wait, then check the pwr up bit | ||
for(uint8_t i = 0; i<4; i++) { //do 4 retries | ||
if(readNAURegister(NAU7802_PU_CTRL) & (1<<3)) | ||
{ | ||
#ifdef DEBUG_OUTPUT_SENSORS | ||
Serial.println("SEN: NAU7802 powered up"); | ||
#endif | ||
break; | ||
} | ||
delay(10); | ||
if(i == 3) { | ||
Serial.println("SEN: error, NAU7802 not powering up!"); | ||
return; | ||
} | ||
} | ||
|
||
//enable digital | ||
writeNAURegister(NAU7802_PU_CTRL, (1<<1)); | ||
//enable analog + digital | ||
writeNAURegister(NAU7802_PU_CTRL, (1<<2)|(1<<1)); | ||
//wait | ||
delay(600); | ||
//setup LDO / gain | ||
writeNAURegister(NAU7802_CTRL1, NAU7802_LDO_30 | NAU7802_PGA_128); | ||
//set sampling rate to 320SPS. | ||
writeNAURegister(NAU7802_CTRL2, NAU7802_SPS_320); | ||
|
||
|
||
/** | ||
* @brief I2C address of the NAU7802 | ||
*/ | ||
#define NAU7802_ADDR 0b00101010 | ||
|
||
/** Power control */ | ||
#define NAU7802_PU_CTRL 0x00 | ||
/** Config/Ctrl 1 */ | ||
#define NAU7802_CTRL1 0x01 | ||
/** Config/Ctrl 2 */ | ||
#define NAU7802_CTRL2 0x02 | ||
|
||
/** 0x03-0x05: channel 1 offset calib */ | ||
/** 0x06-0x09: channel 1 gain ctrl */ | ||
/** 0x0A-0x0C: channel 2 offset calib */ | ||
/** 0x0D-0x10: channel 2 gain ctrl */ | ||
|
||
/** I2C ctrl */ | ||
#define NAU7802_I2CCTRL 0x11 | ||
/** ADC output LSB / starting address */ | ||
#define NAU7802_OUTPUT 0x12 | ||
/** ADC ctrl */ | ||
#define NAU7802_ADCCTRL 0x15 | ||
/** PGA ctrl */ | ||
#define NAU7802_PGACTRL 0x1B | ||
/** Power ctrl */ | ||
#define NAU7802_POWER 0x1C | ||
/** Revision ID */ | ||
#define NAU7802_ID 0x1F | ||
|
||
/***** LDO settings *****/ | ||
#define NAU7802_LDO_33 ((0b100)<<3) | ||
#define NAU7802_LDO_30 ((0b101)<<3) | ||
#define NAU7802_LDO_27 ((0b110)<<3) | ||
#define NAU7802_LDO_24 ((0b111)<<3) | ||
|
||
/***** gain settings *****/ | ||
#define NAU7802_PGA_128 0b111 | ||
#define NAU7802_PGA_64 0b110 | ||
#define NAU7802_PGA_32 0b101 | ||
#define NAU7802_PGA_16 0b100 | ||
#define NAU7802_PGA_8 0b011 | ||
#define NAU7802_PGA_4 0b010 | ||
#define NAU7802_PGA_2 0b001 | ||
#define NAU7802_PGA_1 0b000 | ||
|
||
/***** sampling rate *****/ | ||
#define NAU7802_SPS_320 ((0b111)<<4) | ||
#define NAU7802_SPS_80 ((0b011)<<4) | ||
#define NAU7802_SPS_40 ((0b010)<<4) | ||
#define NAU7802_SPS_20 ((0b001)<<4) | ||
#define NAU7802_SPS_10 ((0b000)<<4) | ||
|
||
#endif /*_NAU7802_H_*/ |
Oops, something went wrong.