View previous topic :: View next topic |
Author |
Message |
mustafa_40
Joined: 24 Oct 2014 Posts: 1
|
MLX90614 Driver(for read) CRC8 (PEC) Code |
Posted: Fri Oct 24, 2014 12:59 am |
|
|
Hi everyone,
I am writing MLX90614 driver (just read) with C in CCS C. I wrote code reading function, but couldn't generate the CRC(PEC) code. CRC8 to write my code please help me ? I'm reading function(ReadSensor()), right? Could you check ? Thank you so much for interest. Good works.
Code: |
#include <18f4550.h>
#if defined(__PCH__)
#use delay(clock=4000000)
#use i2c(master,sda=PIN_B0, scl=PIN_B1)
const float IR_ADDR = 0x5A;
const float OBJ_TEMP = 0x07;
int PEC=0;
/*void crc_control(unsigned int paket, unsigned char)
*/
float ReadSensor(char Temp_Source)
{
unsigned int Temp_var;
i2c_start(); // i2c start
i2c_write(IR_ADDR << 1); //send byte
i2c_write(Temp_Source); //
//i2c_res_start();
i2c_write(IR_ADDR << 1); //send byte
Temp_var = i2c_read(0); // (Not ACK)
Temp_var = ((i2c_read(0) << 8) + Temp_var);
i2c_Stop(); // i2c stop
return Temp_var;
}
float Temp;
void main()
{
i2c_start(); //i2c_init(50000);
delay_ms(1000);
while (1)
{
Temp = ReadSensor(OBJ_TEMP);
Temp = (Temp * 0.02) - 273.15;
delay_ms(500);
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Fri Oct 24, 2014 1:21 am |
|
|
You should only NACK the _last_ byte in a transaction....
You also have two 8bit values, that you attempt to assemble in an 8bit integer....
Look at ex_crc.c
The driver for this is in crc.c. You need the generate_8bit_crc function, with the pattern 0b0111 (CCITT CRC8). |
|
|
|