annotate src/i2c.asm @ 626:be8787f2034d

compass3 support for 3.01 branch
author heinrichsweikamp
date Sun, 23 Jun 2019 15:21:16 +0200
parents 1ad0531e9078
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
3 ; File i2c.asm
0
heinrichsweikamp
parents:
diff changeset
4 ;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
5 ; I2C Interface
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
6 ;
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
7 ; Compass0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
8 ; HMC5883L's read address (8-Bit): 0x3D
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
9 ; HMC5883L's write address (8-Bit): 0x3C
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
10 ; MMA8452Q's read address (8-Bit): 0x39
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
11 ; MMA8452Q's write address (8-Bit): 0x38
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
12 ;
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
13 ; Compass1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
14 ; LSM303D's read address (8-Bit): 0x3D
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
15 ; LSM303D's write address (8-Bit): 0x3C
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
16 ;
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
17 ; Compass2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
18 ; LSM303AGR's Compass read address (8-Bit): 0x3D
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
19 ; LSM303AGR's Compass write address (8-Bit): 0x3C
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
20 ; LSM303AGR's Acceleration read address (8-Bit): 0x33
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
21 ; LSM303AGR's Acceleration write address (8-Bit): 0x32
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
22 ;
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
23 ; Compass3
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
24 ; LSM303C's Compass read address (8-Bit): 0x3D
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
25 ; LSM303C's Compass write address (8-Bit): 0x3C
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
26 ; LSM303C's Acceleration read address (8-Bit): 0x3B
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
27 ; LSM303C's Acceleration write address (8-Bit): 0x3A
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
28 ;
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
29 ; RX Circuity
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
30 ; RX Circuity read address (8-Bit): 0x51
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
31 ; RX Circuity write address (8-Bit): 0x50
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
32 ;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
33 ;
0
heinrichsweikamp
parents:
diff changeset
34 ; Copyright (c) 2012, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
35 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
36 ; HISTORY
heinrichsweikamp
parents:
diff changeset
37 ; 2012-08-22 : [mH] Creation
heinrichsweikamp
parents:
diff changeset
38
heinrichsweikamp
parents:
diff changeset
39
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
40 #include "hwos.inc" ; Mandatory header
0
heinrichsweikamp
parents:
diff changeset
41 #include "wait.inc"
113
heinrichsweikamp
parents: 20
diff changeset
42 #include "math.inc"
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
43 #include "external_flash.inc"
113
heinrichsweikamp
parents: 20
diff changeset
44
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
45 i2c CODE
0
heinrichsweikamp
parents:
diff changeset
46
heinrichsweikamp
parents:
diff changeset
47 I2C_TX:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
48 movwf SSP1BUF
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
49 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
50 bra I2C_WaitforACK ; Returns...
0
heinrichsweikamp
parents:
diff changeset
51
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
52 I2C_TwoBytesRX_div16: ; Get two bytes and devide lo:hi/16 (signed)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
53 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
54 movff SSP1BUF,hi ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
55 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
56 movff SSP1BUF,lo ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
57 I2C_TwoBytesRX_div16_2: ; devide lo:hi/16 (signed) only
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
58 bcf STATUS,C
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
59 btfsc hi,7 ; Copy sign bit to carry
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
60 bsf STATUS,C
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
61 rrcf hi ; /2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
62 rrcf lo
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
63 I2C_TwoBytesRX_div8_2: ; devide lo:hi/8 (signed) only
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
64 bcf STATUS,C
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
65 btfsc hi,7 ; Copy sign bit to carry
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
66 bsf STATUS,C
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
67 rrcf hi ; /4
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
68 rrcf lo
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
69 bcf STATUS,C
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
70 btfsc hi,7 ; Copy sign bit to carry
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
71 bsf STATUS,C
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
72 rrcf hi ; /8
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
73 rrcf lo
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
74 bcf STATUS,C
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
75 btfsc hi,7 ; Copy sign bit to carry
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
76 bsf STATUS,C
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
77 rrcf hi ; /16
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
78 rrcf lo
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
79 return
0
heinrichsweikamp
parents:
diff changeset
80
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
81 global I2C_RX_accelerometer
0
heinrichsweikamp
parents:
diff changeset
82 I2C_RX_accelerometer:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
83 btfsc compass_type3 ; compass3
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
84 bra I2C_RX_accelerometer_compass3 ; yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
85 btfsc compass_type2 ; compass2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
86 bra I2C_RX_accelerometer_compass2 ; yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
87 btfsc compass_type ; compass1?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
88 bra I2C_RX_accelerometer_compass1 ; yes
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
89 I2C_RX_accelerometer_compass0:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
90 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
91 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
92 movlw 0x38 ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
93 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
94 movlw 0x00
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
95 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
96 bsf SSP1CON2,RSEN ; Repeated start condition (!)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
97 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
98 movlw 0x39 ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
99 rcall I2C_TX
158
683321c09cfa nicer boot into surfacemode
heinrichsweikamp
parents: 113
diff changeset
100
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
101 rcall I2C_OneByteRX ; Get Status Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
102 movf SSP1BUF,W
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
103
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
104 ; Non-flipped screen:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
105 ; Chip orientation on the PCB requires
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
106 ; Original = Corrected
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
107 ; x = -x
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
108 ; y = -y
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
109 ; z = -z
0
heinrichsweikamp
parents:
diff changeset
110
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
111 ; Flipped screen:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
112 ; Chip orientation on the PCB requires
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
113 ; Original = Corrected
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
114 ; x = x
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
115 ; y = y
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
116 ; z = -z
166
30ebaf72170d BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents: 158
diff changeset
117
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
118 rcall I2C_TwoBytesRX_div16 ; Get two bytes and devide /16 (signed)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
119 btfsc flip_screen ; 180° rotation ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
120 bra I2C_RX_accelerometer2 ; Yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
121 comf hi ; 16bit sign change.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
122 negf lo
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
123 btfsc STATUS,C ; Carry to propagate ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
124 incf hi,F ; YES: do it.
166
30ebaf72170d BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents: 158
diff changeset
125 I2C_RX_accelerometer2:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
126 movff lo,accel_DX+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
127 movff hi,accel_DX+1 ; Copy result
0
heinrichsweikamp
parents:
diff changeset
128
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
129 rcall I2C_TwoBytesRX_div16 ; Get two bytes and devide /16 (signed)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
130 btfsc flip_screen ; 180° rotation ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
131 bra I2C_RX_accelerometer3 ; Yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
132 comf hi ; 16bit sign change.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
133 negf lo
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
134 btfsc STATUS,C ; Carry to propagate ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
135 incf hi,F ; YES: do it.
166
30ebaf72170d BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents: 158
diff changeset
136 I2C_RX_accelerometer3:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
137 movff lo,accel_DY+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
138 movff hi,accel_DY+1 ; Copy result
0
heinrichsweikamp
parents:
diff changeset
139
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
140 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
141 movff SSP1BUF,hi ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
142 bsf SSP1CON2, RCEN ; Enable recieve mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
143 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
144 ; According to datasheet there should be no Master Acknowlegde for the last Byte (accel_DZ+0)...
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
145 movff SSP1BUF,lo ; Data Byte
0
heinrichsweikamp
parents:
diff changeset
146
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
147 rcall I2C_TwoBytesRX_div16_2; devide lo:hi/16 (signed) only
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
148 comf hi ; 16bit sign change.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
149 negf lo
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
150 btfsc STATUS,C ; Carry to propagate ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
151 incf hi,F ; YES: do it.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
152 movff lo,accel_DZ+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
153 movff hi,accel_DZ+1 ; Copy result
0
heinrichsweikamp
parents:
diff changeset
154
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
155 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
156 bra WaitMSSP ; (And return)
0
heinrichsweikamp
parents:
diff changeset
157
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
158 I2C_RX_accelerometer_compass1:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
159 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
160 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
161 movlw 0x3C ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
162 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
163 movlw b'10101000' ; 0x28 with auto-increment (MSB=1)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
164 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
165 bsf SSP1CON2,RSEN ; Repeated start condition (!)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
166 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
167 movlw 0x3D ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
168 I2C_RX_accelerometer_compass1_xx: ; compass2 and 3 continue here...
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
169 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
170 ; Non-flipped screen:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
171 ; Chip orientation on the PCB requires
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
172 ; Original = Corrected
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
173 ; x = -x (Compass 1)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
174 ; x = x (Compass 2)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
175 ; y = -y
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
176 ; z = -z
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
177
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
178 ; Flipped screen:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
179 ; Chip orientation on the PCB requires
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
180 ; Original = Corrected
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
181 ; x = x (Compass 1)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
182 ; x = -x (Compass 2)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
183 ; y = y
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
184 ; z = -z
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
185
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
186 ; Dump the accelerator data
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
187 rcall I2C_OneByteRX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
188 movff SSP1BUF,lo ;accel_DX+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
189 rcall I2C_OneByteRX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
190 movff SSP1BUF,hi ;accel_DX+1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
191 rcall I2C_TwoBytesRX_div16_2; devide lo:hi/16 (signed) only
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
192 btfss compass_type2 ; compass 2?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
193 bra I2C_RX_accelerometer1_c1 ; No, compass 1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
194 ; compass 2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
195 btfss flip_screen ; 180° rotation ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
196 bra I2C_RX_accelerometer2_c1 ; No, continue with normal compass1 routines for Y and Z
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
197 ; flipped compass 2, negate x
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
198 comf hi ; 16bit sign change.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
199 negf lo
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
200 btfsc STATUS,C ; Carry to propagate ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
201 incf hi,F ; YES: do it.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
202 bra I2C_RX_accelerometer2_c1 ; continue with normal compass1 routines for Y and Z
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
203
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
204 I2C_RX_accelerometer1_c1:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
205 btfsc flip_screen ; 180° rotation ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
206 bra I2C_RX_accelerometer2_c1 ; Yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
207 ; non-flipped compass 1, negate x
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
208 comf hi ; 16bit sign change.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
209 negf lo
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
210 btfsc STATUS,C ; Carry to propagate ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
211 incf hi,F ; YES: do it.
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
212 I2C_RX_accelerometer2_c1:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
213 ; flipped compass 1, non-flipped compass 2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
214 movff lo,accel_DX+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
215 movff hi,accel_DX+1 ; Copy result
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
216 rcall I2C_OneByteRX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
217 movff SSP1BUF,lo ;accel_DY+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
218 rcall I2C_OneByteRX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
219 movff SSP1BUF,hi ;accel_DY+1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
220
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
221 rcall I2C_TwoBytesRX_div16_2; devide lo:hi/16 (signed) only
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
222 btfsc flip_screen ; 180° rotation ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
223 bra I2C_RX_accelerometer3_c1 ; Yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
224 comf hi ; 16bit sign change.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
225 negf lo
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
226 btfsc STATUS,C ; Carry to propagate ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
227 incf hi,F ; YES: do it.
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
228 I2C_RX_accelerometer3_c1:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
229 movff lo,accel_DY+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
230 movff hi,accel_DY+1 ; Copy result
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
231
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
232 rcall I2C_OneByteRX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
233 movff SSP1BUF,lo ;accel_DZ+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
234 bsf SSP1CON2, RCEN ; Enable recieve mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
235 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
236 ; According to datasheet there should be no Master Acknowlegde for the last Byte (accel_DZ+1)...
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
237 movff SSP1BUF,hi ;accel_DZ+1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
238 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
239 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
240 rcall I2C_TwoBytesRX_div16_2; devide lo:hi/16 (signed) only
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
241 comf hi ; 16bit sign change for Z
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
242 negf lo
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
243 btfsc STATUS,C ; Carry to propagate ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
244 incf hi,F ; YES: do it.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
245 movff lo,accel_DZ+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
246 movff hi,accel_DZ+1 ; Copy result
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
247 return
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
248
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
249 I2C_RX_accelerometer_compass2:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
250 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
251 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
252 movlw 0x32 ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
253 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
254 movlw b'10101000' ; 0x28 with auto-increment (MSB=1)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
255 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
256 bsf SSP1CON2,RSEN ; Repeated start condition (!)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
257 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
258 movlw 0x33 ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
259 bra I2C_RX_accelerometer_compass1_xx
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
260
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
261 I2C_RX_accelerometer_compass3:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
262 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
263 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
264 movlw 0x3A ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
265 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
266 movlw 0x28 ; 0x28 (OUT_X_L_A)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
267 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
268 bsf SSP1CON2,RSEN ; Repeated start condition (!)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
269 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
270 movlw 0x3B ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
271 bra I2C_RX_accelerometer_compass1_xx
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
272
0
heinrichsweikamp
parents:
diff changeset
273 I2C_OneByteRX:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
274 bsf SSP1CON2, RCEN ; Enable recieve mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
275 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
276 bsf SSP1CON2,ACKEN ; Master acknowlegde
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
277 bra WaitMSSP ; And return!
0
heinrichsweikamp
parents:
diff changeset
278
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
279 global I2C_RX_compass
0
heinrichsweikamp
parents:
diff changeset
280 I2C_RX_compass:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
281 btfsc compass_type3 ; compass3
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
282 bra I2C_RX_compass3 ; yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
283 btfsc compass_type2 ; compass2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
284 bra I2C_RX_compass2 ; yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
285 btfsc compass_type ; compass1?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
286 bra I2C_RX_compass1 ; yes
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
287 I2C_RX_compass0:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
288 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
289 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
290 movlw 0x3C ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
291 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
292 movlw 0x03
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
293 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
294 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
295 rcall WaitMSSP
0
heinrichsweikamp
parents:
diff changeset
296
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
297 bcf PIR1,SSP1IF
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
298 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
299 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
300 movlw 0x3D ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
301 rcall I2C_TX
0
heinrichsweikamp
parents:
diff changeset
302
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
303 ; Compass IC sends data in following order:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
304 ; x MSB
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
305 ; x LSB
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
306 ; z MSB
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
307 ; z LSB
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
308 ; y MSB
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
309 ; y LSB
0
heinrichsweikamp
parents:
diff changeset
310
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
311 ; Non-flipped screen
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
312 ; Chip orientation on the PCB requires
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
313 ; Original = Corrected
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
314 ; x = -y
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
315 ; z = z
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
316 ; y = x
166
30ebaf72170d BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents: 158
diff changeset
317
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
318 ; Flipped screen
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
319 ; Chip orientation on the PCB requires
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
320 ; Original = Corrected
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
321 ; x = y
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
322 ; z = z
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
323 ; y = -x
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
324
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
325 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
326 movff SSP1BUF,compass_DY+1; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
327 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
328 movff SSP1BUF,compass_DY+0; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
329 btfsc flip_screen ; 180° rotation ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
330 bra I2C_RX_compass0_2 ; Yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
331 banksel compass_DY
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
332 comf compass_DY+1 ; 16bit sign change.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
333 negf compass_DY+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
334 btfsc STATUS,C ; Carry to propagate ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
335 incf compass_DY+1,F ; YES: do it.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
336 I2C_RX_compass0_2:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
337 banksel common
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
338 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
339 movff SSP1BUF,compass_DZ+1; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
340 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
341 movff SSP1BUF,compass_DZ+0; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
342 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
343 movff SSP1BUF,compass_DX+1; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
344 bsf SSP1CON2, RCEN ; Enable recieve mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
345 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
346 movff SSP1BUF,compass_DX+0; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
347 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
348 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
349 btfss flip_screen ; 180° rotation ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
350 return ; No, done.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
351 ; Yes, flip X
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
352 banksel compass_DX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
353 comf compass_DX+1 ; 16bit sign change.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
354 negf compass_DX+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
355 btfsc STATUS,C ; Carry to propagate ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
356 incf compass_DX+1,F ; YES: do it.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
357 banksel common
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
358 return
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
359
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
360 I2C_RX_compass1: ; New compass
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
361 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
362 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
363 movlw 0x3C ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
364 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
365 movlw b'10001000' ; 0x08 with auto-increment (MSB=1)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
366 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
367 bsf SSP1CON2,RSEN ; Repeated start condition (!)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
368 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
369 movlw 0x3D ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
370 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
371 ;rcall WaitMSSP ; Needed? (mH)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
372 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
373 movff SSP1BUF,lo ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
374 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
375 movff SSP1BUF,hi ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
376 rcall I2C_TwoBytesRX_div8_2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
377 movff lo,compass_DX+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
378 movff hi,compass_DX+1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
379 btfss flip_screen ; 180° rotation ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
380 bra I2C_RX_compass1_1 ; Yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
381 ; Yes, flip X
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
382 banksel compass_DX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
383 comf compass_DX+1 ; 16bit sign change.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
384 negf compass_DX+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
385 btfsc STATUS,C ; Carry to propagate ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
386 incf compass_DX+1,F ; YES: do it.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
387 banksel common
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
388 I2C_RX_compass1_1:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
389 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
390 movff SSP1BUF,lo ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
391 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
392 movff SSP1BUF,hi ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
393 rcall I2C_TwoBytesRX_div8_2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
394 movff lo,compass_DY+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
395 movff hi,compass_DY+1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
396 btfss flip_screen ; 180° rotation ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
397 bra I2C_RX_compass1_2 ; Yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
398 ; Yes, flip Y
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
399 banksel compass_DY
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
400 comf compass_DY+1 ; 16bit sign change.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
401 negf compass_DY+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
402 btfsc STATUS,C ; Carry to propagate ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
403 incf compass_DY+1,F ; YES: do it.
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
404 I2C_RX_compass1_2:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
405 banksel common
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
406 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
407 movff SSP1BUF,lo ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
408 bsf SSP1CON2, RCEN ; Enable recieve mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
409 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
410 movff SSP1BUF,hi ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
411 rcall I2C_TwoBytesRX_div8_2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
412 movff lo,compass_DZ+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
413 movff hi,compass_DZ+1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
414 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
415 bra WaitMSSP ;(And return)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
416
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
417 I2C_RX_compass2: ; newest compass
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
418 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
419 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
420 movlw 0x3C ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
421 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
422 movlw 0xE8 ; 0x68 with auto-increment (MSB=1)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
423 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
424 bsf SSP1CON2,RSEN ; Repeated start condition (!)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
425 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
426 movlw 0x3D ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
427 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
428 I2C_RX_compass2_xx: ; compass 3 enters here
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
429 ; rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
430 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
431 movff SSP1BUF,lo ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
432 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
433 movff SSP1BUF,hi ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
434 ; rcall I2C_TwoBytesRX_div8_2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
435 btfsc flip_screen ; 180° rotation ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
436 bra I2C_RX_compass2_1 ; Yes, do nothing with X
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
437 ; No, flip X
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
438 comf hi ; 16bit sign change.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
439 negf lo
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
440 btfsc STATUS,C ; Carry to propagate ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
441 incf hi,F ; YES: do it.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
442 I2C_RX_compass2_1:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
443 movff lo,compass_DX+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
444 movff hi,compass_DX+1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
445 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
446 movff SSP1BUF,lo ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
447 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
448 movff SSP1BUF,hi ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
449 ; rcall I2C_TwoBytesRX_div8_2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
450 btfss flip_screen ; 180° rotation ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
451 bra I2C_RX_compass2_2 ; No, do nothing with Y
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
452 ; Yes, flip Y
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
453 comf hi ; 16bit sign change.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
454 negf lo
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
455 btfsc STATUS,C ; Carry to propagate ?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
456 incf hi,F ; YES: do it.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
457 I2C_RX_compass2_2:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
458 movff lo,compass_DY+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
459 movff hi,compass_DY+1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
460 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
461 movff SSP1BUF,lo ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
462 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
463 movff SSP1BUF,hi ; Data Byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
464 ;rcall I2C_TwoBytesRX_div8_2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
465 movff lo,compass_DZ+0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
466 movff hi,compass_DZ+1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
467 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
468 bra WaitMSSP ;(And return)
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
469
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
470 I2C_RX_compass3:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
471 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
472 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
473 movlw 0x3C ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
474 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
475 movlw 0xA8 ; 0x28 with auto-increment (MSB=1)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
476 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
477 bsf SSP1CON2,RSEN ; Repeated start condition (!)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
478 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
479 movlw 0x3D ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
480 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
481 bra I2C_RX_compass2_xx
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
482
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
483 global I2C_init_compass
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
484 I2C_init_compass:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
485 bsf compass_enabled
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
486 bcf compass_type2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
487 bcf compass_type3
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
488
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
489 ; probe compass 3
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
490 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
491 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
492 movlw 0x3A ; Address byte + Write bit
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
493 movwf SSP1BUF ; control byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
494 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
495 btfss SSP1CON2,ACKSTAT ; ACK?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
496 bsf compass_type3 ; ACK send. compass2 present
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
497 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
498 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
499
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
500 btfsc compass_type3
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
501 bra I2C_init_compass3 ; Compass3
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
502
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
503 ; probe compass 2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
504 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
505 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
506 movlw 0x32 ; Address byte + Write bit
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
507 movwf SSP1BUF ; control byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
508 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
509 btfss SSP1CON2,ACKSTAT ; ACK?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
510 bsf compass_type2 ; ACK send. compass2 present
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
511 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
512 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
513
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
514 btfsc compass_type2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
515 bra I2C_init_compass2 ; Compass2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
516 ; Check for compass0 or compass1...
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
517 bsf compass_type ; set flag
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
518 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
519 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
520 movlw 0x3C ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
521 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
522 movlw 0x0F
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
523 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
524 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
525 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
526 bcf PIR1,SSP1IF
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
527 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
528 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
529 movlw 0x3D ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
530 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
531 rcall I2C_OneByteRX ; Get one byte
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
532 movlw 0x49 ; 0x49 = Compass1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
533 cpfseq SSP1BUF
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
534 bcf compass_type ; clear flag
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
535 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
536 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
537
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
538 btfsc compass_type ; compass1?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
539 bra I2C_init_compass1 ; yes
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
540 ; init compass0
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
541 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
542 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
543 movlw 0x3C ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
544 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
545 movlw 0x00
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
546 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
547 ; movlw b'01101001' ; ConfigA: 3Hz, 8 Samples averaged, Test Mode (Positive Bias)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
548 movlw b'01101000' ; ConfigA: 3Hz, 8 Samples averaged
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
549 rcall I2C_TX
20
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
550 I2C_init_compass_common:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
551 movff opt_compass_gain,i2c_temp1 ; 0-7 (230LSB/Gauss to 1370LSB/Gauss)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
552 swapf i2c_temp1,F
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
553 comf i2c_temp1,F
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
554 bcf STATUS,C
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
555 rlcf i2c_temp1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
556 movf i2c_temp1,W
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
557 clrf i2c_temp1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
558 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
559 movlw b'00000000' ; Continous Mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
560 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
561 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
562 bra WaitMSSP ; (And return)
0
heinrichsweikamp
parents:
diff changeset
563
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
564 I2C_init_compass1:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
565 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
566 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
567 movlw 0x3C ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
568 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
569 movlw 0x9F ; 1F with auto-increment (MSB=1)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
570 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
571 movlw b'00000000' ; CTRL0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
572 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
573 movlw b'00101111' ; CTRL1 (6,25Hz, BDU=0, x,y,z = ON)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
574 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
575 movlw b'11000000' ; CTRL2 (50Hz, +/-2g,
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
576 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
577 movlw b'00000000' ; CTRL3
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
578 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
579 movlw b'00000000' ; CTRL4
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
580 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
581 movlw b'01100100' ; CTRL5 HIGH res, 6,25Hz
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
582 rcall I2C_TX
429
4b93354b7738 hardware_flag handling
heinrichsweikamp
parents: 427
diff changeset
583 init_compass1_common:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
584 movff opt_compass_gain,i2c_temp1 ; 0-7 (230LSB/Gauss to 1370LSB/Gauss)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
585 movlw b'01100000' ; CTRL6 Full scale (+/-12 Gauss -> 2730LSB/Gauss)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
586 dcfsnz i2c_temp1,F ; = 1?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
587 movlw b'01100000' ; Yes, CTRL6 Full scale (+/-12 Gauss -> 2730LSB/Gauss)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
588 dcfsnz i2c_temp1,F ; = 2?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
589 movlw b'01000000' ; Yes, CTRL6 (+/-8 Gauss)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
590 dcfsnz i2c_temp1,F ; = 3?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
591 movlw b'01000000' ; Yes, CTRL6 (+/-8 Gauss)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
592 dcfsnz i2c_temp1,F ; = 4?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
593 movlw b'00100000' ; Yes, CTRL6 (+/-4 Gauss)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
594 dcfsnz i2c_temp1,F ; = 5?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
595 movlw b'00100000' ; Yes, CTRL6 (+/-4 Gauss)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
596 dcfsnz i2c_temp1,F ; = 6?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
597 movlw b'00000000' ; Yes, CTRL6 (+/-2 Gauss)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
598 dcfsnz i2c_temp1,F ; = 7?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
599 movlw b'00000000' ; Yes, CTRL6 (+/-2 Gauss)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
600 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
601 movlw b'00000000' ; CTRL7 Continuous Mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
602 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
603 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
604 bra WaitMSSP ; (And return)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
605
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
606 I2C_init_compass2:
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
607 bsf SSP1CON2,SEN ; Start condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
608 rcall WaitMSSP
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
609 movlw 0x3C ; address
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
610 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
611 movlw 0xE0 ; 0x60 with auto-increment (MSB=1)
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
612 rcall I2C_TX
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
613 movlw b'10000000' ; CFG_REG_A_M (10Hz, Continuous) 0x60
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
614 rcall I2C_TX
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
615 movlw b'00000001' ; CFG_REG_B_M (Low-Pass Filter enabled) 0x61 (set pulse is released every 63 ODR)
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
616 rcall I2C_TX
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
617 movlw b'00010000' ; CFG_REG_C_M BDU=1 0x62
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
618 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
619 bsf SSP1CON2,PEN ; Stop condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
620 bra WaitMSSP ;(And return)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
621
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
622 I2C_init_compass3:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
623 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
624 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
625 movlw 0x3C ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
626 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
627 movlw 0xA0 ; 0x20 with auto-increment (MSB=1)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
628 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
629 movlw b'01110000' ; CTRL_REG1_M (10Hz) 0x20
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
630 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
631 movlw b'01100000' ; CTRL_REG2_M (Full-scale: +/- 16gauss) 0x21
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
632 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
633 movlw b'01000000' ; CTRL_REG3_M (Continuous) 0x22
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
634 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
635 movlw b'00000000' ; CTRL_REG4_M (Z in Low-power mode) 0x23
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
636 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
637 movlw b'00000000' ; CTRL_REG5_M 0x24
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
638 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
639 movlw b'00000000' ; CTRL_REG5_M 0x24
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
640 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
641 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
642 bra WaitMSSP ;(And return)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
643
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
644
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
645 WaitMSSP:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
646 decfsz i2c_temp1,F ; check for timeout during I2C action
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
647 bra WaitMSSP2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
648 bra I2CFail ; timeout occured
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
649 WaitMSSP2:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
650 btfss PIR1,SSP1IF
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
651 bra WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
652 clrf i2c_temp1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
653 bcf PIR1,SSP1IF
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
654 return
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
655
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
656 I2C_WaitforACK:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
657 btfss SSP1CON2,ACKSTAT ; checks for ACK bit from slave
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
658 return
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
659 I2CFail:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
660 rcall I2CReset ; I2C Reset
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
661 bcf PIR1,SSP1IF
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
662 clrf i2c_temp1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
663 bsf i2c_error_flag ; set error flag
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
664 return
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
665
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
666 I2CReset: ; Something went wrong (Slave holds SDA low?)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
667 clrf SSP1CON1 ; wake-up slave and reset entire module
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
668 clrf SSP1CON2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
669 clrf SSP1STAT
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
670 bcf TRISC,3 ; SCL OUTPUT
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
671 bsf TRISC,4 ; SDA Input
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
672 bcf PORTC,3
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
673 movlw d'9'
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
674 movwf i2c_temp1 ; clock-out 9 clock cycles manually
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
675 I2CReset_1:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
676 bsf PORTC,3 ; SCL=1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
677 nop
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
678 nop
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
679 nop
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
680 nop
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
681 btfsc PORTC,4 ; SDA=1?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
682 bra I2CReset_2 ; =1, SDA has been released from slave
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
683 bcf PORTC,3 ; SCL=0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
684 nop
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
685 nop
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
686 bcf PORTC,3
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
687 nop
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
688 nop
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
689 decfsz i2c_temp1,F
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
690 bra I2CReset_1 ; check for nine clock cycles
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
691 I2CReset_2:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
692 bsf TRISC,3 ; SCL Input
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
693 clrf SSP1CON1 ; setup I²C Mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
694 WAITMS d'10' ; Reset-Timeout for I2C devices
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
695 movlw b'00000000' ; with slew rate control
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
696 movwf SSP1STAT
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
697 movlw b'00101000'
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
698 movwf SSP1CON1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
699 movlw b'00000000'
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
700 movwf SSP1CON2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
701 movlw 0x27
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
702 movwf SSP1ADD
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
703 return
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
704
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
705
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
706 global I2C_sleep_compass
0
heinrichsweikamp
parents:
diff changeset
707 I2C_sleep_compass:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
708 bcf compass_enabled
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
709 btfsc compass_type3 ; compass3?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
710 bra I2C_sleep_compass3 ; yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
711 btfsc compass_type2 ; compass2?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
712 bra I2C_sleep_compass2 ; yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
713 btfsc compass_type ; compass1?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
714 bra I2C_sleep_compass1 ; yes
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
715 I2C_sleep_compass0:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
716 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
717 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
718 movlw 0x3C ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
719 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
720 movlw 0x00
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
721 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
722 movlw b'01101000' ; ConfigA
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
723 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
724 movlw b'00100000' ; ConfigB
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
725 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
726 movlw b'00000010' ; Idle Mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
727 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
728 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
729 bra WaitMSSP ; (And return)
0
heinrichsweikamp
parents:
diff changeset
730
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
731 I2C_sleep_compass1:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
732 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
733 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
734 movlw 0x3C ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
735 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
736 movlw 0x20 ; CTRL_REG1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
737 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
738 movlw b'00000000' ; data for CTRL_REG1: acceleration sensor Power-down mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
739 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
740 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
741 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
742 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
743 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
744 movlw 0x3C ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
745 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
746 movlw 0x26 ; CTRL_REG7
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
747 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
748 movlw b'00000010' ; data for CTRL_REG7: magnetic sensor Power-down mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
749 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
750 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
751 bra WaitMSSP ;(And return)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
752
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
753
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
754 I2C_sleep_compass2:
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
755 ; magnetic
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
756 bsf SSP1CON2,SEN ; Start condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
757 rcall WaitMSSP
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
758 movlw 0x3C ; address
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
759 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
760 movlw 0xE0 ; 0x60 with auto-increment (MSB=1)
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
761 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
762 movlw b'00000011' ; CFG_REG_A_M (Idle mode) 0x60
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
763 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
764 movlw b'00000100' ; CFG_REG_B_M 0x61 (set pulse is released only at power-on after PD condition)
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
765 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
766 movlw b'01010001' ; CFG_REG_C_M 0x62
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
767 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
768 movlw b'00000000' ; INT_CTRL_REG_M 0x63
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
769 rcall I2C_TX
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
770
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
771 bsf SSP1CON2,PEN ; Stop condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
772 bra WaitMSSP ; (And return)
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
773
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
774 I2C_sleep_compass3:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
775 ; magnetic
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
776 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
777 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
778 movlw 0x3C ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
779 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
780 movlw 0xA2 ; 0x22 with auto-increment (MSB=1)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
781 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
782 movlw b'01000010' ; CTRL_REG3_M (Power-down) 0x22
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
783 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
784 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
785 bra WaitMSSP ;(And return)
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
786
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
787 I2C_sleep_accelerometer2:
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
788 ; accelerometer
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
789 bsf SSP1CON2,SEN ; Start condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
790 rcall WaitMSSP
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
791 movlw 0x32 ; address
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
792 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
793 movlw 0x9F ; 1F with auto-increment (MSB=1)
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
794 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
795 movlw b'00000000' ; TEMP_CFG_REG_A (Temp sensor off) 0x1F
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
796 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
797 movlw b'00000000' ; CTRL_REG1_A (All off) 0x20
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
798 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
799 bsf SSP1CON2,PEN ; Stop condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
800 bra WaitMSSP ; (And return)
0
heinrichsweikamp
parents:
diff changeset
801
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
802 I2C_sleep_accelerometer3:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
803 ; accelerometer
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
804 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
805 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
806 movlw 0x3A ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
807 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
808 movlw 0x20
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
809 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
810 movlw b'00000000' ; CTRL_REG1_A (100Hz, x,y,z = OFF) 0x20
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
811 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
812 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
813 bra WaitMSSP ; (And return)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
814
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
815 global I2C_init_accelerometer
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
816 I2C_init_accelerometer:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
817 btfsc compass_type3 ; compass3?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
818 bra I2C_init_accelerometer3 ; Yes.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
819 btfsc compass_type2 ; compass2?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
820 bra I2C_init_accelerometer2 ; Yes.
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
821 btfsc compass_type ; compass1?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
822 return ; yes, ignore
615
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
823
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
824 rcall I2C_sleep_accelerometer ; Regs can only be changed in St.By mode
615
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
825
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
826 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
827 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
828 movlw 0x38 ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
829 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
830 movlw 0x0E ; XYZ_DATA_CFG
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
831 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
832 movlw b'00000000' ; High pass Filter=0 , +/- 2g range
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
833 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
834 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
835 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
836
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
837
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
838 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
839 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
840 movlw 0x38 ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
841 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
842 movlw 0x2A ; CTRL_REG1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
843 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
844 ; movlw b'00110000' ; CTRL_REG1: 160ms data rate, St.By Mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
845 movlw b'00110100' ; CTRL_REG1: 160ms data rate, St.By Mode, reduced noise mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
846 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
847 movlw b'00000010' ; CTRL_REG2: High Res in Active mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
848 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
849 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
850 rcall WaitMSSP
0
heinrichsweikamp
parents:
diff changeset
851
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
852 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
853 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
854 movlw 0x38 ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
855 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
856 movlw 0x2A ; CTRL_REG1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
857 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
858 ; movlw b'00110001' ; CTRL_REG1: 160ms data rate, Active Mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
859 movlw b'00110101' ; CTRL_REG1: 160ms data rate, St.By Mode, reduced noise mode, Active Mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
860 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
861 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
862 bra WaitMSSP ; (And return)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
863
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
864 I2C_init_accelerometer2:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
865 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
866 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
867 movlw 0x32 ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
868 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
869 movlw 0x9F ; 1F with auto-increment (MSB=1)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
870 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
871 movlw b'00000000' ; TEMP_CFG_REG_A (Temp sensor off) 0x1F
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
872 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
873 movlw b'01010111' ; CTRL_REG1_A (100Hz, x,y,z = ON) 0x20
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
874 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
875 movlw b'00000000' ; CTRL_REG2_A 0x21
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
876 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
877 movlw b'00000000' ; CTRL_REG3_A 0x22
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
878 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
879 movlw b'00000000' ; CTRL_REG4_A (BDU=0, +/-2g) 0x23
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
880 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
881 movlw b'00000000' ; CTRL_REG5_A 0x24
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
882 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
883 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
884 bra WaitMSSP ; (And return)
0
heinrichsweikamp
parents:
diff changeset
885
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
886 I2C_init_accelerometer3:
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
887 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
888 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
889 movlw 0x3A ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
890 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
891 movlw 0x20
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
892 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
893 movlw b'10011111' ; CTRL_REG1_A (10Hz, x,y,z = ON) 0x20
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
894 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
895 movlw b'00000000' ; CTRL_REG2_A 0x21
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
896 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
897 movlw b'00000000' ; CTRL_REG3_A 0x22
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
898 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
899 movlw b'11001100' ; CTRL_REG4_A 0x23
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
900 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
901 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
902 bra WaitMSSP ; (And return)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
903
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
904
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
905 global I2C_sleep_accelerometer
0
heinrichsweikamp
parents:
diff changeset
906 I2C_sleep_accelerometer:
626
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
907 btfsc compass_type3 ; Compass3
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
908 bra I2C_sleep_accelerometer3 ; Yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
909 btfsc compass_type2 ; Compass2
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
910 bra I2C_sleep_accelerometer2 ; Yes
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
911 btfsc compass_type ; compass1?
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
912 return ; yes, ignore
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
913 ; compass 0
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
914 bsf SSP1CON2,SEN ; Start condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
915 rcall WaitMSSP
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
916 movlw 0x38 ; address
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
917 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
918 movlw 0x2A ; CTRL_REG1
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
919 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
920 movlw b'00000000' ; St. By Mode
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
921 rcall I2C_TX
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
922 bsf SSP1CON2,PEN ; Stop condition
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
923 bra WaitMSSP ; (And return)
be8787f2034d compass3 support for 3.01 branch
heinrichsweikamp
parents: 621
diff changeset
924
556
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
925 lt2942_init_again:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
926 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
927 movlw 0x02 ; Point to accumulated charge registers
556
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
928 rcall I2C_TX_GAUGE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
929 movff battery_acumulated_charge+1,SSP1BUF ; Data Byte
556
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
930 rcall WaitMSSP
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
931 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
932 movff battery_acumulated_charge+0,SSP1BUF ; Data Byte
556
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
933 rcall WaitMSSP
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
934 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
935 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
936 rcall WaitMSSP
556
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
937 movff battery_acumulated_charge+1,sub_a+1
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
938 movff battery_acumulated_charge+0,sub_a+0
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
939 ; and init again...
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
940
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
941 global lt2942_init
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
942 lt2942_init: ; Setup Control register B
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
943 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
944 movlw 0x01 ; Point to control reg B
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
945 rcall I2C_TX_GAUGE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
946 movlw b'11111000' ; Automatic conversion every two seconds
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
947 movff WREG, SSP1BUF ; Data Byte
113
heinrichsweikamp
parents: 20
diff changeset
948 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
949 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
950 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
951 bra WaitMSSP ; (And return)
113
heinrichsweikamp
parents: 20
diff changeset
952
heinrichsweikamp
parents: 20
diff changeset
953 global lt2942_get_status
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
954 lt2942_get_status: ; Read status register
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
955 bcf battery_gauge_available ; Clear flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
956 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
957 movlw 0x00 ; Point to Status reg
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
958 rcall I2C_TX_GAUGE
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
959 rcall I2C_RX_GAUGE
113
heinrichsweikamp
parents: 20
diff changeset
960 movff SSP1BUF,WREG
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
961 btfss WREG,7 ; 2942 found?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
962 bsf battery_gauge_available ; Yes, set flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
963 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
964 bra WaitMSSP ; (And return)
113
heinrichsweikamp
parents: 20
diff changeset
965
heinrichsweikamp
parents: 20
diff changeset
966
heinrichsweikamp
parents: 20
diff changeset
967 global lt2942_get_voltage
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
968 lt2942_get_voltage: ; Read battery voltage registers
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
969 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
970 movlw 0x08 ; Point to voltage registers
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 429
diff changeset
971 rcall I2C_TX_GAUGE
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 429
diff changeset
972 rcall I2C_RX_GAUGE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
973 bsf SSP1CON2,ACKEN ; Master acknowledge
113
heinrichsweikamp
parents: 20
diff changeset
974 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
975 movff SSP1BUF,xA+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
976 bsf SSP1CON2, RCEN ; Enable receive mode
113
heinrichsweikamp
parents: 20
diff changeset
977 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
978 movff SSP1BUF,xA+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
979 bsf SSP1CON2,PEN ; Stop condition
113
heinrichsweikamp
parents: 20
diff changeset
980 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
981
heinrichsweikamp
parents: 20
diff changeset
982 ; banksel common
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
983 ; xA:2 loaded with raw values
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
984 movlw LOW .6000
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
985 movwf xB+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
986 movlw HIGH .6000
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
987 movwf xB+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
988 call mult16x16 ; xA*xB=xC
113
heinrichsweikamp
parents: 20
diff changeset
989
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 616
diff changeset
990 ; xC+3:xC+2 -> Result in mV
113
heinrichsweikamp
parents: 20
diff changeset
991
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
992 ; Update battery voltage in mV
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 616
diff changeset
993 movff xC+3,batt_voltage+1
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 616
diff changeset
994 movff xC+2,batt_voltage+0
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
995
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
996 tstfsz batt_voltage+1 ; <256mV?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
997 return ; No, done.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
998 bra lt2942_init ;(and return)
113
heinrichsweikamp
parents: 20
diff changeset
999
615
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1000 global lt2942_get_temperature
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1001 lt2942_get_temperature: ; Read temperature registers
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1002 clrf i2c_temp1
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1003 movlw 0x0C ; Point to temperature registers
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1004 call I2C_TX_GAUGE
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1005 call I2C_RX_GAUGE
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1006 bsf SSP1CON2,ACKEN ; Master acknowlegde
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1007 rcall WaitMSSP
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1008 movff SSP1BUF,xA+1
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1009 bsf SSP1CON2, RCEN ; Enable recieve mode
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1010 rcall WaitMSSP
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1011 movff SSP1BUF,xA+0
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1012 bsf SSP1CON2,PEN ; Stop condition
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1013 rcall WaitMSSP
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1014
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1015 ; banksel common
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1016 ; xA:2 loaded with raw values
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1017 movlw LOW .6000
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1018 movwf xB+0
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1019 movlw HIGH .6000
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1020 movwf xB+1
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1021 call mult16x16 ;xA*xB=xC
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1022
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 616
diff changeset
1023 ; xC+3:xC+2 -> Result in 0.1K
615
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1024
616
935e20e16dff work on new battery menu
heinrichsweikamp
parents: 615
diff changeset
1025 movlw LOW max_allowed_battery_temp ; in 0.1K
615
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1026 movwf sub_a+0
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1027 movlw HIGH max_allowed_battery_temp
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1028 movwf sub_a+1
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 616
diff changeset
1029 movff xC+3,sub_b+1
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 616
diff changeset
1030 movff xC+2,sub_b+0
615
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1031 call subU16 ; sub_c = sub_a - sub_b (with UNSIGNED values)
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1032 btfss neg_flag
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1033 return ; temp ok, return
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1034 ; too hot, disable charge if currently charging
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1035 btfss cc_active
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1036 return ; Not charging, return
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1037 ; charging: Disable now
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1038 bsf charge_disable
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1039 bcf TRISE,2
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1040 bsf battery_overtemp ; =1: The battery was charged and temp was too high (Only cleared on POR)
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
1041 return
113
heinrichsweikamp
parents: 20
diff changeset
1042
heinrichsweikamp
parents: 20
diff changeset
1043 global lt2942_get_accumulated_charge
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1044 lt2942_get_accumulated_charge: ; Read accumulated charge and compute percent
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1045 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1046 movlw 0x00 ; Point to status register
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
1047 rcall I2C_TX_GAUGE
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
1048 rcall I2C_RX_GAUGE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1049 bsf SSP1CON2,ACKEN ; Master acknowledge
113
heinrichsweikamp
parents: 20
diff changeset
1050 rcall WaitMSSP
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
1051 movff SSP1BUF,gauge_status_byte
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
1052
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1053 bsf SSP1CON2, RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1054 rcall WaitMSSP ; Dummy read (Control byte)
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
1055 movf SSP1BUF,W
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1056 bsf SSP1CON2,ACKEN ; Master acknowledge
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
1057 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1058
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1059 bsf SSP1CON2, RCEN ; Enable receive mode
113
heinrichsweikamp
parents: 20
diff changeset
1060 rcall WaitMSSP
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
1061 movff SSP1BUF,sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1062 bsf SSP1CON2,ACKEN ; Master acknowledge
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
1063 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1064
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1065 bsf SSP1CON2, RCEN ; Enable receive mode
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
1066 rcall WaitMSSP
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
1067 movff SSP1BUF,sub_a+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1068 bsf SSP1CON2,PEN ; Stop condition
113
heinrichsweikamp
parents: 20
diff changeset
1069 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1070
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1071 movff gauge_status_byte,sub_b+0 ; copy into bank common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1072 btfsc sub_b+0,0 ; =1: UVLO Event
556
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
1073 rcall lt2942_init_again
113
heinrichsweikamp
parents: 20
diff changeset
1074
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1075 movff sub_a+1,battery_acumulated_charge+1 ; Save raw value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1076 movff sub_a+0,battery_acumulated_charge+0 ; Save raw value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1077
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1078 ; Compute batt_percent
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1079 ; (charge-battery_offset)/365
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1080 movff battery_offset+0,sub_b+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1081 movff battery_offset+1,sub_b+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1082 call subU16 ; sub_c = sub_a - sub_b (with signed values)
113
heinrichsweikamp
parents: 20
diff changeset
1083
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1084 clrf batt_percent ; Set to zero
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1085 btfsc neg_flag ; result negative?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1086 bra lt2942_set_to_zero_percent ; Yes, keep LT2942 at zero percent and return
113
heinrichsweikamp
parents: 20
diff changeset
1087
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1088 ; > Zero, set batt_percent properly
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1089 movff sub_c+0,xA+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1090 movff sub_c+1,xA+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1091 movff battery_capacity+0,xB+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1092 movff battery_capacity+1,xB+1
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1093 call div16x16 ; xC = xA / xB with xA as remainder
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1094 movff xC+0,batt_percent
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1095 return
113
heinrichsweikamp
parents: 20
diff changeset
1096
449
heinrichsweikamp
parents: 448
diff changeset
1097 lt2942_set_to_zero_percent:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1098 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1099 movlw 0x02 ; Point to accumulated charge registers
449
heinrichsweikamp
parents: 448
diff changeset
1100 rcall I2C_TX_GAUGE
heinrichsweikamp
parents: 448
diff changeset
1101 movff battery_offset+1,SSP1BUF
heinrichsweikamp
parents: 448
diff changeset
1102 rcall WaitMSSP
heinrichsweikamp
parents: 448
diff changeset
1103 rcall I2C_WaitforACK
heinrichsweikamp
parents: 448
diff changeset
1104 movff battery_offset+0,SSP1BUF
heinrichsweikamp
parents: 448
diff changeset
1105 rcall WaitMSSP
heinrichsweikamp
parents: 448
diff changeset
1106 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1107 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1108 bra WaitMSSP ; (and return)
449
heinrichsweikamp
parents: 448
diff changeset
1109
113
heinrichsweikamp
parents: 20
diff changeset
1110 global lt2942_charge_done
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1111 lt2942_charge_done: ; Reset accumulating registers to 0xFFFF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1112 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1113 movlw 0x02 ; Point to accumulated charge registers
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 429
diff changeset
1114 rcall I2C_TX_GAUGE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1115 setf SSP1BUF ; Data Byte
113
heinrichsweikamp
parents: 20
diff changeset
1116 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
1117 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1118 setf SSP1BUF ; Data Byte
113
heinrichsweikamp
parents: 20
diff changeset
1119 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
1120 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1121 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1122 bra WaitMSSP ; (and return)
113
heinrichsweikamp
parents: 20
diff changeset
1123
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1124 I2C_TX_GAUGE: ; Sends a byte to the LT2942 Gauge IC
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1125 movwf i2c_temp2 ; Data byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1126 bsf SSP1CON2,SEN ; Start condition
113
heinrichsweikamp
parents: 20
diff changeset
1127 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1128 movlw b'11001000' ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1129 movwf SSP1BUF ; control byte
113
heinrichsweikamp
parents: 20
diff changeset
1130 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
1131 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1132 movf i2c_temp2,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1133 bra I2C_TX ; (and return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1134
113
heinrichsweikamp
parents: 20
diff changeset
1135 I2C_RX_GAUGE:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1136 bsf SSP1CON2,SEN ; Start condition
113
heinrichsweikamp
parents: 20
diff changeset
1137 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1138 movlw b'11001001' ; Address byte + Read bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1139 movwf SSP1BUF ; control byte
113
heinrichsweikamp
parents: 20
diff changeset
1140 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
1141 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1142 bsf SSP1CON2, RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1143 bra WaitMSSP ; (and return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1144
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1145
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1146 ;-----------------------------------------------------------------------------
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1147 ; Transmitter Functions
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1148
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1149 IFDEF _rx_functions
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1150
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1151 global I2C_probe_OSTC_rx
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1152 I2C_probe_OSTC_rx:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1153 movlw .5
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1154 movwf lo_temp
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1155 I2C_probe_OSTC_rx_1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1156 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1157 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1158 movlw 0x50 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1159 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1160 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1161 btfss SSP1CON2,ACKSTAT ; ACK?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1162 bsf ostc_rx_present ; ACK sent - OSTC_RX present!
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1163 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1164 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1165 btfss ostc_rx_present ; Do we have the RX?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1166 return ; No, Done.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1167 WAITMS .1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1168 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1169 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1170 movlw 0x50 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1171 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1172 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1173 rcall I2C_WaitforACK
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1174 movlw 0x1B
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1175 movwf SSP1BUF ; Data Byte (Get firmware)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1176 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1177 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1178 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1179 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1180 WAITMS .1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1181 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1182 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1183 movlw 0x51 ; Address byte + Read bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1184 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1185 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1186 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1187 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1188 movff SSP1BUF,rx_firmware+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1189 bsf SSP1CON2,ACKEN ; Master acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1190 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1191
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1192 ; last byte in read from RX circuity always with a NACK!
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1193 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1194 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1195 movff SSP1BUF,rx_firmware+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1196 bsf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1197 bsf SSP1CON2,ACKEN ; Master NOT acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1198 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1199 bcf SSP1CON2,ACKDT ; Reset ACKDT flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1200 bsf SSP1CON2,PEN ; Stop condition
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1201 rcall WaitMSSP
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1202
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1203 ; test for RX part not being ready during this read
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1204 movff rx_firmware+1,i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1205 movlw .147
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1206 cpfseq i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1207 bra I2C_probe_OSTC_rx_2 ; not equal
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1208 movff rx_firmware+0,i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1209 movlw .27
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1210 cpfseq i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1211 bra I2C_probe_OSTC_rx_2 ; not equal
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1212 bsf active_reset_ostc_rx
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1213 WAITMS .5
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1214 bcf active_reset_ostc_rx
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1215 WAITMS .250
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1216 WAITMS .250
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1217 clrf i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1218 decfsz lo_temp,F ; try max. 5 times
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1219 bra I2C_probe_OSTC_rx_1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1220 bcf ostc_rx_present ; Clear flag. Something is wrong
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1221 I2C_probe_OSTC_rx_2:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1222 clrf i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1223 return
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1224
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1225
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1226 global I2C_get_tankdata
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1227 I2C_get_tankdata:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1228 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1229 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1230 movlw 0x50 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1231 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1232 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1233 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1234 movlw 0x1E ; Read buffer2 (48 Bytes)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1235 movwf SSP1BUF ; Data Byte
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1236 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1237 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1238 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1239 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1240 WAITMS .1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1241
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1242 ; read 48 bytes
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1243 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1244 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1245 movlw 0x51 ; Address byte + read bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1246 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1247 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1248 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1249 movlw .47 ; 47 with ACK + 1 w/o ACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1250 movwf i2c_temp2
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1251 lfsr FSR2,rx_buffer+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1252 I2C_get_tankdata_loop_read:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1253 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1254 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1255 movff SSP1BUF,POSTINC2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1256 bcf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1257 bsf SSP1CON2,ACKEN ; Master acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1258 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1259 decfsz i2c_temp2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1260 bra I2C_get_tankdata_loop_read
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1261
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1262 ; 1 w/o ACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1263 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1264 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1265 movff SSP1BUF,POSTINC2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1266 bsf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1267 bsf SSP1CON2,ACKEN ; Master NOT acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1268 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1269 bcf SSP1CON2,ACKDT ; Reset ACKDT flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1270
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1271 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1272 bra WaitMSSP ;(and return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1273
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1274
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1275 global I2C_update_OSTC_rx
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1276 I2C_update_OSTC_rx: ; 992*64byte master loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1277 bcf i2c_error_flag ; clear error flag
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1278 ; write 64 bytes
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1279 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1280 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1281 movlw 0x50 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1282 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1283 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1284 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1285 lfsr FSR2,buffer ; send buffer for verify
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1286 movlw .64
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1287 movwf i2c_temp2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1288 I2C_update_OSTC_loop: ; 64byte flash page loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1289 movff up,POSTINC2 ; store for verify
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1290 movff up,SSP1BUF
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1291 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1292 rcall I2C_WaitforACK
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1293 call ext_flash_read_block ; Read one byte
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1294 movwf up ; prepare for transmit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1295 decfsz i2c_temp2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1296 bra I2C_update_OSTC_loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1297 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1298 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1299 WAITMS .1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1300
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1301 ; read 64 bytes
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1302 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1303 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1304 movlw 0x51 ; Address byte + read bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1305 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1306 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1307 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1308 lfsr FSR2,buffer ; send buffer for verify
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1309 movlw .63 ; 63 with ACK + 1 w/o ACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1310 movwf i2c_temp2
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1311 I2C_update_OSTC_loop_read:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1312 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1313 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1314 movf SSP1BUF,W
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1315 cpfseq POSTINC2 ; compare read-back with original
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1316 bsf i2c_error_flag ; Not equal, set flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1317 bcf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1318 bsf SSP1CON2,ACKEN ; Master acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1319 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1320 decfsz i2c_temp2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1321 bra I2C_update_OSTC_loop_read
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1322
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1323 ; 1 w/o ACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1324 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1325 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1326 movf SSP1BUF,W
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1327 cpfseq POSTINC2 ; compare read-back with original
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1328 bsf i2c_error_flag ; Not equal, set flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1329 bsf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1330 bsf SSP1CON2,ACKEN ; Master NOT acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1331 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1332 bcf SSP1CON2,ACKDT ; Reset ACKDT flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1333
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1334 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1335 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1336 WAITMS .1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1337
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1338 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1339 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1340 movlw 0x50 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1341 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1342 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1343 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1344 movlw 0x1F ; Write command!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1345 movwf SSP1BUF ; Data Byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1346 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1347 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1348 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1349 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1350 WAITMS .5 ; Required waiting time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1351
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1352 btfss i2c_error_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1353 retlw .0 ; All ok
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1354 retlw .255 ; an error occurred
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1355
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1356 ENDIF
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1357
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1358 END