I am in a process to write Espruino compatible module for Si114x Pulse sensor library which is basically a code conversion on Arduino library. The sensor uses I2C protocol for MCU comuniication.
I know that Espruino supports byte array in I2C.writeTo() method, and also stop:false/true option.
So if I would need to convert the below code what should be the best option for me?
void PulsePlug<T>::writeParam(uint8_t addr, uint8_t val)
{
// write to parameter ram
_i2c->beginTransmission(i2cAddr);
_i2c->write(Si114x::PARAM_WR);
_i2c->write(val);
// auto-increments into Si114x::COMMAND
_i2c->write(0xA0 | addr); // PARAM_SET
_i2c->endTransmission();
delay(10); // XXX Nothing in datasheet indicates this is required; was in
// original code.
}
uint8_t PulsePlug<T>::readParam(uint8_t addr)
{
// read from parameter ram
_i2c->beginTransmission(i2cAddr);
_i2c->write(Si114x::COMMAND);
_i2c->write(0x80 | addr); // PARAM_QUERY
_i2c->endTransmission();
delay(10); // NOTE: Nothing in datasheet indicates this is required - in original code.
return getReg(Si114x::PARAM_RD);
}
uint8_t PulsePlug<T>::getReg(uint8_t reg)
{
// get a register
_i2c->beginTransmission(i2cAddr);
_i2c->write(reg);
_i2c->endTransmission();
requestData(1);
uint8_t result = _i2c->read();
delay(10); // NOTE: Nothing in datasheet indicates this is required - in original code.
return result;
}
1- Combine all bytes to single byte array?
2- Individual writeTo() call having stop:false for the first call?
3- How should I care the delay, a setTimeout/ Promise?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi there,
I am in a process to write Espruino compatible module for Si114x Pulse sensor library which is basically a code conversion on Arduino library. The sensor uses I2C protocol for MCU comuniication.
I know that Espruino supports byte array in I2C.writeTo() method, and also stop:false/true option.
So if I would need to convert the below code what should be the best option for me?
1- Combine all bytes to single byte array?
2- Individual writeTo() call having stop:false for the first call?
3- How should I care the delay, a setTimeout/ Promise?
Reference:
Si114x datasheet
Arduino Library