Forum Stats

  • 3,852,353 Users
  • 2,264,094 Discussions


Java ME - Raspberry - I2C - Combined message

HarrySatt Member Posts: 26
edited Feb 3, 2016 5:15AM in Java ME SDK

Hi there

I am trying to get the RPi 2 working with combined messages. for that I use

public class I2CCombinedMessage extends java.lang.Object

The I2CCombinedMessage

class allows for constructing a combined message. A combined message may be constituted of at least two reads and/or writes to one or more I2C slaves. A combined message starts with a START bit and ends with a STOP bit. But each of read and write messages constituting the combined message following the very first of these messages starts with a REPEATED START bit (one that is not preceded by a STOP bit).

With this codelet I am able to send the commands with this command but there are still STOP bits send. This should not happen. From bash on the RPi this REPEATED START works fine.

Someone an idea?

regards, Harald.


* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.


package i2c.test001;

import javax.microedition.midlet.MIDlet;


import java.nio.ByteBuffer;

import jdk.dio.DeviceManager;

import jdk.dio.i2cbus.I2CDevice;

import jdk.dio.i2cbus.I2CDeviceConfig;

import jdk.dio.i2cbus.I2CCombinedMessage;



* @author hsattm72


public class I2CTest001 extends MIDlet {

        private final int BUS_ID = 1;

        private final int CFG_ADDRESS = 0x1D;

        private final int ADDRESS_SIZE = 7;

        private final int CLOCK_FREQUENCY = 100000;


    // register addresses for MMA8452Q

        private final int WHO_AM_I = 0x0D;



    public void startApp() {


        System.out.println("* I2C Sample start  *");       



        I2CDeviceConfig config = new I2CDeviceConfig.Builder()


                .setAddress(CFG_ADDRESS, ADDRESS_SIZE)





        I2CDevice i2c = null;


        try {

            i2c =;

            // read the WHO_AM_I register

            ByteBuffer temp = ByteBuffer.allocateDirect(1);

            byte[] cmd = new byte[1];

            cmd[0] = 0x0d;

            I2CCombinedMessage msg = i2c.getBus().createCombinedMessage();

            msg.appendWrite(i2c, ByteBuffer.wrap(cmd) );

            msg.appendRead(i2c, temp);

            int[] transfer = msg.transfer();


            System.out.println("ID = " + transfer[0]);           

        } catch (Exception ex) {



        finally {

            // close the device

            if( i2c != null) {

                try {


                } catch( IOException ex) {








    public void destroyApp(boolean unconditional) {


        System.out.println("*  I2C Sample end   *");       




This discussion has been closed.