|
|
View previous topic :: View next topic |
Author |
Message |
[email protected]
Joined: 18 Apr 2018 Posts: 5
|
PIC16F1455 MAX30205 Body Temperature Sensor I2C code |
Posted: Thu Nov 08, 2018 4:55 am |
|
|
I am working on PIC16F1455 with MAX30205 Body Temperature Sensor, does anyone has I2C example code? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Thu Nov 08, 2018 6:24 am |
|
|
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: 19552
|
|
Posted: Thu Nov 08, 2018 7:50 am |
|
|
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
|
|
Posted: Thu Nov 22, 2018 3:39 pm |
|
|
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;
} |
|
|
|
|
|
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
|