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 support@ccsinfo.com

PIC16F1455 MAX30205 Body Temperature Sensor I2C code

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
xiaop@lsbu.ac.uk



Joined: 18 Apr 2018
Posts: 5

View user's profile Send private message

PIC16F1455 MAX30205 Body Temperature Sensor I2C code
PostPosted: Thu Nov 08, 2018 4:55 am     Reply with quote

I am working on PIC16F1455 with MAX30205 Body Temperature Sensor, does anyone has I2C example code?
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Nov 08, 2018 6:24 am     Reply with quote

While I don't have those devices, I did download their datasheets.
Good news is that PIC will run fine at 3 volts ! So no need for logic level conversion chips.
If you haven't already, code a 1Hz flashing LED program and confirm the PIC runs properly.
Next, get PCM P's 'I2CSCANNER' program from the code library here, compile and test. It should report seeing the max chip. If not, did you use 4k7 pullups ? Check wiring as well. Confirm the device address !
Do NOT proceed until scanner sees the chip !
After that code some basic 'low level' programs to read the temperature from the device. Good news is that since it's a +ve only sensor, you can use unsigned long integers for all the accessing and math. You can probably 'google' someone else's code and convert/adapt into CCS C.

Just take small steps, confirming 'things' are working correctly. Trying to cut the real final program and expecting it to work, well, that almost never, ever happens and you'll spend says trying to figure out why.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Nov 08, 2018 7:50 am     Reply with quote

There is a 'caveat' on the supply voltage. 3.3v, is the _max_ that chip is rated for. I'd be wanting to run with a margin. Possibly 3v, rather than pushing this!...

Code depends on what you want to actually 'do'. The chip wakes in comparator mode, with the trigger level set to 75C (where OS goes on). However you can just read a temperature without worrying about this. Simply select register 1, and read two bytes. The value is in 1/256C steps.
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Thu Nov 22, 2018 3:39 pm     Reply with quote

I use that sensor...

Actually if you look at the datasheet, 3.0V gives the most accurate readings, based on the typical characteristics graphs.

I only use the sensor to read one shots, not continuous. Then, I shut down the sensor until I want to take another measurement.

As noted in the comments, you only use max_read_temp()

You will need to change the #use statement and the MAX30205_ADDRESS. Besides that you should be able to copy and paste that into your program...

Code:
#USE I2C(MASTER, I2C2, STREAM=MAX_TEMP_SENSOR)
#define MAX30205_ADDRESS 0x90
#define MAX_SHUTDOWN 0b00000001
#define MAX_ONESHOT 0b10000000

void max_write_config(int8 config); // user doesn't use this one. This is a helper function that read temp uses
uint16_t max_read_temp(void); // user uses this function only

void max_write_config(int8 config)
{
    i2c_start(MAX_TEMP_SENSOR); // start the i2c stream
    i2c_write(MAX30205_ADDRESS); // call the MAX address
    i2c_write(0x01); // Config register address
    i2c_write(config); // write in configuration bits
    i2c_stop(MAX_TEMP_SENSOR); // stop the i2c stream
}

uint16_t max_read_temp(void)
{
    uint8_t temp_lower;
    uint8_t temp_upper;
    uint16_t temp;

    max_write_config(MAX_ONESHOT); // one shot read sensor
    delay_ms(50); //takes less than 50 ms to convert a temperature

    i2c_start(MAX_TEMP_SENSOR); // start the i2c stream
    i2c_write(MAX30205_ADDRESS); // call the MAX address
    i2c_write(0x00); // call the temperature register address

    i2c_start(MAX_TEMP_SENSOR, 2); // repeated start on i2c stream
    i2c_write(MAX30205_ADDRESS + 1); // call the MAX address (address +1 changes data direction)

    temp_upper = (uint8_t) i2c_read(MAX_TEMP_SENSOR, 1); // read the two bytes in the temperature register
    temp_lower = (uint8_t) i2c_read(MAX_TEMP_SENSOR, 0);

    i2c_stop(MAX_TEMP_SENSOR); // stop the i2c stream

    temp = make16(temp_upper, temp_lower);

    max_write_config(MAX_SHUTDOWN);

    return temp;
}
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