CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

MLX90614 Driver(for read) CRC8 (PEC) Code

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mustafa_40



Joined: 24 Oct 2014
Posts: 1

View user's profile Send private message Send e-mail

MLX90614 Driver(for read) CRC8 (PEC) Code
PostPosted: Fri Oct 24, 2014 12:59 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 24, 2014 1:21 am     Reply with quote

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).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group