Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8057016

DIO: I2CDevice write does not work with ByteBuffer

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P2 P2
    • None
    • None
    • embedded
    • None
    • raspberry pi

    • dio

      In my understanding next two methods must perform the same write action regarding I2C device and they both are correct
         
       private void writeWrong(int addr, byte data) throws IOException, InterruptedException {
              ByteBuffer buf = ByteBuffer.allocate(1);
              buf.put(data);

              i2cdevice.begin();
              i2cdevice.write(addr, 1, buf);
              i2cdevice.end();
              Thread.sleep(2000);
          }

       private void write(int addr, byte data) throws IOException, InterruptedException {
              byte[] bytes = new byte[]{
                      data
              };

              i2cdevice.begin();
              i2cdevice.write(addr, 1, ByteBuffer.wrap(bytes));
              i2cdevice.end();

              Thread.sleep(2000);
          }

      However, if we read immediately after write operation to verify the data, it occurs that writeWrong method does not actually write any data

        private byte read(int addr) throws IOException {
              byte[] bytes = new byte[1];
              i2cdevice.read(addr, 1, ByteBuffer.wrap(bytes));
              return bytes[0];
          }

      so i.e.
      int value = 16;
      writeWrong(0x00, (byte) value);
      read(0x00) = 0
      write(0x00, (byte) value);
      read(0x00) = 16

            stsmirno Stanislav Smirnov (Inactive)
            stsmirno Stanislav Smirnov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: