Code Monkey home page Code Monkey logo

arduino-twi's Introduction

Arduino-TWI

The TWI library is an abstract interface for I2C device drivers. The library includes a hardware and software bus manager, and example device drivers for I2C Humidity and Temperature Sensor (Si70XX), Remote 8-bit I/O expander (PCF8574/PCF8574A), Digital Pressure Sensor (BMP085), and Single/Multi-Channel 1-Wire Master (DS2482).

The software bus manager implementation of the TWI interface uses the Arduino-GPIO library. Both software and avr hardware bus manager implementations supports repeated start condition and device driver mutex on multi-tasking.

Repeated start condition allows combined write/read operations to one or more devices without releasing the bus and thus with the guarantee that the operation is not interrupted (when using multiple masters).

Device driver mutex allows a task to complete a device driver function in a synchronized manner when using the Arduino-Scheduler.

Version: 1.9

Classes

Example Sketches

Dependencies

arduino-twi's People

Contributors

mikaelpatel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

arduino-twi's Issues

Can't get it to work with Arduino Uno or Duemilanove

It's rather confusing to me what the problem is since it works with the Wire library.

I see that the address is not shifted the same direction though (in TWI.h), but it doesn't help changing that:

    Device(TWI& twi, uint8_t addr) :
      m_twi(twi),
      m_addr(addr << 1)
    {
    }

Here is most of my code:

#include <Arduino.h>
#include <Wire.h>
#define AVR
#include "TWI.h"
#include "Hardware/TWI.h"

Hardware::TWI twi;
TWI::Device dev{twi, 0x06};

  uint8_t read(uint8_t address, uint8_t register_, uint8_t bytesToRead, uint8_t* buffer) {
    if (!dev.acquire()) return 0;
    dev.write(&register_, sizeof(register_));
    delay(100);
    int8_t bytesRead = dev.read(buffer, bytesToRead);
    if (!dev.release() or bytesRead < 0) return 0;
    return bytesRead;
    /*
    Wire.beginTransmission(address >> 1);
    Wire.write(register_);
    uint8_t result = Wire.endTransmission();
    if (result == 0) {
      delay(100);
      bytesToRead = Wire.requestFrom(address >> 1, bytesToRead);
      return Wire.readBytes(buffer, bytesToRead);
    } else {
      Serial.print(F("err"));
      Serial.write(result);
    }
    return 0;
    */
  }

Edit: I forgot to mention what went wrong.

Well, at first with some other code (not the one above) my Arduino kept resetting itself whenever I tried to use these functions. Which suggests memory overflow or something seriously wrong.

But with the code above the acquire never happens and if I remember correctly I think it then caused my Arduino to hang.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.