0

System: RPi # B OS: Ubuntu-16.04 Ma'te desktop environment Problem: i2cdetect -y 1 command response ultra-slow after running a program using the pigpio library in a program.

Since I've had no luck with the wiringPi library with talking to a MCP23017 IO expander I thought I'd try the pigpio library.

Well reading and writing the MCP23017 registers works. gpioInitialise(), i2cOpen(), i2cClose(), & gpioTerminate() functions along with register read/writes work properly.

If a read/write fails I'd use the i2cdetect tool to verify the MCP23017 id seated OK in the breadboard. It has a habit of unseating itself on the pins 1 ... 14 side.

When I execute the i2cdetect command after reseating the MC_23017 the command response is super slow. I also get a ton of messages in syslog transfer timeouts:

Jun 22 19:39:06 rpi3b2 kernel: [18443.461850] i2c i2c-1: transfer timed out
Jun 22 19:39:07 rpi3b2 kernel: [18444.461859] i2c i2c-1: transfer timed out
Jun 22 19:39:08 rpi3b2 kernel: [18445.461901] i2c i2c-1: transfer timed out
Jun 22 19:39:09 rpi3b2 kernel: [18446.461903] i2c i2c-1: transfer timed out
Jun 22 19:39:10 rpi3b2 kernel: [18447.461916] i2c i2c-1: transfer timed out
Jun 22 19:39:11 rpi3b2 kernel: [18448.461929] i2c i2c-1: transfer timed out
Jun 22 19:39:12 rpi3b2 kernel: [18449.461918] i2c i2c-1: transfer timed out
Jun 22 19:39:13 rpi3b2 kernel: [18450.461928] i2c i2c-1: transfer timed out
Jun 22 19:39:14 rpi3b2 kernel: [18451.461929] i2c i2c-1: transfer timed out
Jun 22 19:39:15 rpi3b2 kernel: [18452.461946] i2c i2c-1: transfer timed out
Jun 22 19:39:16 rpi3b2 kernel: [18453.461929] i2c i2c-1: transfer timed out
Jun 22 19:39:17 rpi3b2 kernel: [18454.461957] i2c i2c-1: transfer timed out
Jun 22 19:39:18 rpi3b2 kernel: [18455.461944] i2c i2c-1: transfer timed out
Jun 22 19:39:19 rpi3b2 kernel: [18456.461917] i2c i2c-1: transfer timed out

I have to reboot the Pi to get a normal i2cdetect command response. However if I run the pigpio program the same result occur.

Can anyone help/provide an explaination on this? Much appriciated.

    /*-------------------------------------------------------------------------------
 * pgbl_01.c
 * pigpio library.
 * Blink LEDs program #1.
 */

/*-------------------------------------------------------------------------------
 * Includes.
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <pigpio.h>

/*-------------------------------------------------------------------------------
 * Global constants & variables.
 */

#define NUM_PINS 5
unsigned pins[] = { 5, 6, 13, 19, 26 };

/*-------------------------------------------------------------------------------
 * Helper functions.
 */

// Print an 8-bit register value in binary.
// 
const char* printb8(int x) {
    static char b[9];
    b[0] = '\0';
    int z;
    for (z = 128; z > 0; z >>= 1) {
        strcat(b, ((x & z) == z) ? "1" : "0");
    }
    return b;
} /* End printb */

// Press Any Key To Continue.
//
void paktc(){
    printf("Press any key to continue...\n");
    getchar();
    //printf("%c\n", ch);
} /* End paktc */

/*-------------------------------------------------------------------------------
  * Main function.
  */

int main(int argc, char **argv) {
    char *message = "HELLO WOILD from the C programming language!!\n\n";
    printf("%s", message);

    if (gpioInitialise() < 0) {
        fprintf(stderr, "pigpio initialisation failed.\n");
        return(1);
    }
    else {
        printf("pigpio initialisation OK.\n");
    }

    // Set pins for output low, delay 1 min, then high.
    //
    for (int p = 0; p < NUM_PINS; p++) {
        gpioSetMode(p, PI_OUTPUT);
        gpioWrite(pins[p], 0x00);
        sleep(1);
        gpioWrite(pins[p], 0x01);
    }

    // Clean up and close pigpio.
    //
    gpioTerminate();
    printf("Done.\n");
} /* End main() */
2
  • Could you edit the question and include the pigpio program?
    – joan
    Commented Jun 23, 2018 at 13:29
  • Correction:My error. This occured after running a gpio blink LEDs sequentially program using gpioRead() and gpioWrite() not i2cReadByte() and i2cWriteByte().
    – Farad'n
    Commented Jun 23, 2018 at 15:06

1 Answer 1

1

In the pigpio code there is an error in your gpioSetMode() call.

You are setting GPIO 0-4 to be outputs. GPIO 0-3 are the I2C buses GPIO. That will totally confuse the I2C system as it expects them to be in mode ALT0.

Replace

gpioSetMode(p, PI_OUTPUT);

with

gpioSetMode(pins[p], PI_OUTPUT);

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.