Serial Wombat Arduino Library
|
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance. More...
#include <SerialWombat.h>
Public Member Functions | |
void | configureDigitalPin (uint8_t pin, uint8_t highLow) |
int16_t | initialize () |
void | readUniqueIdentifier () |
void | readDeviceIdentifier () |
uint16_t | returnErrorCode (uint8_t *rx) |
SerialWombatChip () | |
int16_t | begin (HardwareSerial &serial, bool reset=true) |
initialize a Serial Wombat chip to use a Serial Interface. More... | |
int16_t | begin (uint8_t i2cAddress) |
initialize a Serial Wombat chip to use the default Wire I2C Interface and specified address. More... | |
int16_t | begin (TwoWire &wire, uint8_t i2cAddress, bool reset=true) |
initialize a Serial Wombat chip to use a specified I2C Interface and address. More... | |
~SerialWombatChip () | |
int | sendPacket (uint8_t tx[], uint8_t rx[]) |
Send an 8 byte packet to the Serial Wombat chip and wait for 8 bytes back. More... | |
int | sendPacket (uint8_t tx[]) |
Send an 8 byte packet to the Serial Wombat chip. More... | |
int | sendPacket (uint8_t tx[], uint8_t rx[], bool retryIfEchoDoesntMatch, uint8_t beginningBytesToMatch=8, uint8_t endBytesToMatch=0) |
Send an 8 byte packet to the Serial Wombat chip and wait for 8 bytes back. More... | |
int | sendPacket (uint8_t tx[], bool retryIfEchoDoesntMatch) |
Send an 8 byte packet to the Serial Wombat chip. More... | |
int | sendPacketNoResponse (uint8_t tx[]) |
Send an 8 byte packet to the Serial Wombat chip, don't wait for a response. More... | |
char * | readVersion (void) |
Request version string (combined model and firmware) and return pointer to it. More... | |
uint32_t | readVersion_uint32 (void) |
Request version as a uint32. More... | |
uint16_t | readPublicData (uint8_t pin) |
Read the 16 Bit public data associated with a Serial Wombat Pin Mode. More... | |
uint16_t | readPublicData (SerialWombatDataSource dataSource) |
Read the 16 Bit public data associated with a Serial Wombat Pin Mode. More... | |
uint16_t | writePublicData (uint8_t pin, uint16_t value) |
Write a 16 bit value to a Serial Wombat pin Mode. More... | |
uint16_t | readSupplyVoltage_mV (void) |
Measure the Serial Wombat chip's Supply voltage. More... | |
int16_t | readTemperature_100thsDegC (void) |
Measure the Serial Wombat chip's internal temperature. More... | |
void | hardwareReset () |
Send a reset command to the Serial Wombat chip. More... | |
void | pinMode (uint8_t pin, uint8_t mode, bool pullDown=false, bool openDrain=false) |
Set a pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings. More... | |
void | digitalWrite (uint8_t pin, uint8_t val) |
Set an output pin High or Low. More... | |
int | digitalRead (uint8_t pin) |
Reads the state of a Pin. More... | |
int | analogRead (uint8_t pin) |
Configures pin as analog input and does an immediate A/D conversion. More... | |
void | analogWrite (uint8_t pin, int val) |
Set a pin to PWM output. More... | |
bool | queryVersion () |
Send a version request to the Serial Wombat chip. More... | |
uint32_t | readFramesExecuted () |
Get the number of 1mS frames that have been executed since Serial Wombat chip reset. More... | |
uint16_t | readOverflowFrames () |
Get the number of times an overflow Frame has occured. More... | |
void | jumpToBoot () |
Jump to Bootloader and wait for a UART download of new firmware. More... | |
uint8_t | readRamAddress (uint16_t address) |
Read Address from RAM based on 16 bit address. More... | |
int16_t | writeRamAddress (uint16_t address, uint8_t value) |
Write byte to Address in RAM based on 16 bit address. More... | |
uint32_t | readFlashAddress (uint32_t address) |
Read Address from Flash based on 32 bit address. More... | |
int16_t | readUserBuffer (uint16_t index, uint8_t *buffer, uint16_t count) |
Read data from the Serial Wombat 18AB's internal RAM buffer. More... | |
void | sleep () |
Shuts down most functions of the Serial Wombat chip reducing power consumption. More... | |
void | wake () |
Called to send a dummy packet to the Serial Wombat chip to wake it from sleep and ready it for other commands. More... | |
bool | isSW18 () |
Returns true if the instance received a model number corresponding to the Serial Wombat 18 series of chips at begin. More... | |
int16_t | eraseFlashPage (uint32_t address) |
Erases a page in flash. Intended for use with the Bootloader, not by end users outside of bootloading sketch. More... | |
int16_t | writeFlashRow (uint32_t address) |
Writes a row in flash. Intended for use with the Bootloader, not by end users outside of bootloading sketc. More... | |
int16_t | setThroughputPin (uint8_t pin) |
Set a pin to be a throughput monitoring pin. More... | |
int | writeUserBuffer (uint16_t index, uint8_t *buffer, uint16_t count) |
Write bytes to the User Memory Buffer in the Serial Wombat chip. More... | |
int | writeUserBuffer (uint16_t index, char *s) |
Write bytes to the User Memory Buffer in the Serial Wombat chip. More... | |
int | writeUserBuffer (uint16_t index, const char s[]) |
Write bytes to the User Memory Buffer in the Serial Wombat chip. More... | |
int16_t | writeFrameTimerPin (uint8_t pin) |
Set a pin to be a frame timer for system utilization (SW18AB Only) More... | |
int16_t | readLastErrorCommand (uint8_t *cmd) |
Returns the last Serial Wombat command that produced a protocol error. More... | |
void | registerErrorHandler (SerialWombatErrorHandler_t handler) |
Registers an error handler that is called by the SerialWombatChip sendPacket() command when a protocol error is returned by the Serial Wombat \handler A function pointer to a function of SerialWombatErrorHandler_t type. More... | |
int16_t | echo (uint8_t data[], uint8_t count=7) |
int16_t | echo (char *data) |
uint32_t | readBirthday () |
int16_t | readBrand (char *data) |
Static Public Member Functions | |
static uint8_t | find (bool keepTrying=false) |
Search the I2C Bus addresses 0x68 to 0x6F for I2C devices, and test to see if they respond to Serial Wombat version commands. Returns first address that responds properly or 0 if none found. More... | |
Public Attributes | |
uint16_t | _supplyVoltagemV = 0 |
uint8_t | model [4] = { 0 } |
Contains the last model retreived by queryVersion() as a zero-terminated string. More... | |
uint8_t | fwVersion [4] = { 0 } |
Contains the last firmware Version retreived by queryVersion() as a zero-terminated string. More... | |
uint8_t | uniqueIdentifier [16] |
uint8_t | uniqueIdentifierLength = 0 |
uint16_t | deviceIdentifier |
uint16_t | deviceRevision |
uint16_t | errorCount = 0 |
Incremented every time a communication or command error is detected. More... | |
bool | inBoot = false |
Set to true if boot mode is indicated by a version query. More... | |
int16_t | lastErrorCode = 0 |
The last error code returned as part of a protocol error message expressed as a positive integer. More... | |
uint32_t | sendReadyTime = 0 |
uint8_t | address = 0 |
The I2C address of the SerialWombatChip instance. More... | |
uint8_t | communicationErrorRetries = 5 |
How many times to retry a packet if communcation bus (such as I2C) error. More... | |
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
This class describes the capabilties of a Serial Wombat Chip that are not Pin Mode functionalities
SerialWombatChip::SerialWombatChip | ( | ) |
SerialWombatChip::~SerialWombatChip | ( | ) |
|
inline |
Configures pin as analog input and does an immediate A/D conversion.
This function is compatible with the Arduino Uno analogRead function.
It does not make use of advanced Serial Wombat chip's functionality such as averaging and filtering. Consider declaring a SerialWombatAnalogInput instead.
pin | The Serial Wombat pin to set. Valid values for SW4A: 0-3 SW4B: 1-3 |
|
inline |
Set a pin to PWM output.
This function is compatible with the Arduino Uno analogWrite function, but will output a PWM with a different frequency. Consider declaring a SerialWombatPWM instead. It has higher resolution and the ability to choose frequency.
pin | The Serial Wombat pin to set. Valid values for SW4A: 0-3 SW4B: 1-3 |
val | A value from 0 (always low) to 255(always high) for the PWM duty cycle |
|
inline |
initialize a Serial Wombat chip to use a Serial Interface.
The reset parameter determines if the Serial Wombat chip is reset prior to other initialization operations. If false, then any prior pin modes and configurations may still be in place. The Serial Wombat chips's source voltage is then read as well as its version.
serial | Serial Interface to be used by the Serial Wombat library |
reset | Whether or not to reset the Serial Wombat chip via command as the first initialization operation |
|
inline |
initialize a Serial Wombat chip to use a specified I2C Interface and address.
This call causes the Serial Wombat chip to optionally reset through its reset command as the first operation. The Serial Wombat chip's source voltage is then read as well as its version.
wire | I2C interface to be used by the Serial Wombat Library |
i2cAddress | I2C Follower address of the Serial Wombat chip commanded by this instance |
reset | Whether or not to reset the Serial Wombat chip via command as the first initialization operation. If false, then any prior pin modes and configurations may still be in place. |
int16_t SerialWombatChip::begin | ( | uint8_t | i2cAddress | ) |
initialize a Serial Wombat chip to use the default Wire I2C Interface and specified address.
This call causes the Serial Wombat chip to be reset through its reset command as the first operation. The Serial Wombat chip's source voltage is then read as well as its version.
i2cAddress | I2C Follower address of the Serial Wombat chip commanded by this instance |
|
inline |
|
inline |
Reads the state of a Pin.
|
inline |
Set an output pin High or Low.
Before calling this function, the pin should be configured as an input or output with pinMode()
pin | The Serial Wombat pin to set. Valid values for SW4A: 0-3 SW4B: 1-3 |
val | Valid values are HIGH or LOW not use SW_INPUT, SW_HIGH or SW_LOW here, as these have different meanings |
|
inline |
|
inline |
|
inline |
Erases a page in flash. Intended for use with the Bootloader, not by end users outside of bootloading sketch.
|
inlinestatic |
Search the I2C Bus addresses 0x68 to 0x6F for I2C devices, and test to see if they respond to Serial Wombat version commands. Returns first address that responds properly or 0 if none found.
keepTrying | if True, go into a loop and do not exit until a Serial Wombat Chip is found |
|
inline |
Send a reset command to the Serial Wombat chip.
Sends a reset command to the Serial Wombat chip. The calling function should wait 500mS before sending additional commands.
|
inline |
|
inline |
Returns true if the instance received a model number corresponding to the Serial Wombat 18 series of chips at begin.
|
inline |
Jump to Bootloader and wait for a UART download of new firmware.
This function causes a reset of the Serial Wombat chip and causes it to remain in the bootloader until a power-cycle occurs. This allows loading new firmware via a UART connection to the bottom two pins (DIP pins 4 (RX) and 5(TX)) on the SW4A/SW4B. When jumping to boot the TX pin will go high. All other communication or functional pins will become inputs (i.e. PWMS, etc will stop).
|
inline |
Set a pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings.
pin | The Serial Wombat pin to set |
mode | Valid values are INPUT, OUTPUT or INPUT_PULLUP as defined by arduino. Do not use SW_INPUT, SW_HIGH or SW_LOW here, as these have different meanings |
pullDown | If True, a weak pull down will be enabled on this pin (No effect on SW4A/SW4B) |
openDrain | If True, output becomes openDrain output rather than push / pull |
|
inline |
Send a version request to the Serial Wombat chip.
This function queries the Serial Wombat chip for its model and version and stores the result in the public members model and fwVersion as zero terminated strings. Returns true if the response is likely a proper version response and false otherwise.
|
inline |
|
inline |
|
inline |
|
inline |
Read Address from Flash based on 32 bit address.
Most Arduino users should not need this command.
This command can be used to read flash locations within the Serial Wombat Chip
Addresses are not validated to be available in a given chip's address range.
address | A 32-bit address pointing to a location in the Serial Wombat Chip's memory map |
|
inline |
Get the number of 1mS frames that have been executed since Serial Wombat chip reset.
This value should be roughly equal to the mS since reset. It will vary based on the Serial Wombat chip's internal oscillator variation, and may run slow if Overflow frames are occuring.
|
inline |
Returns the last Serial Wombat command that produced a protocol error.
cmd | pointer to a uint8_t [8] array into which the error command will be copied |
|
inline |
Get the number of times an overflow Frame has occured.
This value increments each time the Serial Wombat firmware determines it is time to start a new 1 mS frame, but the previous frame is still executing. Indicates processor loading over 100% of real-time. Overflows back to 0 when incremented from 65535.
|
inline |
Read the 16 Bit public data associated with a Serial Wombat Pin Mode.
Reads and returns the 16 bit value associated with a Serial Wombat Pin Mode. Additionally, values of 65 and higher have special meanings. See Serial Wombat firmware documentation for details.
dataSource | The pin (or special meaning value) for which to retreive data |
|
inline |
Read the 16 Bit public data associated with a Serial Wombat Pin Mode.
Reads and returns the 16 bit value associated with a Serial Wombat Pin Mode. Additionally, values of 65 and higher have special meanings. See Serial Wombat firmware documentation for details.
pin | The pin (or special meaning value) for which to retreive data |
|
inline |
Read Address from RAM based on 16 bit address.
Most Arduino users should not need this command.
This command can be used to read variables and registers within the Serial Wombat Chip Note that reading registers may have unintended side effects. See the microcontroller datasheet for details.
Note that Note that the PIC16F15214 used in the SW4A and SW4B chips is a Microchip Enhanced Mid-Range chip with both a banked RAM area and a Linear RAM area at an offset address. See the datasheet for details. It's wierd to people who are unfamilliar with it. The same location can have two different addresses.
Addresses are not validated to be available in a given chip's address range.
address | A 16-bit address pointing to a location in the Serial Wombat Chip's memory map |
|
inline |
Measure the Serial Wombat chip's Supply voltage.
Causes the Serial Wombat chip to measure the counts for the internal reference voltage. The Arduino library then converts these counts to a Source votlage in mV
|
inline |
Measure the Serial Wombat chip's internal temperature.
This command is only supported by the SerialWombat 18 Series. The Arduino library will return 25 deg. C for other models
This value is low accuracy unless a calibration has been performed
|
inline |
|
inline |
Read data from the Serial Wombat 18AB's internal RAM buffer.
index | A 16-bit index into the Serial Wombat Chip's User RAM Buffer |
buffer | a pointer to an array into which bytes will be written |
count | Number of bytes to read |
|
inline |
Request version string (combined model and firmware) and return pointer to it.
This queries the Serial Wombat chip for the 7 characters: product line (1 character) Model (3 characters) and firmware version (3 characters) This is stored in a string in the Serial Wombat object. A pointer to this string is returned.
|
inline |
Request version as a uint32.
This queries the Serial Wombat chip for its version information, and returns the firmware version as a uint32 0x0XYZ where X,Y,and Z represent firmwre version X.Y.Z
|
inline |
Registers an error handler that is called by the SerialWombatChip sendPacket() command when a protocol error is returned by the Serial Wombat \handler A function pointer to a function of SerialWombatErrorHandler_t type.
|
inline |
int SerialWombatChip::sendPacket | ( | uint8_t | tx[] | ) |
Send an 8 byte packet to the Serial Wombat chip.
This method sends 8 bytes and processes the response to check for errors.
tx | address of an array of 8 bytes to send |
int SerialWombatChip::sendPacket | ( | uint8_t | tx[], |
bool | retryIfEchoDoesntMatch | ||
) |
Send an 8 byte packet to the Serial Wombat chip.
This method sends 8 bytes and processes the response to check for errors.
tx | address of an array of 8 bytes to send |
int SerialWombatChip::sendPacket | ( | uint8_t | tx[], |
uint8_t | rx[] | ||
) |
Send an 8 byte packet to the Serial Wombat chip and wait for 8 bytes back.
This method sends 8 bytes via I2C or Serial and blocks until 8 bytes are receieved back
tx | address of an array of 8 bytes to send |
rx | address of an array of 8 bytes into which to put response. |
int SerialWombatChip::sendPacket | ( | uint8_t | tx[], |
uint8_t | rx[], | ||
bool | retryIfEchoDoesntMatch, | ||
uint8_t | beginningBytesToMatch = 8 , |
||
uint8_t | endBytesToMatch = 0 |
||
) |
Send an 8 byte packet to the Serial Wombat chip and wait for 8 bytes back.
This method sends 8 bytes via I2C or Serial and blocks until 8 bytes are receieved back
tx | address of an array of 8 bytes to send |
rx | address of an array of 8 bytes into which to put response. |
int SerialWombatChip::sendPacketNoResponse | ( | uint8_t | tx[] | ) |
Send an 8 byte packet to the Serial Wombat chip, don't wait for a response.
This method sends 8 bytes. Used for resetting the chip prior to bootloading
tx | address of an array of 8 bytes to send |
|
inline |
Set a pin to be a throughput monitoring pin.
This pin goes high when pin processing begins in each 1mS frame, and goes low after pin processing is complete. This allows the CPU utilization of the Serial Wombat chip to be measured using a logic analyzer. This function can only be applied to one pin, and is only disabled by resetting the chip. This function is supported on the SW18AB chip. It is not supported on the SW4 series of chips.
|
inline |
Shuts down most functions of the Serial Wombat chip reducing power consumption.
This command stops the Serial Wombat chip's internal clock, greatly reducing power consumption. The host is responsible for configuring outputs to a safe state prior to calling sleep.
|
inline |
Called to send a dummy packet to the Serial Wombat chip to wake it from sleep and ready it for other commands.
|
inline |
Writes a row in flash. Intended for use with the Bootloader, not by end users outside of bootloading sketc.
|
inline |
Set a pin to be a frame timer for system utilization (SW18AB Only)
This command configures a Serial Wombat 18AB Pin to be a frame timer. This frame goes high at the beginning of pin processing, and low after all pins have been serviced. The duty cycle of this pin is an indicator of the Serial Wombat Chip's CPU utilization. This pin has a frequency of 1kHz corresponding to the 1000 frames per second executive. Most multimeters will filter this pin to a voltage, so the CPU utilization can be seen as a fraction of the system voltage. Only one pin can be the Frame Timer pin at a time.
|
inline |
Write a 16 bit value to a Serial Wombat pin Mode.
pin | The pin number to which to write |
value | The 16 bit value to write |
|
inline |
Write byte to Address in RAM based on 16 bit address.
Most Arduino users should not need this command.
This command can be used to write variables and registers within the Serial Wombat Chip Note that write registers may have unintended side effects. See the microcontroller datasheet for details.
Note that Note that the PIC16F15214 used in the SW4A and SW4B chips is a Microchip Enhanced Mid-Range chip with both a banked RAM area and a Linear RAM area at an offset address. See the datasheet for details. It's wierd to people who are unfamilliar with it. The same location can have two different addresses.
Addresses are not validated to be available in a given chip's address range.
address | A 16-bit address pointing to a location in the Serial Wombat Chip's memory map |
value | An 8 bit value to be written to RAM |
|
inline |
Write bytes to the User Memory Buffer in the Serial Wombat chip.
index | The index into the User Buffer array of bytes where the data should be loaded |
buffer | a pointer to an array of bytes to be loaded into the User Buffer array |
s | string to convert to Ascii bytes and load |
|
inline |
Write bytes to the User Memory Buffer in the Serial Wombat chip.
index | The index into the User Buffer array of bytes where the data should be loaded |
buffer | a pointer to an array of bytes to be loaded into the User Buffer array |
s | string to convert to Ascii bytes and load |
|
inline |
Write bytes to the User Memory Buffer in the Serial Wombat chip.
index | The index into the User Buffer array of bytes where the data should be loaded |
buffer | a pointer to an array of bytes to be loaded into the User Buffer array |
number | of bytes to load |
uint16_t SerialWombatChip::_supplyVoltagemV = 0 |
Stores the last value retreived by readSupplyVoltage_mV(). Used by SerialWombatAnalogInput class to calculate mV outputs from retreived A/D counts. Don't access this member, as it may become private and SerialWombatAnalog input be made a friend of SerialWombat in the future. Call readSupplyVoltage_mV instead.
uint8_t SerialWombatChip::address = 0 |
The I2C address of the SerialWombatChip instance.
uint8_t SerialWombatChip::communicationErrorRetries = 5 |
How many times to retry a packet if communcation bus (such as I2C) error.
uint16_t SerialWombatChip::deviceIdentifier |
Contains a Microchip device identifier for Microchip based Serial Wombat Models. Call queryVersion() to populate this value.
uint16_t SerialWombatChip::deviceRevision |
Contains a Microchip device revision for Microchip based Serial Wombat Models. Call queryVersion() to populate this value.
uint16_t SerialWombatChip::errorCount = 0 |
Incremented every time a communication or command error is detected.
uint8_t SerialWombatChip::fwVersion[4] = { 0 } |
Contains the last firmware Version retreived by queryVersion() as a zero-terminated string.
bool SerialWombatChip::inBoot = false |
Set to true if boot mode is indicated by a version query.
int16_t SerialWombatChip::lastErrorCode = 0 |
The last error code returned as part of a protocol error message expressed as a positive integer.
uint8_t SerialWombatChip::model[4] = { 0 } |
Contains the last model retreived by queryVersion() as a zero-terminated string.
uint32_t SerialWombatChip::sendReadyTime = 0 |
uint8_t SerialWombatChip::uniqueIdentifier[16] |
Contains the unique identifier stored in microcontroller at its manufacturing.
Length and format vary by model. uniqueIdentifier holds the length in bytes.
Call queryVersion() to populate this value.
uint8_t SerialWombatChip::uniqueIdentifierLength = 0 |
Contains the unique identifier length in bytes. This value varies by model. Call queryVersion() to populate this value.