Skip to content

Commit d483adb

Browse files
author
Abhijit A. Mahajani
authored
Merge pull request #19 from mayank-sirotiya-imgtec/thremo_proximity
platform/mikro-e/dev:add Thermo3 click driver
2 parents e9c1f8d + 8c81c71 commit d483adb

File tree

6 files changed

+303
-0
lines changed

6 files changed

+303
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CONTIKI_PROJECT = test-thermo3
2+
CONTIKI = ../../../..
3+
4+
CFLAGS += -DTHERMO3_CLICK
5+
6+
APPS += thermo3-click
7+
APPDIRS += ../../dev
8+
9+
all: $(CONTIKI_PROJECT)
10+
xc32-bin2hex $(CONTIKI_PROJECT).$(TARGET)
11+
12+
distclean: cleanall
13+
14+
cleanall:
15+
rm -f symbols.*
16+
17+
include $(CONTIKI)/Makefile.include
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated
3+
* group companies.
4+
*
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
*
13+
* 2. Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* 3. Neither the name of the copyright holder nor the names of its
18+
* contributors may be used to endorse or promote products derived from this
19+
* software without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
* POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
/**
35+
* \file
36+
* A test application to get temperature form Thermo3 click board.
37+
* http://www.mikroe.com/click/thermo3/
38+
*/
39+
40+
#include <contiki.h>
41+
#include <stdio.h>
42+
#include "dev/common-clicks.h"
43+
44+
#define TEMP_REG 0x00 /*Temp. register Address*/
45+
#define CONFIG_REG 0x01 /*Config. register Address*/
46+
#define CONFIG_MSB 0x60 /*default value*/
47+
#define CONFIG_LSB 0xE0 /*Conversion rate is set to 8Hz*/
48+
/*---------------------------------------------------------------------------*/
49+
PROCESS(test_thermo3, "Test Thermo3 click");
50+
AUTOSTART_PROCESSES (&test_thermo3);
51+
/*---------------------------------------------------------------------------*/
52+
PROCESS_THREAD(test_thermo3, ev, data)
53+
{
54+
PROCESS_BEGIN();
55+
static double temp_c;
56+
static struct etimer et;
57+
tmp102_init();
58+
tmp102_reg_select(CONFIG_REG);
59+
tmp102_reg_write(CONFIG_MSB, CONFIG_LSB);
60+
tmp102_reg_select(TEMP_REG);
61+
while(1) {
62+
temp_c = 0;
63+
etimer_set(&et, CLOCK_SECOND);
64+
temp_c = tmp102_read_temp();
65+
printf("Temperature is %.3f degree celsius\n",temp_c);
66+
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
67+
}
68+
PROCESS_END();
69+
}
70+
/*---------------------------------------------------------------------------*/

platform/mikro-e/dev/common-clicks.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@
4040
#include "relay-click/relay-click.h"
4141
#endif
4242

43+
#ifdef THERMO3_CLICK
44+
#include "thermo3-click/thermo3-click.h"
45+
#endif
46+
4347
#endif /* __COMMON_CLICKS_H__ */
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
thermo3-click_src += thermo3-click.c
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated
3+
* group companies.
4+
*
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
*
13+
* 2. Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* 3. Neither the name of the copyright holder nor the names of its
18+
* contributors may be used to endorse or promote products derived from this
19+
* software without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
* POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
/**
35+
* \file
36+
* Thermo3 click driver.
37+
* http://www.mikroe.com/click/thermo3/
38+
*
39+
*/
40+
41+
#include <stdio.h>
42+
#include <stdint.h>
43+
#include <pic32_i2c.h>
44+
#include "thermo3-click.h"
45+
/*---------------------------------------------------------------------------*/
46+
void tmp102_init(void)
47+
{
48+
i2c1_init();
49+
i2c1_set_frequency (I2C_FREQUENCY);
50+
}
51+
/*---------------------------------------------------------------------------*/
52+
void tmp102_reg_select(uint8_t reg)
53+
{
54+
i2c1_master_enable();
55+
i2c1_send_start();
56+
if(i2c1_byte_send (TMP102_REG_WRITE)) {
57+
i2c1_send_repeated_start();
58+
if(i2c1_byte_send (TMP102_REG_WRITE)) {
59+
printf("Failed the connection to Thermo3\n");
60+
}
61+
}
62+
switch (reg) {
63+
case TMP102_TEMP:
64+
i2c1_byte_send (TMP102_TEMP);
65+
break;
66+
case TMP102_CONF:
67+
i2c1_byte_send (TMP102_CONF);
68+
break;
69+
case TMP102_TLOW:
70+
i2c1_byte_send (TMP102_TLOW);
71+
break;
72+
case TMP102_THIGH:
73+
i2c1_byte_send (TMP102_THIGH);
74+
break;
75+
default:
76+
printf("Invalid Register Address\n");
77+
break;
78+
}
79+
i2c1_send_stop();
80+
i2c1_master_disable();
81+
}
82+
/*---------------------------------------------------------------------------*/
83+
void tmp102_reg_read(uint8_t *data)
84+
{
85+
i2c1_master_enable();
86+
i2c1_send_start();
87+
/*command to TMP102 to Write data on bus */
88+
if(i2c1_byte_send (TMP102_REG_READ)) {
89+
printf("Failed the connection to Thermo3\n");
90+
}
91+
i2c1_byte_receive(data);
92+
i2c1_byte_receive((data + 1));
93+
i2c1_send_stop();
94+
i2c1_master_disable();
95+
}
96+
/*---------------------------------------------------------------------------*/
97+
void tmp102_reg_write(uint8_t msb, uint8_t lsb)
98+
{
99+
i2c1_master_enable();
100+
i2c1_send_start();
101+
/*command to TMP102 to Read data from bus */
102+
i2c1_byte_send (TMP102_REG_WRITE);
103+
i2c1_byte_send(msb);
104+
i2c1_byte_send(lsb);
105+
i2c1_send_stop();
106+
i2c1_master_disable();
107+
}
108+
/*---------------------------------------------------------------------------*/
109+
float tmp102_read_temp(void)
110+
{
111+
uint8_t data[2] = { 0, 0 };
112+
float temp_c = 0;
113+
tmp102_reg_read(data);
114+
/* data[1] having LSB of Temp. Register */
115+
if(data[1] & 0x10) {
116+
temp_c += 0.06250;
117+
}
118+
if(data[1] & 0x20) {
119+
temp_c += 0.12500;
120+
}
121+
if(data[1] & 0x40) {
122+
temp_c += 0.25000;
123+
}
124+
if(data[1] & 0x80) {
125+
temp_c += 0.50000;
126+
}
127+
/* data[0] having MSB of Temp. Register */
128+
if((data[0] & 0x80) != 0x80) {
129+
temp_c += ((float) data[0]);
130+
}
131+
if((data[0] & 0x80) == 0x80) {
132+
data[0] = data[0] - 0x01;
133+
data[0] = ~data[0];
134+
temp_c = temp_c - ((float) data[0]);
135+
}
136+
return temp_c;
137+
}
138+
/*---------------------------------------------------------------------------*/
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated
3+
* group companies.
4+
*
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
*
13+
* 2. Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* 3. Neither the name of the copyright holder nor the names of its
18+
* contributors may be used to endorse or promote products derived from this
19+
* software without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
* POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
/**
35+
* \file
36+
* Thermo3 click driver.
37+
* http://www.mikroe.com/click/thermo3/
38+
*
39+
*/
40+
41+
#ifndef __THERMO3_CLICK_H__
42+
#define __THERMO3_CLICK_H__
43+
44+
#define I2C_FREQUENCY 100000
45+
46+
#define TMP102_REG_WRITE 0x90
47+
/* TMP102 registers */
48+
#define TMP102_TEMP 0x00 /* read only */
49+
#define TMP102_CONF 0x01
50+
#define TMP102_TLOW 0x02
51+
#define TMP102_THIGH 0x03
52+
53+
#define TMP102_REG_READ 0x91
54+
/*---------------------------------------------------------------------------*/
55+
56+
/*init the i2c bus as per TMP102*/
57+
void tmp102_init();
58+
59+
/*gives value of temperatur in degrees celsius*/
60+
float tmp102_read_temp();
61+
62+
/*every time before opration select proper register*/
63+
void tmp102_reg_select(uint8_t );
64+
65+
/*reads selected register*/
66+
void tmp102_reg_read(uint8_t *);
67+
68+
/*write selected register except TMP102_TEMP*/
69+
void tmp102_reg_write(uint8_t , uint8_t );
70+
71+
/*---------------------------------------------------------------------------*/
72+
#endif /* __THERMO3_CLICK_H__ */

0 commit comments

Comments
 (0)