0

I'm toying with pigpio and I can't find some informations:

1) I'm currently using a arduino uno to send bytes (as master) to a Rpi3 as slave, I currently use BCM2 as SDA (A4 on Uno) and BCM3 as SDL(A5 on Uno) on the Rpi.

It seems odd to use the I2C master GPIOs to perform I2C-slave, but I couldn't find any relevant information. Am I using the "good" GPIOs ?

2) If I'm, I can't receive anything from the Uno here are both sources:

#include <Wire.h>

void setup()
{
    Wire.begin(); // join i2c bus as master
}

char str[17];

int x = 0;

void loop()
{
    sprintf(str, "Message %7d\n", x);
    if (++x > 9999999) x=0;

    Wire.beginTransmission(0x0A); 
    Wire.write(str);           
    Wire.endTransmission();    
    delay(100);
}

Arduino code is pretty much standard.

On the Rpi:

#include <pigpio.h>
#include <iostream>
#include <atomic>
#include <signal.h>

//g++ -Wall -pthread -o test test.cpp -lpigpio -lrt

std::atomic<bool> Quit = ATOMIC_VAR_INIT(false);

void quit(int sig)
{
    Quit = true; //will require handler quit too
}

int main(int argc, char** argv)
{
    signal(SIGINT, quit);

    bsc_xfer_t xfer;
    gpioInitialise();

    xfer.control = (0x0A<<16) | 0x305; 

    int status = bscXfer(&xfer);
    if (status >= 0)
    {
        xfer.rxCnt = 0;

        while(!Quit)
        {
            status = bscXfer(&xfer);
            if(status)
            {
                if (xfer.rxCnt > 0)
                {
                    std::cout << std::endl << xfer.rxBuf;
                    memset( xfer.rxBuf, '\0', sizeof(char)*BSC_FIFO_SIZE );
                }
                else
                {
                    //std::cout<<"\n No datas";
                }
            }
        }
    }
    else
    {
        std::cout<<"\nInit status error.\n"<<std::flush;
    }
    return status;
}

Any help on what Im doing wrong will be appreciated.

Edit: following Joan's answer I did swap the SDA & SCL to [ GPIO 18 & 19][1], and it works perfectly, solved fast

1

I do not think the information is "hidden".

E.g. http://abyz.me.uk/rpi/pigpio/cif.html#bscXfer

As far as I am aware all the pigpio API documentation says

The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) in I2C mode

  • I must admit that I read that page and didn't find it, I blame my lack of sleep, testing that now – Ebya Apr 26 '18 at 8:05
  • @Ebya That I understand. It's easy to miss within the other text. For examples it's often worth looking at the documentation for the other languages, in particular pigs or Python. They are often more detailed than the C examples. – joan Apr 26 '18 at 8:10
  • Just tested not receiving anything, joining a picture to the OP in a minute or two. – Ebya Apr 26 '18 at 8:11
  • disreagard comment, the doc doesn't refer to the gpio pin number but to the actual name of the pin... got it working – Ebya Apr 26 '18 at 8:20
  • I'm stuck on how to properly send data as a slave, if you have an example on any languages, I'ld like a link – Ebya Apr 29 '18 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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