Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i2cWriteByte is not able to write value greater then 128 0x80 #332

Open
pawsko opened this issue Mar 1, 2024 · 1 comment
Open

i2cWriteByte is not able to write value greater then 128 0x80 #332

pawsko opened this issue Mar 1, 2024 · 1 comment

Comments

@pawsko
Copy link

pawsko commented Mar 1, 2024

Linux raspberrypi 6.1.0-rpi8-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.73-1+rpt1 (2024-01-25) aarch64 GNU/Linux
Raspberry Pi 3B+
Pi4J 2.4.0
pigpio-i2c provider

I am trying to use the pigpio-i2c provider to write to a device using

public class PCA8574 {
    private static final int I2C_BUS = 0x01;
    private static final int I2C_DEVICE = 0x20;
    private Console console;

    public void setConfig(int config) {
        console = new Console();
        console.title("<-- Set Config -->", "I2C PCA8574 Set Config");
        var pi4J = Pi4J.newAutoContext();
        I2CProvider i2cProvider = pi4J.provider("pigpio-i2c");
        var pca8574Config = I2C.newConfigBuilder(pi4J)
                .id("my-i2c-bus")
                .name("My I2C Bus")
                .bus(I2C_BUS)
                .device(I2C_DEVICE)
                .build();
        try (var i2c = i2cProvider.create(pca8574Config)) {
            i2c.write((byte)config);

            console.println();
            console.println("ATTEMPTING TO SHUTDOWN/TERMINATE THIS PROGRAM");
            pi4J.shutdown();
        }
    }
}

And I am faced with the issue. I know that byte has range from -128 to 127. Inside there is a magic which transforms Java signedbyte value to native C library unsigned value. I cannot write using the pigpio-i2c provider any value lower than 0. I spent a lot of time debugging but still no results. The same error appears: SUCCESS=false; RESULT=-81 which means PIGPIO ERROR: PI_BAD_PARAM; bad i2c/spi/ser parameter. Below are a couple of console logs:

Success write 0 (0x00)

2024-03-01T12:34:35.687+01:00 TRACE 935 --- [nio-8080-exec-2] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::OPEN] -> Open I2C Bus [1] and Device [32]; FLAGS=[0]
2024-03-01T12:34:35.688+01:00 TRACE 935 --- [nio-8080-exec-2] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::OPEN] <- HANDLE=0; SUCCESS=true
2024-03-01T12:34:37.084+01:00 TRACE 935 --- [nio-8080-exec-2] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::WRITE] -> HANDLE=0; Byte [0]
2024-03-01T12:34:38.385+01:00 TRACE 935 --- [nio-8080-exec-2] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::WRITE] <- HANDLE=0; SUCCESS=true; RESULT=0
2024-03-01T12:34:38.386+01:00  INFO 935 --- [nio-8080-exec-2] com.pi4j.util.Console                    : 
2024-03-01T12:34:38.387+01:00  INFO 935 --- [nio-8080-exec-2] com.pi4j.util.Console                    : ATTEMPTING TO SHUTDOWN/TERMINATE THIS PROGRAM
2024-03-01T12:34:38.388+01:00 TRACE 935 --- [nio-8080-exec-2] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::CLOSE] -> HANDLE=0, Close I2C Bus
2024-03-01T12:34:38.390+01:00 TRACE 935 --- [nio-8080-exec-2] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::CLOSE] <- HANDLE=0; SUCCESS=true; RESULT=0
2024-03-01T12:34:38.398+01:00 TRACE 935 --- [nio-8080-exec-2] c.p.l.pigpio.impl.PiGpioNativeImpl       : [SHUTDOWN] -> STARTED
2024-03-01T12:34:38.419+01:00 TRACE 935 --- [nio-8080-exec-2] c.p.l.pigpio.impl.PiGpioNativeImpl       : [SHUTDOWN] <- FINISHED
2024-03-01T12:34:38.420+01:00 TRACE 935 --- [nio-8080-exec-2] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::CLOSE] -> HANDLE=0, Close I2C Bus

Success write 127 (0x7F)

2024-03-01T12:35:32.511+01:00 TRACE 935 --- [nio-8080-exec-3] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::OPEN] -> Open I2C Bus [1] and Device [32]; FLAGS=[0]
2024-03-01T12:35:32.512+01:00 TRACE 935 --- [nio-8080-exec-3] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::OPEN] <- HANDLE=0; SUCCESS=true
2024-03-01T12:35:51.666+01:00 TRACE 935 --- [nio-8080-exec-3] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::WRITE] -> HANDLE=0; Byte [127]
2024-03-01T12:37:02.367+01:00 TRACE 935 --- [nio-8080-exec-3] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::WRITE] <- HANDLE=0; SUCCESS=true; RESULT=0
2024-03-01T12:37:30.655+01:00  INFO 935 --- [nio-8080-exec-3] com.pi4j.util.Console                    : 
2024-03-01T12:37:32.024+01:00  INFO 935 --- [nio-8080-exec-3] com.pi4j.util.Console                    : ATTEMPTING TO SHUTDOWN/TERMINATE THIS PROGRAM
2024-03-01T12:37:33.723+01:00 TRACE 935 --- [nio-8080-exec-3] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::CLOSE] -> HANDLE=0, Close I2C Bus
2024-03-01T12:37:34.304+01:00 TRACE 935 --- [nio-8080-exec-3] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::CLOSE] <- HANDLE=0; SUCCESS=true; RESULT=0
2024-03-01T12:37:37.221+01:00 TRACE 935 --- [nio-8080-exec-3] c.p.l.pigpio.impl.PiGpioNativeImpl       : [SHUTDOWN] -> STARTED
2024-03-01T12:37:37.758+01:00 TRACE 935 --- [nio-8080-exec-3] c.p.l.pigpio.impl.PiGpioNativeImpl       : [SHUTDOWN] <- FINISHED
2024-03-01T12:37:41.726+01:00 TRACE 935 --- [nio-8080-exec-3] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::CLOSE] -> HANDLE=0, Close I2C Bus

Unsuccess write -127 (0x80)

2024-03-01T12:38:13.785+01:00 TRACE 935 --- [nio-8080-exec-4] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::OPEN] -> Open I2C Bus [1] and Device [32]; FLAGS=[0]
2024-03-01T12:38:13.786+01:00 TRACE 935 --- [nio-8080-exec-4] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::OPEN] <- HANDLE=0; SUCCESS=true
2024-03-01T12:38:17.274+01:00 TRACE 935 --- [nio-8080-exec-4] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::WRITE] -> HANDLE=0; Byte [128]
2024-03-01T12:39:55.279+01:00 TRACE 935 --- [nio-8080-exec-4] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::WRITE] <- HANDLE=0; SUCCESS=false; RESULT=-81
2024-03-01T12:39:55.343+01:00  WARN 935 --- [nio-8080-exec-4] c.p.l.pigpio.impl.PiGpioNativeImpl       : PIGPIO ERROR: PI_BAD_PARAM; bad i2c/spi/ser parameter
2024-03-01T12:39:55.350+01:00  INFO 935 --- [nio-8080-exec-4] com.pi4j.util.Console                    : 
2024-03-01T12:39:55.352+01:00  INFO 935 --- [nio-8080-exec-4] com.pi4j.util.Console                    : ATTEMPTING TO SHUTDOWN/TERMINATE THIS PROGRAM
2024-03-01T12:39:55.355+01:00 TRACE 935 --- [nio-8080-exec-4] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::CLOSE] -> HANDLE=0, Close I2C Bus
2024-03-01T12:39:55.357+01:00 TRACE 935 --- [nio-8080-exec-4] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::CLOSE] <- HANDLE=0; SUCCESS=true; RESULT=0
2024-03-01T12:39:55.366+01:00 TRACE 935 --- [nio-8080-exec-4] c.p.l.pigpio.impl.PiGpioNativeImpl       : [SHUTDOWN] -> STARTED
2024-03-01T12:39:55.401+01:00 TRACE 935 --- [nio-8080-exec-4] c.p.l.pigpio.impl.PiGpioNativeImpl       : [SHUTDOWN] <- FINISHED
2024-03-01T12:39:55.402+01:00 TRACE 935 --- [nio-8080-exec-4] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::CLOSE] -> HANDLE=0, Close I2C Bus

Unsuccess write -1 (0xFF)

2024-03-01T13:35:25.532+01:00 TRACE 935 --- [nio-8080-exec-6] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::OPEN] -> Open I2C Bus [1] and Device [32]; FLAGS=[0]
2024-03-01T13:35:25.535+01:00 TRACE 935 --- [nio-8080-exec-6] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::OPEN] <- HANDLE=0; SUCCESS=true
2024-03-01T13:35:31.188+01:00 TRACE 935 --- [nio-8080-exec-6] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::WRITE] -> HANDLE=0; Byte [255]
2024-03-01T13:35:34.032+01:00 TRACE 935 --- [nio-8080-exec-6] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::WRITE] <- HANDLE=0; SUCCESS=false; RESULT=-81
2024-03-01T13:35:34.035+01:00  WARN 935 --- [nio-8080-exec-6] c.p.l.pigpio.impl.PiGpioNativeImpl       : PIGPIO ERROR: PI_BAD_PARAM; bad i2c/spi/ser parameter
2024-03-01T13:35:34.036+01:00  INFO 935 --- [nio-8080-exec-6] com.pi4j.util.Console                    : 
2024-03-01T13:35:34.037+01:00  INFO 935 --- [nio-8080-exec-6] com.pi4j.util.Console                    : ATTEMPTING TO SHUTDOWN/TERMINATE THIS PROGRAM
2024-03-01T13:35:34.040+01:00 TRACE 935 --- [nio-8080-exec-6] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::CLOSE] -> HANDLE=0, Close I2C Bus
2024-03-01T13:35:34.042+01:00 TRACE 935 --- [nio-8080-exec-6] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::CLOSE] <- HANDLE=0; SUCCESS=true; RESULT=0
2024-03-01T13:35:34.050+01:00 TRACE 935 --- [nio-8080-exec-6] c.p.l.pigpio.impl.PiGpioNativeImpl       : [SHUTDOWN] -> STARTED
2024-03-01T13:35:34.089+01:00 TRACE 935 --- [nio-8080-exec-6] c.p.l.pigpio.impl.PiGpioNativeImpl       : [SHUTDOWN] <- FINISHED
2024-03-01T13:35:34.091+01:00 TRACE 935 --- [nio-8080-exec-6] c.p.l.pigpio.impl.PiGpioNativeImpl       : [I2C::CLOSE] -> HANDLE=0, Close I2C Bus

What am I doing wrong? :)
Any ideas, suggestions, directions?
Thanks in advance

@taartspi
Copy link
Collaborator

I don't believe you are in error. I have example devices that use this same write of a byte. They have worked correctly a long time on both pi4 I have. I tried this example code of both pi and now one failed with your error. The pi that operates correctly has the OS updates. The machine that failed has been used in various testing with different java etc. i know i updated the firmware early this month. The update that warns you of the danger in doing it. I tried the steps to revert the firmware to the correct level and it failed. So i created a new SD card. The failing pi operated correctly on this new OS image. So i question if there is a problem with the OS or fixes or firmware on your pi. Can you image a new SD and retry your code ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants