6

I have had minor success using the PIGPIO library and interfacing the Pi as an I2C Slave (Using GPIO Pins 18 and 19 as SDA and SCL) with a Campbell CR1000X Datalogger

I am encountering a problem receiving messages after I slow down the scan rate from the Campbell program though. It seems my program on Pi only successfully reads and outputs data when I send the data from the master at 10ms intervals or faster.

Placing a sleep() function call (tried from one second to upwards of 30 seconds) in my Pi program after every successful read/output did not work either.

Any ideas as to why the Pi program is not reading anything at a scan rate slower than 10ms? (Ideally I want to only send data to the pi every few minutes or more so this is a big problem)

relevant code:

Campbell Controller

PortPairConfig(C7,2) //3.3 V 
I2COpen (C7,50000) //50000 Hz
Scan (30, sec, 0, 0) // send Information every 30 seconds
  I2CWrite(C7,&H0A,Counter, 4, &H3) //&H3 sends start condition at beginning, and stop condition(NACK) at end of transaction
  //Counter is the information variable being sent, 4 is number of bytes
....
Next Scan

Pi Code

atomic<bool> Quit = ATOMIC_VAR_INIT(false);
 void quit(int sig){
 Quit = true;
}

int main(int argc, char** arg){
  signal(SIGINT,quit);
  bsc_xfer_t xfer;
  gpioInitialise();
  xfer.control = (0x0A<<16) | 0x305;

  while(!Quit){
    int status = bscXfer(&xfer);
    if(status){
      if(xfer.rxCnt > 0){
        cout << xfer.rxBuf << endl;
        memset(xfer.rxBuf, '\0', sizeof(char)*BSC_FIFO_SIZE);
      }
    }
  }
  return 1;
}

Note: This program outputs the expected information when I have my Campbell scan at 10,msec

Thanks for taking the time to read and help out

2
  • 2
    rxBuf is read only. Don't memset it. If you want to use cout to dump the contents, instead copy rxCnt bytes to a null-filled scratch array and cout that. Apr 26, 2019 at 13:54
  • I believe the reason why communication works in this way has nothing to do with I2C or the Pi. Perhaps your device expects to be polled all the time and goes to sleep mode if you don't talk to it for longer than 10 ms. Dec 7, 2020 at 14:18

0

Your Answer

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

Browse other questions tagged or ask your own question.