AccelStepperI2C
v 0.1
I2C wrapper (and a bit more) for the AccelStepper Arduino library
|
Go to the documentation of this file.
20 address = i2c_address;
26 void I2Cwrapper::doDelay()
28 uint32_t
now = millis();
29 delay(max(0, I2Cdelay - int16_t(
now - lastI2Ctransmission)));
30 lastI2Ctransmission =
now;
39 log(
" Sending command #");
log(cmd);
40 log(
" to unit #");
log(int8_t(unit));
50 Wire.beginTransmission(address);
55 for (uint8_t d = 3; d <
buf.
idx; d++) {
60 sentOK = (Wire.endTransmission() == 0);
76 if (Wire.requestFrom(address, uint8_t(numBytes + 1)) > 0) {
77 log(
" Requesting result (");
79 log(
" bytes incl. CRC8): ");
81 while ((i <= numBytes) and (i <
buf.
maxLen)) {
88 log((i <= numBytes) ?
" -- buffer out of space! " :
"");
89 log(
" total bytes = ");
104 Wire.beginTransmission(address);
105 return Wire.endTransmission() == 0;
123 int16_t d = I2Cdelay;
150 uint32_t res = 0xffffffff;
164 uint16_t se = sentErrorsCount;
171 uint16_t re = resultErrorsCount;
172 resultErrorsCount = 0;
void setCRC8()
Calculate CRC8 checksum for the currently used buffer ([1]...[idx-1]) and store it in the first byte ...
bool resultOK
True if return value from previous function call was received successfully.
void prepareCommand(uint8_t cmd, uint8_t unit=-1)
bool sentOK
True if previous function call was successfully transferred to slave.
I2Cwrapper(uint8_t i2c_address, uint8_t maxBuf=maxBufDefault)
Constructor.
bool checkCRC8()
Check for correct CRC8 checksum. First byte [0] holds the checksum, rest of the currently used buffer...
uint8_t clearInterrupt()
Acknowledge a received interrupt to slave so that it can clear the interupt condition and return the ...
uint16_t resultErrors()
Return and reset the number of failed receive events since the last time this method was used....
void read(T &value)
Read any basic data type from the buffer from the current position and increment the position pointer...
const uint8_t changeI2CaddressCmd
uint16_t transmissionErrors()
Return and reset the sum of failed commands sent and failed receive events since the last time this m...
const uint8_t setInterruptPinCmd
uint8_t idx
The position pointer. Remember, [0] holds the CRC8 checksum, so for an empty buffer,...
A helper class for the AccelStepperI2C (and ServoI2C) library.
bool readResult(uint8_t numBytes)
void init(uint8_t buflen)
Allocate and reset buffer.
void reset()
Reset the position pointer to the start of the buffer (which is[1] as [0] is the CRC8 chcksum) withou...
uint16_t sentErrors()
Return and reset the number of failed commands sent since the last time this method was used....
uint8_t maxLen
Maximum length of buffer in bytes. Read and write operations use this to check for sufficient space (...
bool ping()
Test if slave is listening.
uint32_t getSlaveVersion()
Get semver compliant version of slave firmware.
void changeI2Caddress(uint8_t newAddress)
Permanently change the I2C address of the device. New address is stored in EEPROM (AVR) or flash memo...
uint8_t * buffer
The allocated buffer.
const uint8_t getVersionResult
const uint8_t getVersionCmd
const uint8_t clearInterruptResult
int16_t setI2Cdelay(int16_t delay)
Define a minimum time that the master keeps between I2C transmissions. This is to make sure that the ...
const uint8_t clearInterruptCmd
void reset()
Tells the slave to reset to it's default state. It is recommended to reset the slave every time the m...
void write(const T &value)
Write any basic data type to the buffer at the current position and increment the position pointer ac...
bool checkVersion(uint32_t masterVersion)
Get version of slave firmware and compare it with library version.
void setInterruptPin(int8_t pin, bool activeHigh=true)
Define a global interrupt pin which can be used by device units (steppers, servos....