Pi4J / pi4j-v1

DEPRECATED Java I/O library for Raspberry Pi (GPIO, I2C, SPI, UART)
http://www.pi4j.com
Apache License 2.0
1.31k stars 447 forks source link

PI4J, I2C, IOException, Invalid argument using module MS5607 #431

Closed pcotegithub closed 5 years ago

pcotegithub commented 5 years ago

Hello I cannot send a RESET command to the module, this should be simple.

I have tried module swap (got 3) and nothing changed. Other I2C module such as BME280 works. Checked all the voltages and they are OK. This is the code (extracts) and error message

// Parallax Device I2C MS5607 I2C address public static final int MS5607_WRITE_ADDR = 0xEE; public static final int MS5607_READ_ADDR = 0xEF;

// Parallax Device I2C MS5607 chip commands public static final byte MS5607_CMD_RESET = (byte) 0x1E; // ADC reset command

try {

    ms5607DeviceWriter = i2cSensorBus.getDevice(MS5607_WRITE_ADDR);
    ms5607DeviceReader = i2cSensorBus.getDevice(MS5607_READ_ADDR);

} catch (IOException e) {
    System.err.println(RED + systemDateFormat.format(new Date()) + " " + "--> <ERROR> Unable to find MS5607 device" + RESET);
    System.err.println(RED + "--> <ERROR> " + e.getMessage() + RESET);
}

// MS5607
try {
    System.out.println("******************************************************");
    System.out.println("MS-5607 attempt RESET");
    ms5607DeviceWriter.write(MS5607_CMD_RESET);
    System.out.println(GREEN + "MS-5607 RESET successful" + RESET);
    sleep(10); // from C code, wait 3 ms but chose 10ms

} catch (IOException e) {
    System.err.println(RED + systemDateFormat.format(new Date()) + " " + "--> <ERROR> Unable to reset MS5607 device" + RESET);
    System.err.println(RED + "--> <ERROR> " + e.getMessage() + RESET);
}

The output at runtime:


MS-5607 attempt RESET 2018-09-18 20:18:23 --> Unable to reset MS5607 device --> Invalid argument

I am unable to find what is wrong. The PI4J documentation indicates void return and byte as a parameter.

Any idea??

pcotegithub commented 5 years ago

Closed by myself

Found the problem. It is an 8 bit I2C address that needs to be changed to a 7 bit address. Therefore the EE (write address) and EF (read address) are changed to a single 7bit I2C address of 76 hex.

See https://www.totalphase.com/support/articles/200349176-7-bit-8-bit-and-10-bit-I2C-Slave-Addressing