-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from mayank-sirotiya-imgtec/thremo_proximity
platform/mikro-e/dev:add Thermo3 click driver
- Loading branch information
Showing
6 changed files
with
303 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
CONTIKI_PROJECT = test-thermo3 | ||
CONTIKI = ../../../.. | ||
|
||
CFLAGS += -DTHERMO3_CLICK | ||
|
||
APPS += thermo3-click | ||
APPDIRS += ../../dev | ||
|
||
all: $(CONTIKI_PROJECT) | ||
xc32-bin2hex $(CONTIKI_PROJECT).$(TARGET) | ||
|
||
distclean: cleanall | ||
|
||
cleanall: | ||
rm -f symbols.* | ||
|
||
include $(CONTIKI)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated | ||
* group companies. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from this | ||
* software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
/** | ||
* \file | ||
* A test application to get temperature form Thermo3 click board. | ||
* http://www.mikroe.com/click/thermo3/ | ||
*/ | ||
|
||
#include <contiki.h> | ||
#include <stdio.h> | ||
#include "dev/common-clicks.h" | ||
|
||
#define TEMP_REG 0x00 /*Temp. register Address*/ | ||
#define CONFIG_REG 0x01 /*Config. register Address*/ | ||
#define CONFIG_MSB 0x60 /*default value*/ | ||
#define CONFIG_LSB 0xE0 /*Conversion rate is set to 8Hz*/ | ||
/*---------------------------------------------------------------------------*/ | ||
PROCESS(test_thermo3, "Test Thermo3 click"); | ||
AUTOSTART_PROCESSES (&test_thermo3); | ||
/*---------------------------------------------------------------------------*/ | ||
PROCESS_THREAD(test_thermo3, ev, data) | ||
{ | ||
PROCESS_BEGIN(); | ||
static double temp_c; | ||
static struct etimer et; | ||
tmp102_init(); | ||
tmp102_reg_select(CONFIG_REG); | ||
tmp102_reg_write(CONFIG_MSB, CONFIG_LSB); | ||
tmp102_reg_select(TEMP_REG); | ||
while(1) { | ||
temp_c = 0; | ||
etimer_set(&et, CLOCK_SECOND); | ||
temp_c = tmp102_read_temp(); | ||
printf("Temperature is %.3f degree celsius\n",temp_c); | ||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); | ||
} | ||
PROCESS_END(); | ||
} | ||
/*---------------------------------------------------------------------------*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
thermo3-click_src += thermo3-click.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated | ||
* group companies. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from this | ||
* software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
/** | ||
* \file | ||
* Thermo3 click driver. | ||
* http://www.mikroe.com/click/thermo3/ | ||
* | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <pic32_i2c.h> | ||
#include "thermo3-click.h" | ||
/*---------------------------------------------------------------------------*/ | ||
void tmp102_init(void) | ||
{ | ||
i2c1_init(); | ||
i2c1_set_frequency (I2C_FREQUENCY); | ||
} | ||
/*---------------------------------------------------------------------------*/ | ||
void tmp102_reg_select(uint8_t reg) | ||
{ | ||
i2c1_master_enable(); | ||
i2c1_send_start(); | ||
if(i2c1_byte_send (TMP102_REG_WRITE)) { | ||
i2c1_send_repeated_start(); | ||
if(i2c1_byte_send (TMP102_REG_WRITE)) { | ||
printf("Failed the connection to Thermo3\n"); | ||
} | ||
} | ||
switch (reg) { | ||
case TMP102_TEMP: | ||
i2c1_byte_send (TMP102_TEMP); | ||
break; | ||
case TMP102_CONF: | ||
i2c1_byte_send (TMP102_CONF); | ||
break; | ||
case TMP102_TLOW: | ||
i2c1_byte_send (TMP102_TLOW); | ||
break; | ||
case TMP102_THIGH: | ||
i2c1_byte_send (TMP102_THIGH); | ||
break; | ||
default: | ||
printf("Invalid Register Address\n"); | ||
break; | ||
} | ||
i2c1_send_stop(); | ||
i2c1_master_disable(); | ||
} | ||
/*---------------------------------------------------------------------------*/ | ||
void tmp102_reg_read(uint8_t *data) | ||
{ | ||
i2c1_master_enable(); | ||
i2c1_send_start(); | ||
/*command to TMP102 to Write data on bus */ | ||
if(i2c1_byte_send (TMP102_REG_READ)) { | ||
printf("Failed the connection to Thermo3\n"); | ||
} | ||
i2c1_byte_receive(data); | ||
i2c1_byte_receive((data + 1)); | ||
i2c1_send_stop(); | ||
i2c1_master_disable(); | ||
} | ||
/*---------------------------------------------------------------------------*/ | ||
void tmp102_reg_write(uint8_t msb, uint8_t lsb) | ||
{ | ||
i2c1_master_enable(); | ||
i2c1_send_start(); | ||
/*command to TMP102 to Read data from bus */ | ||
i2c1_byte_send (TMP102_REG_WRITE); | ||
i2c1_byte_send(msb); | ||
i2c1_byte_send(lsb); | ||
i2c1_send_stop(); | ||
i2c1_master_disable(); | ||
} | ||
/*---------------------------------------------------------------------------*/ | ||
float tmp102_read_temp(void) | ||
{ | ||
uint8_t data[2] = { 0, 0 }; | ||
float temp_c = 0; | ||
tmp102_reg_read(data); | ||
/* data[1] having LSB of Temp. Register */ | ||
if(data[1] & 0x10) { | ||
temp_c += 0.06250; | ||
} | ||
if(data[1] & 0x20) { | ||
temp_c += 0.12500; | ||
} | ||
if(data[1] & 0x40) { | ||
temp_c += 0.25000; | ||
} | ||
if(data[1] & 0x80) { | ||
temp_c += 0.50000; | ||
} | ||
/* data[0] having MSB of Temp. Register */ | ||
if((data[0] & 0x80) != 0x80) { | ||
temp_c += ((float) data[0]); | ||
} | ||
if((data[0] & 0x80) == 0x80) { | ||
data[0] = data[0] - 0x01; | ||
data[0] = ~data[0]; | ||
temp_c = temp_c - ((float) data[0]); | ||
} | ||
return temp_c; | ||
} | ||
/*---------------------------------------------------------------------------*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated | ||
* group companies. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from this | ||
* software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
/** | ||
* \file | ||
* Thermo3 click driver. | ||
* http://www.mikroe.com/click/thermo3/ | ||
* | ||
*/ | ||
|
||
#ifndef __THERMO3_CLICK_H__ | ||
#define __THERMO3_CLICK_H__ | ||
|
||
#define I2C_FREQUENCY 100000 | ||
|
||
#define TMP102_REG_WRITE 0x90 | ||
/* TMP102 registers */ | ||
#define TMP102_TEMP 0x00 /* read only */ | ||
#define TMP102_CONF 0x01 | ||
#define TMP102_TLOW 0x02 | ||
#define TMP102_THIGH 0x03 | ||
|
||
#define TMP102_REG_READ 0x91 | ||
/*---------------------------------------------------------------------------*/ | ||
|
||
/*init the i2c bus as per TMP102*/ | ||
void tmp102_init(); | ||
|
||
/*gives value of temperatur in degrees celsius*/ | ||
float tmp102_read_temp(); | ||
|
||
/*every time before opration select proper register*/ | ||
void tmp102_reg_select(uint8_t ); | ||
|
||
/*reads selected register*/ | ||
void tmp102_reg_read(uint8_t *); | ||
|
||
/*write selected register except TMP102_TEMP*/ | ||
void tmp102_reg_write(uint8_t , uint8_t ); | ||
|
||
/*---------------------------------------------------------------------------*/ | ||
#endif /* __THERMO3_CLICK_H__ */ |