SparkFun_smol_Power_Board_Arduino_Library
|
#include <SparkFun_smol_Power_Board.h>
Public Member Functions | |
bool | isConnected () |
Class to communicate with the SparkFun smôl Power Boards. More... | |
bool | setI2CAddress (byte address) |
Change the smôl Power Board AAA's I2C address. You will need to call .begin again using the new address to re-establish communication with the Power Board. More... | |
byte | getI2CAddress () |
Just for fun, read back the Power Board's I2C address. This proves that I2C communication is possible and that the Power Board has the correct address stored in eeprom. More... | |
byte | getResetReason () |
Read the reason for the ATtiny's most recent reset. More... | |
float | getTemperature () |
Read the ATtiny's internal temperature. TO DO: Add temperature calibration / correction functionality. More... | |
float | measureVCC () |
Measure the ATtiny43U's VCC by reading the 1.1V internal reference via the ADC. More... | |
bool | setADCVoltageReference (sfe_power_board_ADC_ref_e ref) |
Set the ATtiny43U's ADC voltage reference to VCC or the internal 1.1V reference. More... | |
sfe_power_board_ADC_ref_e | getADCVoltageReference () |
Get the ATtiny43U's ADC voltage reference: VCC or the internal 1.1V reference. More... | |
bool | setWatchdogTimerPrescaler (sfe_power_board_WDT_prescale_e prescaler) |
Set the ATtiny43U's Watchdog Timer prescaler to set the WDT interrupt rate. More... | |
sfe_power_board_WDT_prescale_e | getWatchdogTimerPrescaler () |
Get the ATtiny43U's Watchdog Timer prescaler setting. More... | |
bool | setPowerdownDurationWDTInts (uint16_t duration) |
Set the Power Board Power-down duration in Watchdog Timer interrupts. More... | |
bool | getPowerDownDurationWDTInts (uint16_t *duration) |
Get the Power Board Power-down duration in Watchdog Timer interrupts. More... | |
bool | powerDownNow () |
Power down the system now. The smôl bus power will be disabled. The ATtiny43U will wake up and turn the power back on after SFE_SMOL_POWER_REGISTER_POWERDOWN_DURATION WDT interrupts. More... | |
byte | getFirmwareVersion () |
Get the Power Board firmware version. More... | |
byte | computeCRC8 (byte data[], byte len) |
Given an array of bytes, this calculates the CRC8 for those bytes. From: http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html Tested with: http://www.sunshine2k.de/coding/javascript/crc/crc_js.html x^8+x^5+x^4+1 = 0x31. More... | |
Public Attributes | |
SMOL_POWER_BOARD_IO | smolPowerBoard_io |
Communication interface for the SparkFun smôl Power Boards
byte sfeSmolPowerBoard::computeCRC8 | ( | byte | data[], |
byte | len | ||
) |
Given an array of bytes, this calculates the CRC8 for those bytes. From: http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html Tested with: http://www.sunshine2k.de/coding/javascript/crc/crc_js.html x^8+x^5+x^4+1 = 0x31.
data | The array of bytes |
len | The length of the array of bytes |
sfe_power_board_ADC_ref_e sfeSmolPowerBoard::getADCVoltageReference | ( | ) |
Get the ATtiny43U's ADC voltage reference: VCC or the internal 1.1V reference.
byte sfeSmolPowerBoard::getFirmwareVersion | ( | ) |
Get the Power Board firmware version.
byte sfeSmolPowerBoard::getI2CAddress | ( | ) |
Just for fun, read back the Power Board's I2C address. This proves that I2C communication is possible and that the Power Board has the correct address stored in eeprom.
bool sfeSmolPowerBoard::getPowerDownDurationWDTInts | ( | uint16_t * | duration | ) |
Get the Power Board Power-down duration in Watchdog Timer interrupts.
duration | Pointer for the power-down duration. |
byte sfeSmolPowerBoard::getResetReason | ( | ) |
Read the reason for the ATtiny's most recent reset.
The reset reason is updated as soon as the ATtiny43U starts. The four MCU STatus Register Flags are read. If the ATtiny43U found that its eeprom was corrupt when the code started, SFE_SMOL_POWER_EEPROM_CORRUPT_ON_RESET will be set indicating that the eeprom settings have been reset to the default values.
float sfeSmolPowerBoard::getTemperature | ( | ) |
Read the ATtiny's internal temperature.
TO DO: Add temperature calibration / correction functionality.
To read the approximate temperature, we need to read two bytes (uint16_t, little endian) from SFE_SMOL_POWER_REGISTER_TEMPERATURE. These will be the raw ADC reading which we need to convert to Degrees C. The ATtiny43U will use the 1.1V internal reference for the conversion. There is no need to select it here. The sensitivity is approximately 1 LSB/°C with 25°C reading as 300 ADU.
sfe_power_board_WDT_prescale_e sfeSmolPowerBoard::getWatchdogTimerPrescaler | ( | ) |
Get the ATtiny43U's Watchdog Timer prescaler setting.
bool sfeSmolPowerBoard::isConnected | ( | ) |
Class to communicate with the SparkFun smôl Power Boards.
Check that the SparkFun smôl Power Board AAA is awake and communicating. This function is called by smolPowerAAA::begin.
float sfeSmolPowerBoard::measureVCC | ( | ) |
Measure the ATtiny43U's VCC by reading the 1.1V internal reference via the ADC.
By reading the 1.1V internal reference we can work out what VCC is. We need to read two bytes (uint16_t, little endian) from SFE_SMOL_POWER_REGISTER_VBAT. This will be the raw 10-bit ADC reading. We need to manually convert this to voltage. The ATtiny43U will automatically select VCC as the reference. There is no need to select it here.
bool sfeSmolPowerBoard::powerDownNow | ( | ) |
Power down the system now. The smôl bus power will be disabled. The ATtiny43U will wake up and turn the power back on after SFE_SMOL_POWER_REGISTER_POWERDOWN_DURATION WDT interrupts.
To power-down, we need to write six bytes to the SFE_SMOL_POWER_REGISTER_POWERDOWN_NOW register. The first five are the ASCII characters SLEEP. The sixth is a one byte CRC of the characters.
bool sfeSmolPowerBoard::setADCVoltageReference | ( | sfe_power_board_ADC_ref_e | ref | ) |
Set the ATtiny43U's ADC voltage reference to VCC or the internal 1.1V reference.
ref | The reference: SFE_SMOL_POWER_USE_ADC_REF_VCC or SFE_SMOL_POWER_USE_ADC_REF_1V1 |
To change the voltage reference, we need to write two bytes to SFE_SMOL_POWER_REGISTER_ADC_REFERENCE The first is the new address. The second is a one byte CRC of the address.
bool sfeSmolPowerBoard::setI2CAddress | ( | byte | address | ) |
Change the smôl Power Board AAA's I2C address. You will need to call .begin again using the new address to re-establish communication with the Power Board.
address | The new I2C address. |
To change the address, we need to write two bytes to SFE_POWER_BOARD_REGISTER_I2C_ADDRESS. The first is the new address. The second is a one byte CRC of the address.
bool sfeSmolPowerBoard::setPowerdownDurationWDTInts | ( | uint16_t | duration | ) |
Set the Power Board Power-down duration in Watchdog Timer interrupts.
duration | The power-down duration. |
To change the power-down duration, we need to write three bytes to the SFE_SMOL_POWER_REGISTER_POWERDOWN_DURATION register. The first two are the duration in uint16_t little endian format. The third is a one byte CRC of the duration.
bool sfeSmolPowerBoard::setWatchdogTimerPrescaler | ( | sfe_power_board_WDT_prescale_e | prescaler | ) |
Set the ATtiny43U's Watchdog Timer prescaler to set the WDT interrupt rate.
prescaler | The prescaler. |
To change the prescaler, we need to write two bytes to SFE_SMOL_POWER_REGISTER_WDT_PRESCALER The first is the new prescaler. The second is a one byte CRC of the address.