Mercurial > public > hwos_code
comparison src/i2c.asm @ 427:ceb1b7329dce
add code for new compass chip
author | heinrichsweikamp |
---|---|
date | Tue, 14 Jun 2016 13:02:17 +0200 |
parents | 653a3ab08062 |
children | 4b93354b7738 |
comparison
equal
deleted
inserted
replaced
426:8f8151bb53bb | 427:ceb1b7329dce |
---|---|
7 ; HMC5883L's read address (8-Bit): 0x3D | 7 ; HMC5883L's read address (8-Bit): 0x3D |
8 ; HMC5883L's write address (8-Bit): 0x3C | 8 ; HMC5883L's write address (8-Bit): 0x3C |
9 ; | 9 ; |
10 ; MMA8452Q's read address (8-Bit): 0x39 | 10 ; MMA8452Q's read address (8-Bit): 0x39 |
11 ; MMA8452Q's write address (8-Bit): 0x38 | 11 ; MMA8452Q's write address (8-Bit): 0x38 |
12 ; | |
13 ; LSM303D's read address (8-Bit): 0x3D | |
14 ; LSM303D's write address (8-Bit): 0x3C | |
12 ; | 15 ; |
13 ; Copyright (c) 2012, JD Gascuel, HeinrichsWeikamp, all right reserved. | 16 ; Copyright (c) 2012, JD Gascuel, HeinrichsWeikamp, all right reserved. |
14 ;============================================================================= | 17 ;============================================================================= |
15 ; HISTORY | 18 ; HISTORY |
16 ; 2012-08-22 : [mH] Creation | 19 ; 2012-08-22 : [mH] Creation |
98 I2C_TwoBytesRX_div16_2: ; devide lo:hi/16 (signed) only | 101 I2C_TwoBytesRX_div16_2: ; devide lo:hi/16 (signed) only |
99 bcf STATUS,C | 102 bcf STATUS,C |
100 btfsc hi,7 ; Copy sign bit to carry | 103 btfsc hi,7 ; Copy sign bit to carry |
101 bsf STATUS,C | 104 bsf STATUS,C |
102 rrcf hi ; /2 | 105 rrcf hi ; /2 |
103 rrcf lo | 106 rrcf lo |
107 I2C_TwoBytesRX_div8_2: ; devide lo:hi/8 (signed) only | |
104 bcf STATUS,C | 108 bcf STATUS,C |
105 btfsc hi,7 ; Copy sign bit to carry | 109 btfsc hi,7 ; Copy sign bit to carry |
106 bsf STATUS,C | 110 bsf STATUS,C |
107 rrcf hi ; /4 | 111 rrcf hi ; /4 |
108 rrcf lo | 112 rrcf lo |
109 bcf STATUS,C | 113 bcf STATUS,C |
110 btfsc hi,7 ; Copy sign bit to carry | 114 btfsc hi,7 ; Copy sign bit to carry |
111 bsf STATUS,C | 115 bsf STATUS,C |
112 rrcf hi ; /8 | 116 rrcf hi ; /8 |
113 rrcf lo | 117 rrcf lo |
118 rrcf lo | 122 rrcf lo |
119 return | 123 return |
120 | 124 |
121 global I2C_RX_accelerometer | 125 global I2C_RX_accelerometer |
122 I2C_RX_accelerometer: | 126 I2C_RX_accelerometer: |
123 bsf SSP1CON2,SEN ; Start condition | 127 btfsc compass_type ; compass1? |
124 rcall WaitMSSP | 128 bra I2C_RX_accelerometer_compass1 ; yes |
125 movlw 0x38 ; address | 129 ;I2C_RX_accelerometer_compass0: |
126 rcall I2C_TX | 130 bsf SSP1CON2,SEN ; Start condition |
127 movlw 0x00 | 131 rcall WaitMSSP |
128 rcall I2C_TX | 132 movlw 0x38 ; address |
129 bsf SSP1CON2,RSEN ; Repeated start condition (!) | 133 rcall I2C_TX |
130 rcall WaitMSSP | 134 movlw 0x00 |
131 movlw 0x39 ; address | 135 rcall I2C_TX |
136 bsf SSP1CON2,RSEN ; Repeated start condition (!) | |
137 rcall WaitMSSP | |
138 movlw 0x39 ; address | |
132 rcall I2C_TX | 139 rcall I2C_TX |
133 | 140 |
134 rcall I2C_OneByteRX ; Get Status Byte | 141 rcall I2C_OneByteRX ; Get Status Byte |
135 movf SSP1BUF,W | 142 movf SSP1BUF,W |
136 | 143 |
187 | 194 |
188 bsf SSP1CON2,PEN ; Stop condition | 195 bsf SSP1CON2,PEN ; Stop condition |
189 rcall WaitMSSP | 196 rcall WaitMSSP |
190 return | 197 return |
191 | 198 |
199 I2C_RX_accelerometer_compass1: | |
200 bsf SSP1CON2,SEN ; Start condition | |
201 rcall WaitMSSP | |
202 movlw 0x3C ; address | |
203 rcall I2C_TX | |
204 movlw b'10101000' ; 0x28 with auto-increment (MSB=1) | |
205 rcall I2C_TX | |
206 bsf SSP1CON2,RSEN ; Repeated start condition (!) | |
207 rcall WaitMSSP | |
208 movlw 0x3D ; address | |
209 rcall I2C_TX | |
210 | |
211 ; Non-flipped screen: | |
212 ; Chip orientation on the PCB requires | |
213 ; Original = Corrected | |
214 ; x = -x | |
215 ; y = -y | |
216 ; z = -z | |
217 | |
218 ; Flipped screen: | |
219 ; Chip orientation on the PCB requires | |
220 ; Original = Corrected | |
221 ; x = x | |
222 ; y = y | |
223 ; z = -z | |
224 | |
225 ; Dump the accelerator data | |
226 rcall I2C_OneByteRX | |
227 movff SSP1BUF,lo ;accel_DX+0 | |
228 rcall I2C_OneByteRX | |
229 movff SSP1BUF,hi ;accel_DX+1 | |
230 rcall I2C_TwoBytesRX_div16_2; devide lo:hi/16 (signed) only | |
231 btfsc flip_screen ; 180° rotation ? | |
232 bra I2C_RX_accelerometer2_c1 ; Yes | |
233 comf hi ; 16bit sign change. | |
234 negf lo | |
235 btfsc STATUS,C ; Carry to propagate ? | |
236 incf hi,F ; YES: do it. | |
237 I2C_RX_accelerometer2_c1: | |
238 movff lo,accel_DX+0 | |
239 movff hi,accel_DX+1 ; Copy result | |
240 | |
241 rcall I2C_OneByteRX | |
242 movff SSP1BUF,lo ;accel_DY+0 | |
243 rcall I2C_OneByteRX | |
244 movff SSP1BUF,hi ;accel_DY+1 | |
245 | |
246 rcall I2C_TwoBytesRX_div16_2; devide lo:hi/16 (signed) only | |
247 btfsc flip_screen ; 180° rotation ? | |
248 bra I2C_RX_accelerometer3_c1 ; Yes | |
249 comf hi ; 16bit sign change. | |
250 negf lo | |
251 btfsc STATUS,C ; Carry to propagate ? | |
252 incf hi,F ; YES: do it. | |
253 I2C_RX_accelerometer3_c1: | |
254 movff lo,accel_DY+0 | |
255 movff hi,accel_DY+1 ; Copy result | |
256 | |
257 rcall I2C_OneByteRX | |
258 movff SSP1BUF,lo ;accel_DZ+0 | |
259 bsf SSP1CON2, RCEN ; Enable recieve mode | |
260 rcall WaitMSSP | |
261 ; According to datasheet there should be no Master Acknowlegde for the last Byte (accel_DZ+1)... | |
262 movff SSP1BUF,hi ;accel_DZ+1 | |
263 bsf SSP1CON2,PEN ; Stop condition | |
264 rcall WaitMSSP | |
265 rcall I2C_TwoBytesRX_div16_2; devide lo:hi/16 (signed) only | |
266 comf hi ; 16bit sign change for Z | |
267 negf lo | |
268 btfsc STATUS,C ; Carry to propagate ? | |
269 incf hi,F ; YES: do it. | |
270 movff lo,accel_DZ+0 | |
271 movff hi,accel_DZ+1 ; Copy result | |
272 return | |
273 | |
192 I2C_OneByteRX: | 274 I2C_OneByteRX: |
193 bsf SSP1CON2, RCEN ; Enable recieve mode | 275 bsf SSP1CON2, RCEN ; Enable recieve mode |
194 rcall WaitMSSP | 276 rcall WaitMSSP |
195 bsf SSP1CON2,ACKEN ; Master acknowlegde | 277 bsf SSP1CON2,ACKEN ; Master acknowlegde |
196 rcall WaitMSSP | 278 bra WaitMSSP ; And return! |
197 return | |
198 | 279 |
199 global I2C_RX_compass | 280 global I2C_RX_compass |
200 I2C_RX_compass: | 281 I2C_RX_compass: |
201 bsf SSP1CON2,SEN ; Start condition | 282 btfsc compass_type ; compass1? |
202 rcall WaitMSSP | 283 bra I2C_RX_compass1 ; yes |
203 movlw 0x3C ; address | 284 ;I2C_RX_compass0: |
204 rcall I2C_TX | 285 bsf SSP1CON2,SEN ; Start condition |
205 movlw 0x03 | 286 rcall WaitMSSP |
206 rcall I2C_TX | 287 movlw 0x3C ; address |
207 bsf SSP1CON2,PEN ; Stop condition | 288 rcall I2C_TX |
208 rcall WaitMSSP | 289 movlw 0x03 |
209 | 290 rcall I2C_TX |
210 bcf PIR1,SSPIF | 291 bsf SSP1CON2,PEN ; Stop condition |
211 bsf SSP1CON2,SEN ; Start condition | 292 rcall WaitMSSP |
212 rcall WaitMSSP | 293 |
213 movlw 0x3D ; address | 294 bcf PIR1,SSPIF |
295 bsf SSP1CON2,SEN ; Start condition | |
296 rcall WaitMSSP | |
297 movlw 0x3D ; address | |
214 rcall I2C_TX | 298 rcall I2C_TX |
215 | 299 |
216 ; Compass IC sends data in following order: | 300 ; Compass IC sends data in following order: |
217 ; x MSB | 301 ; x MSB |
218 ; x LSB | 302 ; x LSB |
247 btfsc STATUS,C ; Carry to propagate ? | 331 btfsc STATUS,C ; Carry to propagate ? |
248 incf compass_DY+1,F ; YES: do it. | 332 incf compass_DY+1,F ; YES: do it. |
249 I2C_RX_compass2: | 333 I2C_RX_compass2: |
250 banksel common | 334 banksel common |
251 rcall I2C_OneByteRX ; Get one byte | 335 rcall I2C_OneByteRX ; Get one byte |
252 movff SSP1BUF,compass_DZ+1; Data Byte | 336 movff SSP1BUF,compass_DZ+1; Data Byte |
253 rcall I2C_OneByteRX ; Get one byte | 337 rcall I2C_OneByteRX ; Get one byte |
254 movff SSP1BUF,compass_DZ+0; Data Byte | 338 movff SSP1BUF,compass_DZ+0; Data Byte |
255 rcall I2C_OneByteRX ; Get one byte | 339 rcall I2C_OneByteRX ; Get one byte |
256 movff SSP1BUF,compass_DX+1; Data Byte | 340 movff SSP1BUF,compass_DX+1; Data Byte |
257 bsf SSP1CON2, RCEN ; Enable recieve mode | 341 bsf SSP1CON2, RCEN ; Enable recieve mode |
258 rcall WaitMSSP | 342 rcall WaitMSSP |
259 movff SSP1BUF,compass_DX+0; Data Byte | 343 movff SSP1BUF,compass_DX+0; Data Byte |
260 bsf SSP1CON2,PEN ; Stop condition | 344 bsf SSP1CON2,PEN ; Stop condition |
261 rcall WaitMSSP | 345 rcall WaitMSSP |
262 btfss flip_screen ; 180° rotation ? | 346 btfss flip_screen ; 180° rotation ? |
263 return ; No, done. | 347 return ; No, done. |
264 ; Yes, flip X | 348 ; Yes, flip X |
265 banksel compass_DX | 349 banksel compass_DX |
266 comf compass_DX+1 ; 16bit sign change. | 350 comf compass_DX+1 ; 16bit sign change. |
267 negf compass_DX+0 | 351 negf compass_DX+0 |
268 btfsc STATUS,C ; Carry to propagate ? | 352 btfsc STATUS,C ; Carry to propagate ? |
269 incf compass_DX+1,F ; YES: do it. | 353 incf compass_DX+1,F ; YES: do it. |
270 banksel common | 354 banksel common |
271 return | 355 return |
356 | |
357 I2C_RX_compass1: ; New compass | |
358 bsf SSP1CON2,SEN ; Start condition | |
359 rcall WaitMSSP | |
360 movlw 0x3C ; address | |
361 rcall I2C_TX | |
362 movlw b'10001000' ; 0x08 with auto-increment (MSB=1) | |
363 rcall I2C_TX | |
364 bsf SSP1CON2,RSEN ; Repeated start condition (!) | |
365 rcall WaitMSSP | |
366 movlw 0x3D ; address | |
367 rcall I2C_TX | |
368 | |
369 rcall I2C_OneByteRX ; Get one byte | |
370 movff SSP1BUF,lo ; Data Byte | |
371 rcall I2C_OneByteRX ; Get one byte | |
372 movff SSP1BUF,hi ; Data Byte | |
373 rcall I2C_TwoBytesRX_div8_2 | |
374 movff lo,compass_DX+0 | |
375 movff hi,compass_DX+1 | |
376 btfss flip_screen ; 180° rotation ? | |
377 bra I2C_RX_compass1_1 ; Yes | |
378 ; Yes, flip X | |
379 banksel compass_DX | |
380 comf compass_DX+1 ; 16bit sign change. | |
381 negf compass_DX+0 | |
382 btfsc STATUS,C ; Carry to propagate ? | |
383 incf compass_DX+1,F ; YES: do it. | |
384 banksel common | |
385 I2C_RX_compass1_1: | |
386 rcall I2C_OneByteRX ; Get one byte | |
387 movff SSP1BUF,lo ; Data Byte | |
388 rcall I2C_OneByteRX ; Get one byte | |
389 movff SSP1BUF,hi ; Data Byte | |
390 rcall I2C_TwoBytesRX_div8_2 | |
391 movff lo,compass_DY+0 | |
392 movff hi,compass_DY+1 | |
393 btfss flip_screen ; 180° rotation ? | |
394 bra I2C_RX_compass1_2 ; Yes | |
395 ; Yes, flip Y | |
396 banksel compass_DY | |
397 comf compass_DY+1 ; 16bit sign change. | |
398 negf compass_DY+0 | |
399 btfsc STATUS,C ; Carry to propagate ? | |
400 incf compass_DY+1,F ; YES: do it. | |
401 I2C_RX_compass1_2: | |
402 banksel common | |
403 rcall I2C_OneByteRX ; Get one byte | |
404 movff SSP1BUF,lo ; Data Byte | |
405 bsf SSP1CON2, RCEN ; Enable recieve mode | |
406 rcall WaitMSSP | |
407 movff SSP1BUF,hi ; Data Byte | |
408 rcall I2C_TwoBytesRX_div8_2 | |
409 movff lo,compass_DZ+0 | |
410 movff hi,compass_DZ+1 | |
411 bsf SSP1CON2,PEN ; Stop condition | |
412 rcall WaitMSSP | |
413 return | |
272 | 414 |
273 global I2C_init_compass | 415 global I2C_init_compass |
274 I2C_init_compass: | 416 I2C_init_compass: |
275 bsf SSP1CON2,SEN ; Start condition | 417 bsf compass_enabled |
276 rcall WaitMSSP | 418 bsf compass_type ; set flag |
277 movlw 0x3C ; address | 419 bsf SSP1CON2,SEN ; Start condition |
278 rcall I2C_TX | 420 rcall WaitMSSP |
279 movlw 0x00 | 421 movlw 0x3C ; address |
280 rcall I2C_TX | 422 rcall I2C_TX |
281 ; movlw b'01101001' ; ConfigA: 3Hz, 8 Samples averaged, Test Mode (Positive Bias) | 423 movlw 0x0F |
282 movlw b'01101000' ; ConfigA: 3Hz, 8 Samples averaged | 424 rcall I2C_TX |
425 bsf SSP1CON2,PEN ; Stop condition | |
426 rcall WaitMSSP | |
427 bcf PIR1,SSPIF | |
428 bsf SSP1CON2,SEN ; Start condition | |
429 rcall WaitMSSP | |
430 movlw 0x3D ; address | |
431 rcall I2C_TX | |
432 rcall I2C_OneByteRX ; Get one byte | |
433 movlw 0x49 ; 0x49 = Compass1 | |
434 cpfseq SSP1BUF | |
435 bcf compass_type ; clear flag | |
436 bsf SSP1CON2,PEN ; Stop condition | |
437 rcall WaitMSSP | |
438 | |
439 btfsc compass_type ; compass1? | |
440 bra I2C_init_compass1 ; yes | |
441 ; init compass0 | |
442 bsf SSP1CON2,SEN ; Start condition | |
443 rcall WaitMSSP | |
444 movlw 0x3C ; address | |
445 rcall I2C_TX | |
446 movlw 0x00 | |
447 rcall I2C_TX | |
448 ; movlw b'01101001' ; ConfigA: 3Hz, 8 Samples averaged, Test Mode (Positive Bias) | |
449 movlw b'01101000' ; ConfigA: 3Hz, 8 Samples averaged | |
283 rcall I2C_TX | 450 rcall I2C_TX |
284 bra I2C_init_compass_common | 451 bra I2C_init_compass_common |
285 | 452 |
286 global I2C_init_compass_fast | 453 global I2C_init_compass_fast |
287 I2C_init_compass_fast: | 454 I2C_init_compass_fast: |
288 bsf SSP1CON2,SEN ; Start condition | 455 btfsc compass_type ; compass1? |
289 rcall WaitMSSP | 456 bra I2C_init_compass_fast1 ; yes |
290 movlw 0x3C ; address | 457 ;I2C_init_compass_fast0: |
291 rcall I2C_TX | 458 bsf SSP1CON2,SEN ; Start condition |
292 movlw 0x00 | 459 rcall WaitMSSP |
293 rcall I2C_TX | 460 movlw 0x3C ; address |
294 movlw b'00111000' ; ConfigA: 75Hz, 2 Samples averaged | 461 rcall I2C_TX |
295 ; movlw b'00111001' ; ConfigA: 75Hz, 2 Samples averaged, Test Mode (Positive Bias) | 462 movlw 0x00 |
463 rcall I2C_TX | |
464 movlw b'00111000' ; ConfigA: 75Hz, 2 Samples averaged | |
465 ; movlw b'00111001' ; ConfigA: 75Hz, 2 Samples averaged, Test Mode (Positive Bias) | |
296 rcall I2C_TX | 466 rcall I2C_TX |
297 I2C_init_compass_common: | 467 I2C_init_compass_common: |
298 movff opt_compass_gain,i2c_temp ; 0-7 (230LSB/Gauss to 1370LSB/Gaus) | 468 movff opt_compass_gain,i2c_temp ; 0-7 (230LSB/Gauss to 1370LSB/Gauss) |
299 swapf i2c_temp,F | 469 swapf i2c_temp,F |
300 comf i2c_temp,F | 470 comf i2c_temp,F |
301 bcf STATUS,C | 471 bcf STATUS,C |
302 rlcf i2c_temp | 472 rlcf i2c_temp |
303 movf i2c_temp,W | 473 movf i2c_temp,W |
304 clrf i2c_temp | 474 clrf i2c_temp |
305 rcall I2C_TX | 475 rcall I2C_TX |
306 movlw b'00000000' ; Continous Mode | 476 movlw b'00000000' ; Continous Mode |
307 rcall I2C_TX | 477 rcall I2C_TX |
308 bsf SSP1CON2,PEN ; Stop condition | 478 bsf SSP1CON2,PEN ; Stop condition |
309 rcall WaitMSSP | 479 rcall WaitMSSP |
310 bsf compass_enabled | 480 return |
311 return | 481 |
312 | 482 I2C_init_compass1: |
483 bsf SSP1CON2,SEN ; Start condition | |
484 rcall WaitMSSP | |
485 movlw 0x3C ; address | |
486 rcall I2C_TX | |
487 movlw 0x9F ; 1F with auto-increment (MSB=1) | |
488 rcall I2C_TX | |
489 movlw b'00000000' ; CTRL0 | |
490 rcall I2C_TX | |
491 movlw b'00101111' ; CTRL1 (6,25Hz, BDU=0, x,y,z = ON) | |
492 rcall I2C_TX | |
493 movlw b'11000000' ; CTRL2 (50Hz, +/-2g, | |
494 rcall I2C_TX | |
495 movlw b'00000000' ; CTRL3 | |
496 rcall I2C_TX | |
497 movlw b'00000000' ; CTRL4 | |
498 rcall I2C_TX | |
499 movlw b'01100100' ; CTRL5 HIGH res, 6,25Hz | |
500 rcall I2C_TX | |
501 ;movlw b'01100000' ; CTRL6 Full scale (+/-12 Gauss -> 2730LSB/Gauss) | |
502 movlw b'00000000' ; CTRL6 (+/-2 Gauss) | |
503 rcall I2C_TX | |
504 movlw b'00000000' ; CTRL7 Continuous Mode | |
505 rcall I2C_TX | |
506 bsf SSP1CON2,PEN ; Stop condition | |
507 rcall WaitMSSP | |
508 return | |
509 | |
510 I2C_init_compass_fast1: | |
511 bsf SSP1CON2,SEN ; Start condition | |
512 rcall WaitMSSP | |
513 movlw 0x3C ; address | |
514 rcall I2C_TX | |
515 movlw 0x9F ; 1F with auto-increment (MSB=1) | |
516 rcall I2C_TX | |
517 movlw b'00000000' ; CTRL0 | |
518 rcall I2C_TX | |
519 movlw b'01101111' ; CTRL1 (100Hz, BDU=0, x,y,z = ON) | |
520 rcall I2C_TX | |
521 movlw b'11000000' ; CTRL2 (50Hz, +/-2g, | |
522 rcall I2C_TX | |
523 movlw b'00000000' ; CTRL3 | |
524 rcall I2C_TX | |
525 movlw b'00000000' ; CTRL4 | |
526 rcall I2C_TX | |
527 movlw b'01110100' ; CTRL5 HIGH res, 100Hz | |
528 rcall I2C_TX | |
529 movlw b'01100000' ; CTRL6 Full scale (+/-12 Gauss -> 2730LSB/Gauss) | |
530 rcall I2C_TX | |
531 movlw b'00000000' ; CTRL7 Continuous Mode | |
532 rcall I2C_TX | |
533 bsf SSP1CON2,PEN ; Stop condition | |
534 rcall WaitMSSP | |
535 return | |
536 | |
313 global I2C_sleep_compass | 537 global I2C_sleep_compass |
314 I2C_sleep_compass: | 538 I2C_sleep_compass: |
315 bsf SSP1CON2,SEN ; Start condition | |
316 rcall WaitMSSP | |
317 movlw 0x3C ; address | |
318 rcall I2C_TX | |
319 movlw 0x00 | |
320 rcall I2C_TX | |
321 movlw b'01101000' ; ConfigA | |
322 rcall I2C_TX | |
323 movlw b'00100000' ; ConfigB | |
324 rcall I2C_TX | |
325 movlw b'00000010' ; Idle Mode | |
326 rcall I2C_TX | |
327 bsf SSP1CON2,PEN ; Stop condition | |
328 rcall WaitMSSP | |
329 bcf compass_enabled | 539 bcf compass_enabled |
330 return | 540 |
331 | 541 btfsc compass_type ; compass1? |
542 bra I2C_sleep_compass1 ; yes | |
543 ;I2C_sleep_compass0: | |
544 bsf SSP1CON2,SEN ; Start condition | |
545 rcall WaitMSSP | |
546 movlw 0x3C ; address | |
547 rcall I2C_TX | |
548 movlw 0x00 | |
549 rcall I2C_TX | |
550 movlw b'01101000' ; ConfigA | |
551 rcall I2C_TX | |
552 movlw b'00100000' ; ConfigB | |
553 rcall I2C_TX | |
554 movlw b'00000010' ; Idle Mode | |
555 rcall I2C_TX | |
556 bsf SSP1CON2,PEN ; Stop condition | |
557 rcall WaitMSSP | |
558 return | |
559 | |
560 I2C_sleep_compass1: | |
561 bsf SSP1CON2,SEN ; Start condition | |
562 rcall WaitMSSP | |
563 movlw 0x3C ; address | |
564 rcall I2C_TX | |
565 movlw 0x20 ; CTRL_REG1 | |
566 rcall I2C_TX | |
567 movlw b'00000000' ; data for CTRL_REG1: acceleration sensor Power-down mode | |
568 rcall I2C_TX | |
569 bsf SSP1CON2,PEN ; Stop condition | |
570 rcall WaitMSSP | |
571 bsf SSP1CON2,SEN ; Start condition | |
572 rcall WaitMSSP | |
573 movlw 0x3C ; address | |
574 rcall I2C_TX | |
575 movlw 0x26 ; CTRL_REG7 | |
576 rcall I2C_TX | |
577 movlw b'00000010' ; data for CTRL_REG7: magnetic sensor Power-down mode | |
578 rcall I2C_TX | |
579 bsf SSP1CON2,PEN ; Stop condition | |
580 rcall WaitMSSP | |
581 return | |
582 | |
332 | 583 |
333 global I2C_init_accelerometer | 584 global I2C_init_accelerometer |
334 I2C_init_accelerometer: | 585 I2C_init_accelerometer: |
586 btfsc compass_type ; compass1? | |
587 return ; yes, ignore | |
588 | |
335 rcall I2C_sleep_accelerometer ; Regs can only be changed in St.By mode | 589 rcall I2C_sleep_accelerometer ; Regs can only be changed in St.By mode |
336 | 590 |
337 bsf SSP1CON2,SEN ; Start condition | 591 bsf SSP1CON2,SEN ; Start condition |
338 rcall WaitMSSP | 592 rcall WaitMSSP |
339 movlw 0x38 ; address | 593 movlw 0x38 ; address |
374 | 628 |
375 return | 629 return |
376 | 630 |
377 global I2C_sleep_accelerometer | 631 global I2C_sleep_accelerometer |
378 I2C_sleep_accelerometer: | 632 I2C_sleep_accelerometer: |
633 btfsc compass_type ; compass1? | |
634 return ; yes, ignore | |
635 | |
379 bsf SSP1CON2,SEN ; Start condition | 636 bsf SSP1CON2,SEN ; Start condition |
380 rcall WaitMSSP | 637 rcall WaitMSSP |
381 movlw 0x38 ; address | 638 movlw 0x38 ; address |
382 rcall I2C_TX | 639 rcall I2C_TX |
383 movlw 0x2A ; CTRL_REG1 | 640 movlw 0x2A ; CTRL_REG1 |
580 rcall WaitMSSP | 837 rcall WaitMSSP |
581 rcall I2C_WaitforACK | 838 rcall I2C_WaitforACK |
582 bsf SSP1CON2, RCEN ; Enable recieve mode | 839 bsf SSP1CON2, RCEN ; Enable recieve mode |
583 rcall WaitMSSP | 840 rcall WaitMSSP |
584 return | 841 return |
585 | 842 |
586 | 843 |
587 | 844 END |
588 END |