Commit 58bc12b6d64e71504d85d2247e5f29ffba0be45e

Authored by Imanol-Mikel Barba Sabariego
1 parent 176fff61

--no commit message

Project/applications/smartcities/i2c.c
... ... @@ -111,14 +111,11 @@ void I2C_stop(I2C_TypeDef* I2Cx)
111 111  
112 112 uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address)
113 113 {
114   - printf("I2C busy...\r\n");
115 114 while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY))
116 115 {
117 116 // wait until I2C1 is not busy any more
118 117 }
119   - printf("I2C ready...\r\n");
120 118 I2C_GenerateSTART(I2Cx, ENABLE);
121   - printf("START RELEASED...\r\n");
122 119 while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT))
123 120 {
124 121 // wait for I2C1 EV5 --> Slave has acknowledged start condition
... ... @@ -128,17 +125,12 @@ uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address)
128 125 chThdSleepMilliseconds(SCAN_TIMEOUT);
129 126 if(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
130 127 {
131   - printf("I2C address not detected: %x\r\n", address);
132 128 return 1;
133 129 }
134 130 printf("I2C address detected: %x\r\n", address);
135 131 I2C_write(I2C1,0x00);
136 132 I2C_stop(I2C1);
137 133 return 0;
138   - /*while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
139   - {
140   - // wait for I2Cx EV6, check if Slave has acknowledged Master receiver mode
141   - }*/
142 134 }
143 135  
144 136 void I2C_scan(uint8_t *addresses)
... ... @@ -149,7 +141,6 @@ void I2C_scan(uint8_t *addresses)
149 141 {
150 142 if(!I2C_check(I2C1,sensors[i] << 1))
151 143 {
152   - printf("adding...\r\n");
153 144 addresses[j++] = sensors[i];
154 145 }
155 146 else
... ... @@ -159,45 +150,4 @@ void I2C_scan(uint8_t *addresses)
159 150 I2C_init();
160 151 }
161 152 }
162   -}
163   -
164   -/* SAMPLE CODE BMP-085
165   - *
166   - uint16_t received_data;
167   - char answer[10];
168   - int32_t UT, X1, X2, B5; // following ds convention
169   - float t;
170   - bmp085_calib_data _bmp085_coeffs;
171   -
172   - printf("Hello\r\n");
173   - I2C_init();
174   -
175   - printf("I2C Initialized\r\n");
176   - I2C_start(I2C1,SLAVE_ADDRESS << 1, I2C_Direction_Transmitter);
177   - printf("I2C First write\r\n");
178   - I2C_write(I2C1, 0xF4);
179   - printf("I2C Second write\r\n");
180   - I2C_write(I2C1, 0x2E);
181   - printf("I2C stop\r\n");
182   - I2C_stop(I2C1);
183   - printf("I2C Temperature measurment started\r\n");
184   -
185   - I2C_start(I2C1,SLAVE_ADDRESS << 1, I2C_Direction_Transmitter);
186   - printf("I2C First write\r\n");
187   - I2C_write(I2C1, 0xF6);
188   - printf("I2C stop\r\n");
189   - I2C_stop(I2C1);
190   - printf("I2C Temperature measurment request sent\r\n");
191   -
192   - I2C_start(I2C1, SLAVE_ADDRESS<<1, I2C_Direction_Receiver);
193   - printf("I2C Read request sent\r\n");
194   - received_data = I2C_read_ack(I2C1);
195   - received_data = received_data << 8;
196   - received_data = received_data | I2C_read_ack(I2C1);
197   - printf("I2C data received\r\n");
198   -
199   - sprintf(answer,"%d",received_data);
200   - printf("Data: %s\r\n",answer);
201   -
202   - * --Imanol
203   - */
  153 +}
204 154 \ No newline at end of file
... ...
Project/applications/smartcities/include/sensors.h
... ... @@ -11,7 +11,7 @@
11 11 #define LIGHT_ADDR 0x39
12 12 #define DISTANCE_ADDR 0x01
13 13 #define PRESSURE_ADDR 0x77
14   -#define HUMIDITY_TEMP_ADDR 0x00
  14 +#define HUMIDITY_TEMP_ADDR 0x27
15 15 //REMEMBER TO UPDATE I2C_scan ROUTINE WITH EACH NEW SENSOR!!!!
16 16 #define TOTAL_SENSORS 4
17 17  
... ... @@ -63,4 +63,10 @@ bmp085_callibration get_pressure_callibration_data(void);
63 63 char* callibration_pressure_data_csv(bmp085_callibration parameters);
64 64 void init_pressure(void);
65 65  
  66 +//HUMIDITY AND TEMPERATURE SENSOR
  67 +
  68 +void init_humidity_temp(void);
  69 +uint16_t get_humidity_data(void);
  70 +uint16_t get_temperature_data(void);
  71 +
66 72 #endif
... ...
Project/applications/smartcities/sensors.c
... ... @@ -230,3 +230,32 @@ void init_pressure(void)
230 230  
231 231 chThdSleepMilliseconds(5);
232 232 }
  233 +
  234 +void init_humidity_temp(void)
  235 +{
  236 + I2C_start(I2C1,HUMIDITY_TEMP_ADDR << 1, I2C_Direction_Transmitter);
  237 + I2C_stop(I2C1);
  238 +}
  239 +uint16_t get_humidity_data(void)
  240 +{
  241 + uint16_t data = 0;
  242 + I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Receiver);
  243 + data = I2C_read_ack(I2C1) & 0x3F;
  244 + data = data << 8;
  245 + data |= I2C_read_nack(I2C1);
  246 + I2C_stop(I2C1);
  247 + return data;
  248 +}
  249 +uint16_t get_temperature_data(void)
  250 +{
  251 + uint16_t data = 0;
  252 + I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Receiver);
  253 + I2C_read_ack(I2C1);
  254 + I2C_read_ack(I2C1);
  255 + data = I2C_read_ack(I2C1);
  256 + data = data << 8;
  257 + data |= I2C_read_nack(I2C1) & 0xFC ;
  258 + data = data >> 2;
  259 + I2C_stop(I2C1);
  260 + return data;
  261 +}
... ...