There is another problem does concern me.
When I run bcm2835 i2c to communicate with mlx90615, there will be some silent hang after hours or days reading temp from chip. If the hang is some error like communication failure, I can use exception to handle it. But it is a silent hang, the program will stop there.
Here is my code, is there any wrong usage? This happen on both pi1 and pi2.
Thanks for this wonderful library~
"""
//fordit: gcc MLXi2c.c -o i2c -l bcm2835
#include <stdio.h>
#include <bcm2835.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include<time.h>
#define AVG 1 //averaging samples
#define LOGTIME 10 //loging period
int main(int argc, char **argv)
{
unsigned char buf[6];
unsigned char i,reg;
double temp=0,calc=0, skytemp,atemp;
bcm2835_init();
bcm2835_i2c_begin();
bcm2835_i2c_set_baudrate(100000);
bcm2835_i2c_setSlaveAddress(0x5a);
printf("\nOk, your device is working!!\n");
bcm2835_i2c_begin();
while (1){
calc=0;
reg=7;
//bcm2835_i2c_begin();
bcm2835_i2c_write (®, 1);
bcm2835_i2c_read_register_rs(®,&buf[0],3);
temp = (double) (((buf[1]) << 8) + buf[0]);
temp = (temp * 0.02)-0.01;
temp = temp - 273.15;
calc+=temp;
printf("%f\n",calc);
}
}
"""