void SRF08::write_reg(_address address, byte reg, char val) { beginTransmission(address); send(reg); send(val); endTransmission(); }
void PulsePlug::setReg (byte reg, byte val) { // set a register beginTransmission(); Wire.write(reg); Wire.write(val); endTransmission(); delay(10); // XXX Nothing in datasheet indicates this is required; was in original code. }
byte PulsePlug::readParam (byte addr) { // read from parameter ram beginTransmission(); Wire.write(PulsePlug::COMMAND); Wire.write(0x80 | addr); // PARAM_QUERY endTransmission(); delay(10); // XXX Nothing in datasheet indicates this is required; was in original code. return getReg(PulsePlug::PARAM_RD); }
void PulsePlug::writeParam (byte addr, byte val) { // write to parameter ram beginTransmission(); Wire.write(PulsePlug::PARAM_WR); Wire.write(val); // auto-increments into PulsePlug::COMMAND Wire.write(0xA0 | addr); // PARAM_SET endTransmission(); delay(10); // XXX Nothing in datasheet indicates this is required; was in original code. }
byte PulsePlug::getReg (byte reg) { // get a register beginTransmission(); Wire.write(reg); endTransmission(); requestData(1); byte result = Wire.read(); delay(10); // XXX Nothing in datasheet indicates this is required; was in original code. return result; }
uint8_t Vortex86CAN::sendMsgBuf(uint32_t id, uint8_t ext, uint8_t len, uint8_t *buf) { uint8_t ret; beginTransmission(id, ext); write(buf, len); ret = endTransmission(); return (ret == 0) ? (CAN_OK) : (CAN_FAIL); }
bool PulsePlug::isPresent() { beginTransmission(); byte result = endTransmission(); if (result == 0) { return true; } else { Serial.print("isPresent() error code = "); Serial.println(result); return false; } }
void cMxRadio::sendFrame(uint16_t destaddress,bool needackval,uint8_t* frm, uint8_t len) { uint8_t oldvalue=txTmpBuffer[0]; if(!needackval) txTmpBuffer[0] = 0x41; else txTmpBuffer[0] = 0x61; beginTransmission(destaddress); write(frm,len); endTransmission(); txTmpBuffer[0]=oldvalue; }
/** = a reading from a sonar, should call ping first. */ int Srf08::getData(){ int distance Wire.beginTransmission(SRF_ADDR+_device); Wire.write(SRF_ECHO_H); Wire.endTransmission(); // read back data Wire.requestFrom(SRF_ADDR+_device, (int) 1); while(Wire.available() < 2){ // need some sort of timeout! } distance = Wire.read() << 8; distance += Wire.read(); return distance; }
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop) { if (quantity > BUFFER_LENGTH) { quantity = BUFFER_LENGTH; } if (!quantity) { return (0); } WireContext *wc = getWireContext(); beginTransmission(address); wc->i2cTransaction.readCount = quantity; /* if != 0; then error occurred */ return (endTransmission(sendStop) ? 0 : quantity); }
// Returns ambient light values as an array // First item is visual light, second is IR light. uint16_t* PulsePlug::fetchALSData () { static uint16_t als_data[2]; static uint16_t tmp; // read out all result registers as lsb-msb pairs of bytes beginTransmission(); Wire.write(ALS_VIS_DATA0); endTransmission(); requestData(4); for (int i=0; i<=1; i++) { als_data[i] = Wire.read(); tmp = Wire.read(); als_data[i] += (tmp << 8); } return als_data; }
// Fetch data from the PS1, PS2 and PS3 registers. // They are stored as LSB-MSB pairs of bytes there; convert them to 16bit ints here. uint16_t* PulsePlug::fetchLedData() { static uint16_t ps[3]; static uint16_t tmp; beginTransmission(); Wire.write(PulsePlug::PS1_DATA0); endTransmission(); requestData(6); for (int i=0; i<=2; i++) { ps[i] = Wire.read(); tmp = Wire.read(); ps[i] += (tmp << 8); } return ps; }
/** * @brief TX a Byte * * If "beginTrasmission" was used, then it writes into the transmit buffer for non-immediate mode * If "beginTrasmission" was not used, then it transmits the single byte immediately (slower for multiple bytes) * * @param c character to be sent */ void cMxRadio::write(uint8_t c) { if (usedBeginTransmission) { if (txTmpBufferLength < ZR_TXTMPBUFF_SIZE - 2) { txTmpBuffer[txTmpBufferLength] = c; txTmpBufferLength++; if (txTmpBufferLength >= ZR_TXTMPBUFF_SIZE - 2) { // buffer is now full // just send it all out so we have more room endTransmission(); beginTransmission(); } } } else { txTmpBuffer[HeadSize] = c; // set payload txTmpBuffer[HeadSize+1] = 0; // empty FCS txTmpBuffer[HeadSize+2] = 0; // empty FCS #ifdef ZR_TXWAIT_BEFORE waitTxDone(0xFFFF); #endif txIsBusy = 1; if (setautotx) radio_set_state(STATE_TXAUTO); else radio_set_state(STATE_TX); ZR_RFTX_LED_ON(); radio_send_frame(10, txTmpBuffer, 0); #ifdef ZR_TXWAIT_AFTER waitTxDone(0xFFFF); if (setautorx) radio_set_state(STATE_RXAUTO); else radio_set_state(STATE_RX); txIsBusy = 0; #endif } }
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop) { if (isize > 0) { // send internal address; this mode allows sending a repeated start to access // some devices' internal registers. This function is executed by the hardware // TWI module on other processors (for example Due's TWI_IADR and TWI_MMR registers) beginTransmission(address); // the maximum size of internal address is 3 bytes if (isize > 3){ isize = 3; } // write internal register address - most significant byte first while (isize-- > 0) write((uint8_t)(iaddress >> (isize*8))); endTransmission(false); }
void SRF08::ping(_address address, byte reg) { beginTransmission(address); send(reg); endTransmission(); }
void WireClass::beginTransmission(int address) { beginTransmission((uint8_t) address); }
void SoftwareWire::beginTransmission(int address) { beginTransmission((uint8_t)address); }
// // printStatus // ----------- // Print information to the Serial port // Used during developing and debugging. // Call it with the Serial port as parameter: // myWire.printStatus(Serial); // This function is not compatible with the Wire library. // When this function is not called, it does not use any memory. // void SoftwareWire::printStatus( HardwareSerial& Ser) { Ser.println(F("-------------------")); Ser.println(F("SoftwareWire Status")); Ser.println(F("-------------------")); Ser.print(F(" F_CPU = ")); Ser.println(F_CPU); Ser.print(F(" sizeof(SoftwareWire) = ")); Ser.println(sizeof(SoftwareWire)); Ser.print(F(" _transmission status = ")); Ser.println(_transmission); Ser.print(F(" _i2cdelay = ")); Ser.print(_i2cdelay); if( _i2cdelay == 0) Ser.print(F(" (free running)")); Ser.println(); Ser.print(F(" _pullups = ")); Ser.print(_pullups); if( _pullups) Ser.print(F(" (enabled)")); Ser.println(); Ser.print(F(" _timeout = ")); Ser.print(_timeout); Ser.println(F(" ms")); Ser.print(F(" SOFTWAREWIRE_BUFSIZE = ")); Ser.println(SOFTWAREWIRE_BUFSIZE); Ser.print(F(" rxBufPut = ")); Ser.println(rxBufPut); Ser.print(F(" rxBufGet = ")); Ser.println(rxBufGet); Ser.print(F(" available() = ")); Ser.println(available()); Ser.print(F(" rxBuf (hex) = ")); for(int ii=0; ii<SOFTWAREWIRE_BUFSIZE; ii++) { if(rxBuf[ii] < 16) Ser.print(F("0")); Ser.print(rxBuf[ii],HEX); Ser.print(F(" ")); } Ser.println(); Ser.print(F(" _sdaPin = ")); Ser.println(_sdaPin); Ser.print(F(" _sclPin = ")); Ser.println(_sclPin); Ser.print(F(" _sdaBitMast = 0x")); Ser.println(_sdaBitMask, HEX); Ser.print(F(" _sclBitMast = 0x")); Ser.println(_sclBitMask, HEX); Ser.print(F(" _sdaPortReg = ")); Ser.println( (uint16_t) _sdaPortReg, HEX); Ser.print(F(" _sclPortReg = ")); Ser.println( (uint16_t) _sclPortReg, HEX); Ser.print(F(" _sdaDirReg = ")); Ser.println( (uint16_t) _sdaDirReg, HEX); Ser.print(F(" _sclDirReg = ")); Ser.println( (uint16_t) _sclDirReg, HEX); Ser.print(F(" _sdaPinReg = ")); Ser.println( (uint16_t) _sdaPinReg, HEX); Ser.print(F(" _sclPinReg = ")); Ser.println( (uint16_t) _sclPinReg, HEX); Ser.print(F(" line state sda = ")); Ser.println(i2c_sda_read()); Ser.print(F(" line state scl = ")); Ser.println(i2c_scl_read()); #ifdef ENABLE_I2C_SCANNER // i2c_scanner // Taken from : http://playground.arduino.cc/Main/I2cScanner // At April 2015, it was version 5 Ser.println("\n I2C Scanner"); byte error, address; int nDevices; Ser.println(" Scanning..."); nDevices = 0; for(address=1; address<127; address++ ) { // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. beginTransmission(address); error = endTransmission(); if (error == 0) { Ser.print(" I2C device found at address 0x"); if (address<16) Ser.print("0"); Ser.print(address,HEX); Ser.println(" !"); nDevices++; } else if (error==4) { Ser.print(" Unknow error at address 0x"); if (address<16) Ser.print("0"); Ser.println(address,HEX); } } if (nDevices == 0) Ser.println(" No I2C devices found\n"); else Ser.println(" done\n"); #endif }
uint8_t I2C::beginTransmission(int address) { return(beginTransmission((uint8_t) address)); }
void TwoWire::beginTransmission(int address) { beginTransmission((uint8_t) address); }
void x10Class::beginTransmission(int data) { beginTransmission((uint8_t)data); }
uint8_t SoftI2CMaster::beginTransmission(int address) { return beginTransmission((uint8_t)address); }
void TwoWire::beginTransmission(int slave_address) { beginTransmission((uint8)slave_address); }
void TwoWire::beginTransmission(uint8_t address) { beginTransmission(static_cast<uint16_t>(address)); }