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 this and help me out.
rxBufis read only. Don'tmemsetit. If you want to usecoutto dump the contents, instead copyrxCntbytes to a null-filled scratch array andcoutthat.