SparkFun_smol_Power_Board_Arduino_Library
Public Member Functions | Public Attributes | List of all members
sfeSmolPowerBoard Class Reference

#include <SparkFun_smol_Power_Board.h>

Inheritance diagram for sfeSmolPowerBoard:
smolPowerAAA smolPowerLiPo

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
 

Detailed Description

Communication interface for the SparkFun smôl Power Boards

Member Function Documentation

◆ computeCRC8()

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.

Parameters
dataThe array of bytes
lenThe length of the array of bytes
Returns
The CRC

◆ getADCVoltageReference()

sfe_power_board_ADC_ref_e sfeSmolPowerBoard::getADCVoltageReference ( )

Get the ATtiny43U's ADC voltage reference: VCC or the internal 1.1V reference.

Returns
SFE_SMOL_POWER_USE_ADC_REF_VCC or SFE_SMOL_POWER_USE_ADC_REF_1V1 if the reference was read successfuly, SFE_SMOL_POWER_USE_ADC_REF_UNDEFINED if not.

◆ getFirmwareVersion()

byte sfeSmolPowerBoard::getFirmwareVersion ( )

Get the Power Board firmware version.

Returns
The firmware version if read successfully, 0x00 if not. The firmware version is: Major Version (4-bits << 4) | Minor Version (4-bits). E.g. 0x10 is: v1.0, Major Version 1, Minor Version 0.

◆ getI2CAddress()

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.

Returns
The Power Board's I2C address. Returns zero if an error occurred.

◆ getPowerDownDurationWDTInts()

bool sfeSmolPowerBoard::getPowerDownDurationWDTInts ( uint16_t *  duration)

Get the Power Board Power-down duration in Watchdog Timer interrupts.

Parameters
durationPointer for the power-down duration.
Returns
True if the duration was read successfully, false if not.

◆ getResetReason()

byte sfeSmolPowerBoard::getResetReason ( )

Read the reason for the ATtiny's most recent reset.

Returns
The reset reason: the logical OR of:
SFE_SMOL_POWER_RESET_REASON_PORF
SFE_SMOL_POWER_RESET_REASON_EXTRF
SFE_SMOL_POWER_RESET_REASON_BORF
SFE_SMOL_POWER_RESET_REASON_WDRF
SFE_SMOL_POWER_EEPROM_CORRUPT_ON_RESET
SFE_SMOL_POWER_COMM_ERROR

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.

◆ getTemperature()

float sfeSmolPowerBoard::getTemperature ( )

Read the ATtiny's internal temperature.
TO DO: Add temperature calibration / correction functionality.

Returns
The temperature in Degrees Centigrade / Celcius or -273.15 if an error occured.

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.

◆ getWatchdogTimerPrescaler()

sfe_power_board_WDT_prescale_e sfeSmolPowerBoard::getWatchdogTimerPrescaler ( )

Get the ATtiny43U's Watchdog Timer prescaler setting.

Returns
The appropriate SFE_SMOL_POWER_WDT_PRESCALE_ or SFE_SMOL_POWER_WDT_PRESCALE_UNDEFINED if communication failed.

◆ isConnected()

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.

Returns
True if communication with the Power Board was successful, otherwise false.

◆ measureVCC()

float sfeSmolPowerBoard::measureVCC ( )

Measure the ATtiny43U's VCC by reading the 1.1V internal reference via the ADC.

Returns
The battery voltage in Volts or -99.0 if an error occurred.

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.

◆ powerDownNow()

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.

Returns
True if communication with the ATtiny43U was successful, false if not.

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.

◆ setADCVoltageReference()

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.

Parameters
refThe reference: SFE_SMOL_POWER_USE_ADC_REF_VCC or SFE_SMOL_POWER_USE_ADC_REF_1V1
Returns
True if the reference is set successfuly, false if not.

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.

◆ setI2CAddress()

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.

Parameters
addressThe new I2C address.
Returns
True if communication with the Power Board was successful, otherwise false.

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.

◆ setPowerdownDurationWDTInts()

bool sfeSmolPowerBoard::setPowerdownDurationWDTInts ( uint16_t  duration)

Set the Power Board Power-down duration in Watchdog Timer interrupts.

Parameters
durationThe power-down duration.
Returns
True if the duration is set successfuly, false if not.

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.

◆ setWatchdogTimerPrescaler()

bool sfeSmolPowerBoard::setWatchdogTimerPrescaler ( sfe_power_board_WDT_prescale_e  prescaler)

Set the ATtiny43U's Watchdog Timer prescaler to set the WDT interrupt rate.

Parameters
prescalerThe prescaler.
Returns
True if the prescaler is set successfuly, false if not.

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.


The documentation for this class was generated from the following files: