I2C and an IR sensor - Raspberry Pi Forums


i'm stuck. i'm trying configure ir (specifically, mlx90614) sensor's eeprom, can change things need change (settling time, etc).

far, have written following function in c:

code: select all

void writeconfig(){     // see http://depa.usst.edu.cn/chenjq/www2/sdesign/javascript/crccalculation.htm     // pec calculation     unsigned char * write = (unsigned char *)malloc(sizeof(unsigned char) * 9);      unsigned char * clear = (unsigned char *)malloc(sizeof(unsigned char) * 9);      // command, lsb, msb, pec     write[0] = 0x25; write[1] = 0x74; write[2] = 0xb4; write[3] = 0x70;     clear[0] = 0x25; clear[1] = 0x00; clear[2] = 0x00; clear[3] = 0x83;      bcm2835_i2c_write(clear, 4);     waitmillis(100);      bcm2835_i2c_write(write, 4);     waitmillis(100);      free(clear);     free(write);  }
clear eeprom, write desired value it.

know pec correct -- example code (in configuration sketch) @ cheap-thermocam.tk has:

code: select all

int address = 0x5a << 1; unsigned char lsb = 0x74; unsigned char msb = 0xb4; int pec = 0x70; ... i2cwrite(address, lsb, msb, pec) void i2cwrite(int adress, unsigned int lsb, unsigned int msb, int pec){   i2c_start_wait(dev+i2c_write);   i2c_write(adress);   i2c_write(lsb);    i2c_write(msb);   i2c_write(pec);   i2c_stop();     delay(100); } 
know 0x5a << 1 not same. library requires slave address between 0x03 , 0x77, , i've checked of oscilloscope. waveform looks correct writing, when read, read same value out.

think library i'm using correct -- writing, has i2c_read, i2c_write, , i2c_read_rep_start. don't care language solution in, long works.

completeness, here's function reads:

code: select all

int readconfig(){     // adapted  http://www.raspberrypi.org/phpbb3/viewtopic.php?t=17738&p=362569     unsigned char reg = 0x25; // command send     unsigned char buf[6] = {0,0,0,0,0,0};     int data=-1;      /*bcm2835_i2c_begin();*/     int w = bcm2835_i2c_write(&reg, 1);     int r = bcm2835_i2c_read_register_rs(&reg, &buf[0], 3);     printf("in read: %d, %d\n", w, r);     /*bcm2835_i2c_end();*/      data = buf[0] + (buf[1]<<8);     return data; }  
functions reading , writing return value, 0 if read/wrote correctly , 1 if doesn't. readconfig() function returns 0's while writeconfig() function returns 1. i've done while loop wait return 0, it's infinite loop.

complete code: https://github.com/scottsievert/ircamer ... ircamera.c
docs on bcm2835_i2c library: http://www.airspayce.com/mikem/bcm2835/group__i2c.html



raspberrypi



Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial