Announcement

Collapse
No announcement yet.

Problems using DTWI.h library

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems using DTWI.h library

    Yesterday

    So I have been working on i2c communication between the picadillo 35T lcd and a smart battery device. So the lcd is the master device while the smart battery is the slave. I had the communcation between both devices working using the UECIDE-0.8.7J-full.exe IDE. Then I upgraded the UECIDE to version 0.8.8alpha22. I have downloaded the chipkit i2c libraries which are
    • libdtwi-chipkit 10.9.1
    • libwire-chipkit-harmony 9.0.1
    • libwire-chipkit 10.9.1
    but for some reason I can't get i2c to work. I decided to use DTWI.h library and tried to follow the I2CMasterEEPROM example but the lcd still can't communicate with the smart battery.

    Prior to upgrading to the new IDE the smart battery address (slave) was 0x16 (22 in decimal) but using the Wire.h library it is recommended that you get rid of the last bit so the address used was 0x0B (11 in decimal) which was used and I was able to communicate between the lcd and smart battery.

    Now using the upgraded IDE and DTWI I tried using but 0x0B and 0x16 address and I still wasn't able to communicate between the lcd and the smart battery.

    So the way the communication works between the LCD and Smart Battery is that the lcd retrieves battery data from the smart battery and then displays it on the screen.

    this is the I have written so far


    Code:
    #include <DTWI.h>
    DTWI0 dtwi0;
    #define BATTERY_ADDR 0x16
    #define SERIAL_NUMBER 0x1C
    
    /*********************Structure*************************************/
    struct { // battery parameter - unsigned word unsigned
      char lsb;
      unsigned char msb;
      unsigned int value;
    } typedef Param_uword;
    
    struct {
      Param_uword ManufacturerAccess; // Code 0x00 - ManufacturerAccess()
      Param_uword SerialNumber; // Code 0x1C - SerialNumber()
    } typedef battery;
    
    void setParam_U(unsigned char cmd, Param_uword* pu)
    {
      /* Wire.beginTransmission(BATTERY_ADDR);
        Wire.send(cmd);
        Wire.endTransmission();
        Wire.requestFrom(BATTERY_ADDR, 2); // request 2 bytes from battery
        pu->lsb = Wire.receive();
        pu->msb = Wire.receive(); // combine the MSB + LSB into one value for displaying
        pu->value = pu->msb << BYTE; // bit-shift the MSB to the left by 8 bits, moving it to the MSB position
        pu->value = pu->value ^ pu->lsb; // bitwise XOR the LSB with the value to place it in the LSB position
      */
      dtwi0.beginMaster();
      dtwi0.startMasterWrite(BATTERY_ADDR);
      dtwi0.write(&cmd, sizeof(cmd));
      dtwi0.stopMaster();
      dtwi0.startMasterWrite(BATTERY_ADDR);
      dtwi0.startMasterRead(BATTERY_ADDR);
      dtwi0.read(&pu->lsb, sizeof(pu->lsb));
      dtwi0.read(&pu->msb, sizeof(pu->msb));
      dtwi0.stopMaster();
      dtwi0.endMaster();
      pu->value = pu->msb << BYTE; // bit-shift the MSB to the left by 8 bits, moving it to the MSB position
      pu->value = pu->value ^ pu->lsb; // bitwise XOR the LSB with the value to place it in the LSB position
    }
    Code:
    #include "interface.h"
    void setup()
    {
      ...
    }
    
    battery batteryData;
    
    void loop() {
      setParam_U(SERIAL_NUMBER, &batteryData.SerialNumber);
      ...
    }
    This is but just a sample of the code I have written. Please disregard setParam() Wire.h implementation comment. That was my prior code before the IDE upgrade. I just need to get DTWI.h library implementation to work.

    Thank you.
    Last edited by James_4DSystems; 3rd March 2016, 09:00 AM. Reason: Was unreadable - edited/formatted

  • #2
    So I implemented this simple i2c code using the Wire.h. But I still can't get i2c to work, either for DTWI.h library or Wire.h library.
    Code:
    #include <Wire.h>
    
    void setup(){
      Wire.begin();
    }
    
    void loop(){
      int x = 0;
      Wire.beginTransmission(11);
      Wire.send(0x09);
      Wire.endTransmission();
      Wire.requestFrom(11, 2);  // request 2 bytes from battery
      x = Wire.receive();
      x = Wire.receive();
      delay(250);              
    }
    address 0x09 is the cmd code to retrieve the smart battery voltage.

    Comment

    Working...
    X