annotate src/i2c.asm @ 165:9b82239fa062

testing consumption
author heinrichsweikamp
date Thu, 11 Sep 2014 15:41:48 +0200
parents 683321c09cfa
children 30ebaf72170d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
heinrichsweikamp
parents:
diff changeset
3 ; File i2c.asm
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ; I2C Interface to HMC5883L and MMA8452Q
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; HMC5883L's read address (8-Bit): 0x3D
heinrichsweikamp
parents:
diff changeset
8 ; HMC5883L's write address (8-Bit): 0x3C
heinrichsweikamp
parents:
diff changeset
9 ;
heinrichsweikamp
parents:
diff changeset
10 ; MMA8452Q's read address (8-Bit): 0x39
heinrichsweikamp
parents:
diff changeset
11 ; MMA8452Q's write address (8-Bit): 0x38
heinrichsweikamp
parents:
diff changeset
12 ;
heinrichsweikamp
parents:
diff changeset
13 ; Copyright (c) 2012, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
14 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
15 ; HISTORY
heinrichsweikamp
parents:
diff changeset
16 ; 2012-08-22 : [mH] Creation
heinrichsweikamp
parents:
diff changeset
17
heinrichsweikamp
parents:
diff changeset
18
heinrichsweikamp
parents:
diff changeset
19 #include "ostc3.inc" ; Mandatory header
heinrichsweikamp
parents:
diff changeset
20 #include "wait.inc"
113
heinrichsweikamp
parents: 20
diff changeset
21 #include "math.inc"
heinrichsweikamp
parents: 20
diff changeset
22
heinrichsweikamp
parents: 20
diff changeset
23 #DEFINE battery_offset .27302 ; 65536-(3,25Ah/0,085mAh)
heinrichsweikamp
parents: 20
diff changeset
24 #DEFINE battery_devider .382 ; 3,25Ah/0,085mAh/100 [%]
0
heinrichsweikamp
parents:
diff changeset
25
heinrichsweikamp
parents:
diff changeset
26 i2c CODE
heinrichsweikamp
parents:
diff changeset
27
heinrichsweikamp
parents:
diff changeset
28 WaitMSSP:
heinrichsweikamp
parents:
diff changeset
29 decfsz i2c_temp,F ; check for timeout during I2C action
heinrichsweikamp
parents:
diff changeset
30 bra WaitMSSP2
heinrichsweikamp
parents:
diff changeset
31 bra I2CFail ; timeout occured
heinrichsweikamp
parents:
diff changeset
32 WaitMSSP2:
heinrichsweikamp
parents:
diff changeset
33 btfss PIR1,SSPIF
heinrichsweikamp
parents:
diff changeset
34 bra WaitMSSP
heinrichsweikamp
parents:
diff changeset
35 clrf i2c_temp
heinrichsweikamp
parents:
diff changeset
36 bcf PIR1,SSPIF
heinrichsweikamp
parents:
diff changeset
37 nop
heinrichsweikamp
parents:
diff changeset
38 return
heinrichsweikamp
parents:
diff changeset
39
heinrichsweikamp
parents:
diff changeset
40 I2C_WaitforACK:
heinrichsweikamp
parents:
diff changeset
41 btfss SSPCON2,ACKSTAT ; checks for ACK bit from slave
heinrichsweikamp
parents:
diff changeset
42 return
heinrichsweikamp
parents:
diff changeset
43 I2CFail:
heinrichsweikamp
parents:
diff changeset
44 rcall I2CReset ; I2C Reset
heinrichsweikamp
parents:
diff changeset
45 bcf PIR1,SSPIF
heinrichsweikamp
parents:
diff changeset
46 clrf i2c_temp
heinrichsweikamp
parents:
diff changeset
47 return
heinrichsweikamp
parents:
diff changeset
48
heinrichsweikamp
parents:
diff changeset
49 I2CReset: ; Something went wrong (Slave holds SDA low?)
heinrichsweikamp
parents:
diff changeset
50 clrf SSP1CON1 ; wake-up slave and reset entire module
heinrichsweikamp
parents:
diff changeset
51 clrf SSP1CON2
heinrichsweikamp
parents:
diff changeset
52 clrf SSP1STAT
heinrichsweikamp
parents:
diff changeset
53 bcf TRISC,3 ; SCL OUTPUT
heinrichsweikamp
parents:
diff changeset
54 bsf TRISC,4 ; SDA Input
heinrichsweikamp
parents:
diff changeset
55 bcf PORTC,3
heinrichsweikamp
parents:
diff changeset
56 movlw d'9'
heinrichsweikamp
parents:
diff changeset
57 movwf i2c_temp ; clock-out 9 clock cycles manually
heinrichsweikamp
parents:
diff changeset
58 I2CReset_1:
heinrichsweikamp
parents:
diff changeset
59 bsf PORTC,3 ; SCL=1
heinrichsweikamp
parents:
diff changeset
60 nop
heinrichsweikamp
parents:
diff changeset
61 nop
heinrichsweikamp
parents:
diff changeset
62 nop
heinrichsweikamp
parents:
diff changeset
63 nop
heinrichsweikamp
parents:
diff changeset
64 btfsc PORTC,4 ; SDA=1?
heinrichsweikamp
parents:
diff changeset
65 bra I2CReset_2 ; =1, SDA has been released from slave
heinrichsweikamp
parents:
diff changeset
66 bcf PORTC,3 ; SCL=0
heinrichsweikamp
parents:
diff changeset
67 nop
heinrichsweikamp
parents:
diff changeset
68 nop
heinrichsweikamp
parents:
diff changeset
69 bcf PORTC,3
heinrichsweikamp
parents:
diff changeset
70 nop
heinrichsweikamp
parents:
diff changeset
71 nop
heinrichsweikamp
parents:
diff changeset
72 decfsz i2c_temp,F
heinrichsweikamp
parents:
diff changeset
73 bra I2CReset_1 ; check for nine clock cycles
heinrichsweikamp
parents:
diff changeset
74 I2CReset_2:
heinrichsweikamp
parents:
diff changeset
75 bsf TRISC,3 ; SCL Input
heinrichsweikamp
parents:
diff changeset
76 clrf SSP1CON1 ; setup I²C Mode
heinrichsweikamp
parents:
diff changeset
77 WAITMS d'10' ; Reset-Timeout for I2C devices
heinrichsweikamp
parents:
diff changeset
78 movlw b'00000000' ; with slew rate control
heinrichsweikamp
parents:
diff changeset
79 movwf SSPSTAT
heinrichsweikamp
parents:
diff changeset
80 movlw b'00101000'
heinrichsweikamp
parents:
diff changeset
81 movwf SSP1CON1
heinrichsweikamp
parents:
diff changeset
82 movlw b'00000000'
heinrichsweikamp
parents:
diff changeset
83 movwf SSP1CON2
heinrichsweikamp
parents:
diff changeset
84 movlw 0x27
heinrichsweikamp
parents:
diff changeset
85 movwf SSP1ADD
heinrichsweikamp
parents:
diff changeset
86 return
heinrichsweikamp
parents:
diff changeset
87
heinrichsweikamp
parents:
diff changeset
88 I2C_TX:
heinrichsweikamp
parents:
diff changeset
89 movwf SSP1BUF
heinrichsweikamp
parents:
diff changeset
90 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
91 bra I2C_WaitforACK ; Returns...
heinrichsweikamp
parents:
diff changeset
92
heinrichsweikamp
parents:
diff changeset
93 I2C_TwoBytesRX_div16: ; Get two bytes and devide lo:hi/16 (signed)
heinrichsweikamp
parents:
diff changeset
94 rcall I2C_OneByteRX ; Get one byte
heinrichsweikamp
parents:
diff changeset
95 movff SSP1BUF,hi ; Data Byte
heinrichsweikamp
parents:
diff changeset
96 rcall I2C_OneByteRX ; Get one byte
heinrichsweikamp
parents:
diff changeset
97 movff SSP1BUF,lo ; Data Byte
heinrichsweikamp
parents:
diff changeset
98 I2C_TwoBytesRX_div16_2: ; devide lo:hi/16 (signed) only
heinrichsweikamp
parents:
diff changeset
99 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
100 btfsc hi,7 ; Copy sign bit to carry
heinrichsweikamp
parents:
diff changeset
101 bsf STATUS,C
heinrichsweikamp
parents:
diff changeset
102 rrcf hi ; /2
heinrichsweikamp
parents:
diff changeset
103 rrcf lo
heinrichsweikamp
parents:
diff changeset
104 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
105 btfsc hi,7 ; Copy sign bit to carry
heinrichsweikamp
parents:
diff changeset
106 bsf STATUS,C
heinrichsweikamp
parents:
diff changeset
107 rrcf hi ; /4
heinrichsweikamp
parents:
diff changeset
108 rrcf lo
heinrichsweikamp
parents:
diff changeset
109 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
110 btfsc hi,7 ; Copy sign bit to carry
heinrichsweikamp
parents:
diff changeset
111 bsf STATUS,C
heinrichsweikamp
parents:
diff changeset
112 rrcf hi ; /8
heinrichsweikamp
parents:
diff changeset
113 rrcf lo
heinrichsweikamp
parents:
diff changeset
114 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
115 btfsc hi,7 ; Copy sign bit to carry
heinrichsweikamp
parents:
diff changeset
116 bsf STATUS,C
heinrichsweikamp
parents:
diff changeset
117 rrcf hi ; /16
heinrichsweikamp
parents:
diff changeset
118 rrcf lo
heinrichsweikamp
parents:
diff changeset
119 return
heinrichsweikamp
parents:
diff changeset
120
heinrichsweikamp
parents:
diff changeset
121 global I2C_RX_accelerometer
heinrichsweikamp
parents:
diff changeset
122 I2C_RX_accelerometer:
heinrichsweikamp
parents:
diff changeset
123 bsf SSP1CON2,SEN ; Start condition
heinrichsweikamp
parents:
diff changeset
124 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
125 movlw 0x38 ; address
heinrichsweikamp
parents:
diff changeset
126 rcall I2C_TX
158
683321c09cfa nicer boot into surfacemode
heinrichsweikamp
parents: 113
diff changeset
127 movlw 0x00
0
heinrichsweikamp
parents:
diff changeset
128 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
129 bsf SSP1CON2,RSEN ; Repeated start condition (!)
heinrichsweikamp
parents:
diff changeset
130 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
131 movlw 0x39 ; address
heinrichsweikamp
parents:
diff changeset
132 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
133
158
683321c09cfa nicer boot into surfacemode
heinrichsweikamp
parents: 113
diff changeset
134 rcall I2C_OneByteRX ; Get Status Byte
683321c09cfa nicer boot into surfacemode
heinrichsweikamp
parents: 113
diff changeset
135 movf SSP1BUF,W
683321c09cfa nicer boot into surfacemode
heinrichsweikamp
parents: 113
diff changeset
136
0
heinrichsweikamp
parents:
diff changeset
137 ; Chip orientation on the PCB requires
heinrichsweikamp
parents:
diff changeset
138 ; Original = Corrected
heinrichsweikamp
parents:
diff changeset
139 ; x = -x
heinrichsweikamp
parents:
diff changeset
140 ; y = -y
heinrichsweikamp
parents:
diff changeset
141 ; z = -z
heinrichsweikamp
parents:
diff changeset
142
heinrichsweikamp
parents:
diff changeset
143 rcall I2C_TwoBytesRX_div16 ; Get two bytes and devide /16 (signed)
heinrichsweikamp
parents:
diff changeset
144 comf hi ; 16bit sign change.
heinrichsweikamp
parents:
diff changeset
145 negf lo
heinrichsweikamp
parents:
diff changeset
146 btfsc STATUS,C ; Carry to propagate ?
heinrichsweikamp
parents:
diff changeset
147 incf hi,F ; YES: do it.
heinrichsweikamp
parents:
diff changeset
148 movff lo,accel_DX+0
heinrichsweikamp
parents:
diff changeset
149 movff hi,accel_DX+1 ; Copy result
heinrichsweikamp
parents:
diff changeset
150
heinrichsweikamp
parents:
diff changeset
151 rcall I2C_TwoBytesRX_div16 ; Get two bytes and devide /16 (signed)
heinrichsweikamp
parents:
diff changeset
152 comf hi ; 16bit sign change.
heinrichsweikamp
parents:
diff changeset
153 negf lo
heinrichsweikamp
parents:
diff changeset
154 btfsc STATUS,C ; Carry to propagate ?
heinrichsweikamp
parents:
diff changeset
155 incf hi,F ; YES: do it.
heinrichsweikamp
parents:
diff changeset
156 movff lo,accel_DY+0
heinrichsweikamp
parents:
diff changeset
157 movff hi,accel_DY+1 ; Copy result
heinrichsweikamp
parents:
diff changeset
158
heinrichsweikamp
parents:
diff changeset
159 rcall I2C_OneByteRX ; Get one byte
heinrichsweikamp
parents:
diff changeset
160 movff SSP1BUF,hi ; Data Byte
heinrichsweikamp
parents:
diff changeset
161 bsf SSP1CON2, RCEN ; Enable recieve mode
heinrichsweikamp
parents:
diff changeset
162 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
163 ; According to datasheet there should be no Master Acknowlegde for the last Byte (accel_DZ+0)...
heinrichsweikamp
parents:
diff changeset
164 movff SSP1BUF,lo ; Data Byte
heinrichsweikamp
parents:
diff changeset
165
heinrichsweikamp
parents:
diff changeset
166 rcall I2C_TwoBytesRX_div16_2; devide lo:hi/16 (signed) only
heinrichsweikamp
parents:
diff changeset
167 comf hi ; 16bit sign change.
heinrichsweikamp
parents:
diff changeset
168 negf lo
heinrichsweikamp
parents:
diff changeset
169 btfsc STATUS,C ; Carry to propagate ?
heinrichsweikamp
parents:
diff changeset
170 incf hi,F ; YES: do it.
heinrichsweikamp
parents:
diff changeset
171 movff lo,accel_DZ+0
heinrichsweikamp
parents:
diff changeset
172 movff hi,accel_DZ+1 ; Copy result
heinrichsweikamp
parents:
diff changeset
173
heinrichsweikamp
parents:
diff changeset
174 bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents:
diff changeset
175 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
176 return
heinrichsweikamp
parents:
diff changeset
177
heinrichsweikamp
parents:
diff changeset
178 I2C_OneByteRX:
heinrichsweikamp
parents:
diff changeset
179 bsf SSP1CON2, RCEN ; Enable recieve mode
heinrichsweikamp
parents:
diff changeset
180 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
181 bsf SSP1CON2,ACKEN ; Master acknowlegde
heinrichsweikamp
parents:
diff changeset
182 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
183 return
heinrichsweikamp
parents:
diff changeset
184
heinrichsweikamp
parents:
diff changeset
185 global I2C_RX_compass
heinrichsweikamp
parents:
diff changeset
186 I2C_RX_compass:
heinrichsweikamp
parents:
diff changeset
187 bsf SSP1CON2,SEN ; Start condition
heinrichsweikamp
parents:
diff changeset
188 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
189 movlw 0x3C ; address
heinrichsweikamp
parents:
diff changeset
190 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
191 movlw 0x03
heinrichsweikamp
parents:
diff changeset
192 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
193 bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents:
diff changeset
194 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
195
heinrichsweikamp
parents:
diff changeset
196 bcf PIR1,SSPIF
heinrichsweikamp
parents:
diff changeset
197 bsf SSP1CON2,SEN ; Start condition
heinrichsweikamp
parents:
diff changeset
198 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
199 movlw 0x3D ; address
heinrichsweikamp
parents:
diff changeset
200 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
201
heinrichsweikamp
parents:
diff changeset
202 ; Compass IC sends data in following order:
heinrichsweikamp
parents:
diff changeset
203 ; x MSB
heinrichsweikamp
parents:
diff changeset
204 ; x LSB
heinrichsweikamp
parents:
diff changeset
205 ; z MSB
heinrichsweikamp
parents:
diff changeset
206 ; z LSB
heinrichsweikamp
parents:
diff changeset
207 ; y MSB
heinrichsweikamp
parents:
diff changeset
208 ; y LSB
heinrichsweikamp
parents:
diff changeset
209
heinrichsweikamp
parents:
diff changeset
210 ; Chip orientation on the PCB requires
heinrichsweikamp
parents:
diff changeset
211 ; Original = Corrected
heinrichsweikamp
parents:
diff changeset
212 ; x = -y
heinrichsweikamp
parents:
diff changeset
213 ; z = z
heinrichsweikamp
parents:
diff changeset
214 ; y = x
heinrichsweikamp
parents:
diff changeset
215
heinrichsweikamp
parents:
diff changeset
216 rcall I2C_OneByteRX ; Get one byte
heinrichsweikamp
parents:
diff changeset
217 movff SSP1BUF,compass_DY+1; Data Byte
heinrichsweikamp
parents:
diff changeset
218 rcall I2C_OneByteRX ; Get one byte
heinrichsweikamp
parents:
diff changeset
219 movff SSP1BUF,compass_DY+0; Data Byte
heinrichsweikamp
parents:
diff changeset
220 banksel compass_DY
heinrichsweikamp
parents:
diff changeset
221 comf compass_DY+1 ; 16bit sign change.
heinrichsweikamp
parents:
diff changeset
222 negf compass_DY+0
heinrichsweikamp
parents:
diff changeset
223 btfsc STATUS,C ; Carry to propagate ?
heinrichsweikamp
parents:
diff changeset
224 incf compass_DY+1,F ; YES: do it.
heinrichsweikamp
parents:
diff changeset
225 banksel common
heinrichsweikamp
parents:
diff changeset
226 rcall I2C_OneByteRX ; Get one byte
heinrichsweikamp
parents:
diff changeset
227 movff SSP1BUF,compass_DZ+1; Data Byte
heinrichsweikamp
parents:
diff changeset
228 rcall I2C_OneByteRX ; Get one byte
heinrichsweikamp
parents:
diff changeset
229 movff SSP1BUF,compass_DZ+0; Data Byte
heinrichsweikamp
parents:
diff changeset
230 rcall I2C_OneByteRX ; Get one byte
heinrichsweikamp
parents:
diff changeset
231 movff SSP1BUF,compass_DX+1; Data Byte
heinrichsweikamp
parents:
diff changeset
232 bsf SSP1CON2, RCEN ; Enable recieve mode
heinrichsweikamp
parents:
diff changeset
233 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
234 movff SSP1BUF,compass_DX+0; Data Byte
heinrichsweikamp
parents:
diff changeset
235 bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents:
diff changeset
236 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
237 return
heinrichsweikamp
parents:
diff changeset
238
heinrichsweikamp
parents:
diff changeset
239 global I2C_init_compass
heinrichsweikamp
parents:
diff changeset
240 I2C_init_compass:
heinrichsweikamp
parents:
diff changeset
241 bsf SSP1CON2,SEN ; Start condition
heinrichsweikamp
parents:
diff changeset
242 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
243 movlw 0x3C ; address
heinrichsweikamp
parents:
diff changeset
244 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
245 movlw 0x00
heinrichsweikamp
parents:
diff changeset
246 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
247 ; movlw b'01101001' ; ConfigA: 3Hz, 8 Samples averaged, Test Mode (Positive Bias)
heinrichsweikamp
parents:
diff changeset
248 movlw b'01101000' ; ConfigA: 3Hz, 8 Samples averaged
heinrichsweikamp
parents:
diff changeset
249 rcall I2C_TX
20
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
250 bra I2C_init_compass_common
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
251
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
252 global I2C_init_compass_fast
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
253 I2C_init_compass_fast:
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
254 bsf SSP1CON2,SEN ; Start condition
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
255 rcall WaitMSSP
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
256 movlw 0x3C ; address
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
257 rcall I2C_TX
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
258 movlw 0x00
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
259 rcall I2C_TX
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
260 movlw b'00111000' ; ConfigA: 75Hz, 2 Samples averaged
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
261 ; movlw b'00111001' ; ConfigA: 75Hz, 2 Samples averaged, Test Mode (Positive Bias)
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
262 rcall I2C_TX
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
263 I2C_init_compass_common:
18
4e3f133dfbf4 add new opt_compass_gain option to work with more magnetic battery types
heinrichsweikamp
parents: 0
diff changeset
264 movff opt_compass_gain,i2c_temp ; 0-7 (230LSB/Gauss to 1370LSB/Gaus)
4e3f133dfbf4 add new opt_compass_gain option to work with more magnetic battery types
heinrichsweikamp
parents: 0
diff changeset
265 swapf i2c_temp,F
4e3f133dfbf4 add new opt_compass_gain option to work with more magnetic battery types
heinrichsweikamp
parents: 0
diff changeset
266 comf i2c_temp,F
4e3f133dfbf4 add new opt_compass_gain option to work with more magnetic battery types
heinrichsweikamp
parents: 0
diff changeset
267 bcf STATUS,C
4e3f133dfbf4 add new opt_compass_gain option to work with more magnetic battery types
heinrichsweikamp
parents: 0
diff changeset
268 rlcf i2c_temp
4e3f133dfbf4 add new opt_compass_gain option to work with more magnetic battery types
heinrichsweikamp
parents: 0
diff changeset
269 movf i2c_temp,W
4e3f133dfbf4 add new opt_compass_gain option to work with more magnetic battery types
heinrichsweikamp
parents: 0
diff changeset
270 clrf i2c_temp
0
heinrichsweikamp
parents:
diff changeset
271 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
272 movlw b'00000000' ; Continous Mode
heinrichsweikamp
parents:
diff changeset
273 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
274 bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents:
diff changeset
275 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
276 bsf compass_enabled
heinrichsweikamp
parents:
diff changeset
277 return
heinrichsweikamp
parents:
diff changeset
278
heinrichsweikamp
parents:
diff changeset
279 global I2C_sleep_compass
heinrichsweikamp
parents:
diff changeset
280 I2C_sleep_compass:
heinrichsweikamp
parents:
diff changeset
281 bsf SSP1CON2,SEN ; Start condition
heinrichsweikamp
parents:
diff changeset
282 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
283 movlw 0x3C ; address
heinrichsweikamp
parents:
diff changeset
284 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
285 movlw 0x00
heinrichsweikamp
parents:
diff changeset
286 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
287 movlw b'01101000' ; ConfigA
heinrichsweikamp
parents:
diff changeset
288 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
289 movlw b'00100000' ; ConfigB
heinrichsweikamp
parents:
diff changeset
290 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
291 movlw b'00000010' ; Idle Mode
heinrichsweikamp
parents:
diff changeset
292 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
293 bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents:
diff changeset
294 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
295 bcf compass_enabled
heinrichsweikamp
parents:
diff changeset
296 return
heinrichsweikamp
parents:
diff changeset
297
heinrichsweikamp
parents:
diff changeset
298
heinrichsweikamp
parents:
diff changeset
299 global I2C_init_accelerometer
heinrichsweikamp
parents:
diff changeset
300 I2C_init_accelerometer:
heinrichsweikamp
parents:
diff changeset
301 rcall I2C_sleep_accelerometer ; Regs can only be changed in St.By mode
heinrichsweikamp
parents:
diff changeset
302
heinrichsweikamp
parents:
diff changeset
303 bsf SSP1CON2,SEN ; Start condition
heinrichsweikamp
parents:
diff changeset
304 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
305 movlw 0x38 ; address
heinrichsweikamp
parents:
diff changeset
306 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
307 movlw 0x0E ; XYZ_DATA_CFG
heinrichsweikamp
parents:
diff changeset
308 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
309 movlw b'00000000' ; High pass Filter=0 , +/- 2g range
heinrichsweikamp
parents:
diff changeset
310 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
311 bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents:
diff changeset
312 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
313
heinrichsweikamp
parents:
diff changeset
314
heinrichsweikamp
parents:
diff changeset
315 bsf SSP1CON2,SEN ; Start condition
heinrichsweikamp
parents:
diff changeset
316 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
317 movlw 0x38 ; address
heinrichsweikamp
parents:
diff changeset
318 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
319 movlw 0x2A ; CTRL_REG1
heinrichsweikamp
parents:
diff changeset
320 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
321 ; movlw b'00110000' ; CTRL_REG1: 160ms data rate, St.By Mode
heinrichsweikamp
parents:
diff changeset
322 movlw b'00110100' ; CTRL_REG1: 160ms data rate, St.By Mode, reduced noise mode
heinrichsweikamp
parents:
diff changeset
323 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
324 movlw b'00000010' ; CTRL_REG2: High Res in Active mode
heinrichsweikamp
parents:
diff changeset
325 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
326 bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents:
diff changeset
327 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
328
heinrichsweikamp
parents:
diff changeset
329 bsf SSP1CON2,SEN ; Start condition
heinrichsweikamp
parents:
diff changeset
330 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
331 movlw 0x38 ; address
heinrichsweikamp
parents:
diff changeset
332 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
333 movlw 0x2A ; CTRL_REG1
heinrichsweikamp
parents:
diff changeset
334 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
335 ; movlw b'00110001' ; CTRL_REG1: 160ms data rate, Active Mode
heinrichsweikamp
parents:
diff changeset
336 movlw b'00110101' ; CTRL_REG1: 160ms data rate, St.By Mode, reduced noise mode, Active Mode
heinrichsweikamp
parents:
diff changeset
337 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
338 bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents:
diff changeset
339 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
340
heinrichsweikamp
parents:
diff changeset
341 return
heinrichsweikamp
parents:
diff changeset
342
heinrichsweikamp
parents:
diff changeset
343 global I2C_sleep_accelerometer
heinrichsweikamp
parents:
diff changeset
344 I2C_sleep_accelerometer:
heinrichsweikamp
parents:
diff changeset
345 bsf SSP1CON2,SEN ; Start condition
heinrichsweikamp
parents:
diff changeset
346 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
347 movlw 0x38 ; address
heinrichsweikamp
parents:
diff changeset
348 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
349 movlw 0x2A ; CTRL_REG1
heinrichsweikamp
parents:
diff changeset
350 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
351 movlw b'00000000' ; St. By Mode
heinrichsweikamp
parents:
diff changeset
352 rcall I2C_TX
heinrichsweikamp
parents:
diff changeset
353 bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents:
diff changeset
354 rcall WaitMSSP
heinrichsweikamp
parents:
diff changeset
355 return
heinrichsweikamp
parents:
diff changeset
356
113
heinrichsweikamp
parents: 20
diff changeset
357 global lt2942_init
heinrichsweikamp
parents: 20
diff changeset
358 lt2942_init: ; Setup Control register B
heinrichsweikamp
parents: 20
diff changeset
359 clrf i2c_temp
heinrichsweikamp
parents: 20
diff changeset
360 movlw 0x01 ; Point to control reg B
heinrichsweikamp
parents: 20
diff changeset
361 call I2C_TX_GAUGE
heinrichsweikamp
parents: 20
diff changeset
362 movlw b'11111000' ; Automatic conversion every two seconds
heinrichsweikamp
parents: 20
diff changeset
363 movff WREG, SSP1BUF ; Data Byte
heinrichsweikamp
parents: 20
diff changeset
364 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
365 rcall I2C_WaitforACK
heinrichsweikamp
parents: 20
diff changeset
366 bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents: 20
diff changeset
367 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
368 return
heinrichsweikamp
parents: 20
diff changeset
369
heinrichsweikamp
parents: 20
diff changeset
370 global lt2942_get_status
heinrichsweikamp
parents: 20
diff changeset
371 lt2942_get_status: ; Read status register
heinrichsweikamp
parents: 20
diff changeset
372 bcf c3_hardware ; Clear flag
heinrichsweikamp
parents: 20
diff changeset
373 clrf i2c_temp
heinrichsweikamp
parents: 20
diff changeset
374 movlw 0x00 ; Point to Status reg
heinrichsweikamp
parents: 20
diff changeset
375 call I2C_TX_GAUGE
heinrichsweikamp
parents: 20
diff changeset
376 call I2C_RX_GAUGE
heinrichsweikamp
parents: 20
diff changeset
377 movff SSP1BUF,WREG
heinrichsweikamp
parents: 20
diff changeset
378 btfss WREG,7 ; 2942 found?
heinrichsweikamp
parents: 20
diff changeset
379 bsf c3_hardware ; Yes, set flag
heinrichsweikamp
parents: 20
diff changeset
380 bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents: 20
diff changeset
381 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
382 return
heinrichsweikamp
parents: 20
diff changeset
383
heinrichsweikamp
parents: 20
diff changeset
384
heinrichsweikamp
parents: 20
diff changeset
385 global lt2942_get_voltage
heinrichsweikamp
parents: 20
diff changeset
386 lt2942_get_voltage: ; Read battery voltage registers
heinrichsweikamp
parents: 20
diff changeset
387 clrf i2c_temp
heinrichsweikamp
parents: 20
diff changeset
388 movlw 0x08 ; Point to voltage registers
heinrichsweikamp
parents: 20
diff changeset
389 call I2C_TX_GAUGE
heinrichsweikamp
parents: 20
diff changeset
390 call I2C_RX_GAUGE
heinrichsweikamp
parents: 20
diff changeset
391 bsf SSP1CON2,ACKEN ; Master acknowlegde
heinrichsweikamp
parents: 20
diff changeset
392 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
393 movff SSP1BUF,xA+1
heinrichsweikamp
parents: 20
diff changeset
394 bsf SSP1CON2, RCEN ; Enable recieve mode
heinrichsweikamp
parents: 20
diff changeset
395 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
396 movff SSP1BUF,xA+0
heinrichsweikamp
parents: 20
diff changeset
397 bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents: 20
diff changeset
398 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
399
heinrichsweikamp
parents: 20
diff changeset
400 ; banksel common
heinrichsweikamp
parents: 20
diff changeset
401 ; xA:2 loaded with raw values
heinrichsweikamp
parents: 20
diff changeset
402 movlw LOW .6000
heinrichsweikamp
parents: 20
diff changeset
403 movwf xB+0
heinrichsweikamp
parents: 20
diff changeset
404 movlw HIGH .6000
heinrichsweikamp
parents: 20
diff changeset
405 movwf xB+1
heinrichsweikamp
parents: 20
diff changeset
406 call mult16x16 ;xA*xB=xC
heinrichsweikamp
parents: 20
diff changeset
407
heinrichsweikamp
parents: 20
diff changeset
408 ; devide xC (32bit)/65535 for result in mV (16bit)
heinrichsweikamp
parents: 20
diff changeset
409 movlw .16
heinrichsweikamp
parents: 20
diff changeset
410 movwf i2c_temp
heinrichsweikamp
parents: 20
diff changeset
411 lt2942_get_voltage2:
heinrichsweikamp
parents: 20
diff changeset
412 bcf STATUS,C
heinrichsweikamp
parents: 20
diff changeset
413 rrcf xC+3,F
heinrichsweikamp
parents: 20
diff changeset
414 rrcf xC+2,F
heinrichsweikamp
parents: 20
diff changeset
415 rrcf xC+1,F
heinrichsweikamp
parents: 20
diff changeset
416 rrcf xC+0,F
heinrichsweikamp
parents: 20
diff changeset
417 decfsz i2c_temp,F
heinrichsweikamp
parents: 20
diff changeset
418 bra lt2942_get_voltage2
heinrichsweikamp
parents: 20
diff changeset
419
heinrichsweikamp
parents: 20
diff changeset
420 ; Update battery voltage in mV
heinrichsweikamp
parents: 20
diff changeset
421 movff xC+1,batt_voltage+1
heinrichsweikamp
parents: 20
diff changeset
422 movff xC+0,batt_voltage+0
heinrichsweikamp
parents: 20
diff changeset
423 return
heinrichsweikamp
parents: 20
diff changeset
424
heinrichsweikamp
parents: 20
diff changeset
425 ; global lt2942_get_temperature
heinrichsweikamp
parents: 20
diff changeset
426 ;lt2942_get_temperature: ; Read temperature registers
heinrichsweikamp
parents: 20
diff changeset
427 ; clrf i2c_temp
heinrichsweikamp
parents: 20
diff changeset
428 ; movlw 0x0C ; Point to temperature registers
heinrichsweikamp
parents: 20
diff changeset
429 ; call I2C_TX_GAUGE
heinrichsweikamp
parents: 20
diff changeset
430 ; call I2C_RX
heinrichsweikamp
parents: 20
diff changeset
431 ; bsf SSP1CON2,ACKEN ; Master acknowlegde
heinrichsweikamp
parents: 20
diff changeset
432 ; rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
433 ; movff SSP1BUF,xA+1
heinrichsweikamp
parents: 20
diff changeset
434 ; bsf SSP1CON2, RCEN ; Enable recieve mode
heinrichsweikamp
parents: 20
diff changeset
435 ; rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
436 ; movff SSP1BUF,xA+0
heinrichsweikamp
parents: 20
diff changeset
437 ; bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents: 20
diff changeset
438 ; rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
439 ;
heinrichsweikamp
parents: 20
diff changeset
440 ;; banksel common
heinrichsweikamp
parents: 20
diff changeset
441 ; ; xA:2 loaded with raw values
heinrichsweikamp
parents: 20
diff changeset
442 ; movlw LOW .6000
heinrichsweikamp
parents: 20
diff changeset
443 ; movwf xB+0
heinrichsweikamp
parents: 20
diff changeset
444 ; movlw HIGH .6000
heinrichsweikamp
parents: 20
diff changeset
445 ; movwf xB+1
heinrichsweikamp
parents: 20
diff changeset
446 ; call mult16x16 ;xA*xB=xC
heinrichsweikamp
parents: 20
diff changeset
447 ;
heinrichsweikamp
parents: 20
diff changeset
448 ; ; devide xC (32bit)/65535 for result in 0.1K (16bit)
heinrichsweikamp
parents: 20
diff changeset
449 ; movlw .16
heinrichsweikamp
parents: 20
diff changeset
450 ; movwf i2c_temp
heinrichsweikamp
parents: 20
diff changeset
451 ;lt2942_get_temperature2:
heinrichsweikamp
parents: 20
diff changeset
452 ; bcf STATUS,C
heinrichsweikamp
parents: 20
diff changeset
453 ; rrcf xC+3,F
heinrichsweikamp
parents: 20
diff changeset
454 ; rrcf xC+2,F
heinrichsweikamp
parents: 20
diff changeset
455 ; rrcf xC+1,F
heinrichsweikamp
parents: 20
diff changeset
456 ; rrcf xC+0,F
heinrichsweikamp
parents: 20
diff changeset
457 ; decfsz i2c_temp,F
heinrichsweikamp
parents: 20
diff changeset
458 ; bra lt2942_get_temperature2
heinrichsweikamp
parents: 20
diff changeset
459 ;
heinrichsweikamp
parents: 20
diff changeset
460 ; movff xC+1,sub_a+1
heinrichsweikamp
parents: 20
diff changeset
461 ; movff xC+0,sub_a+0
heinrichsweikamp
parents: 20
diff changeset
462 ; movlw LOW .2731 ; Kelvin to Celcius offset
heinrichsweikamp
parents: 20
diff changeset
463 ; movwf sub_b+0
heinrichsweikamp
parents: 20
diff changeset
464 ; movlw HIGH .2731 ; Kelvin to Celcius offset
heinrichsweikamp
parents: 20
diff changeset
465 ; movwf sub_b+1
heinrichsweikamp
parents: 20
diff changeset
466 ; call subU16 ; sub_c = sub_a - sub_b (with UNSIGNED values)
heinrichsweikamp
parents: 20
diff changeset
467 ;
heinrichsweikamp
parents: 20
diff changeset
468 ; ; Update batttery_temperature in 0.1°C
heinrichsweikamp
parents: 20
diff changeset
469 ; movff sub_c+1,battery_temperature+1
heinrichsweikamp
parents: 20
diff changeset
470 ; movff sub_c+0,battery_temperature+0
heinrichsweikamp
parents: 20
diff changeset
471 ; return
heinrichsweikamp
parents: 20
diff changeset
472
heinrichsweikamp
parents: 20
diff changeset
473 global lt2942_get_accumulated_charge
heinrichsweikamp
parents: 20
diff changeset
474 lt2942_get_accumulated_charge: ; Read accumulated charge and compute percent
heinrichsweikamp
parents: 20
diff changeset
475 clrf i2c_temp
heinrichsweikamp
parents: 20
diff changeset
476 movlw 0x02 ; Point to accumulated charge registers
heinrichsweikamp
parents: 20
diff changeset
477 call I2C_TX_GAUGE
heinrichsweikamp
parents: 20
diff changeset
478 call I2C_RX_GAUGE
heinrichsweikamp
parents: 20
diff changeset
479 bsf SSP1CON2,ACKEN ; Master acknowlegde
heinrichsweikamp
parents: 20
diff changeset
480 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
481 movff SSP1BUF,sub_a+1 ; battery_acumulated_charge+1
heinrichsweikamp
parents: 20
diff changeset
482 bsf SSP1CON2, RCEN ; Enable recieve mode
heinrichsweikamp
parents: 20
diff changeset
483 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
484 movff SSP1BUF,sub_a+0 ; battery_acumulated_charge+0
heinrichsweikamp
parents: 20
diff changeset
485 bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents: 20
diff changeset
486 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
487
heinrichsweikamp
parents: 20
diff changeset
488 ; Compute batt_percent
heinrichsweikamp
parents: 20
diff changeset
489 ; charge-battery_offset/382
heinrichsweikamp
parents: 20
diff changeset
490 movlw LOW battery_offset
heinrichsweikamp
parents: 20
diff changeset
491 movwf sub_b+0
heinrichsweikamp
parents: 20
diff changeset
492 movlw HIGH battery_offset
heinrichsweikamp
parents: 20
diff changeset
493 movwf sub_b+1
heinrichsweikamp
parents: 20
diff changeset
494 call subU16 ; sub_c = sub_a - sub_b (with signed values)
heinrichsweikamp
parents: 20
diff changeset
495
heinrichsweikamp
parents: 20
diff changeset
496 clrf batt_percent ; Set to zero
heinrichsweikamp
parents: 20
diff changeset
497 btfsc neg_flag ; result negative?
heinrichsweikamp
parents: 20
diff changeset
498 return ; Yes, done.
heinrichsweikamp
parents: 20
diff changeset
499
heinrichsweikamp
parents: 20
diff changeset
500 ; > Zero, set batt_percent properly
heinrichsweikamp
parents: 20
diff changeset
501 movff sub_c+0,xA+0
heinrichsweikamp
parents: 20
diff changeset
502 movff sub_c+1,xA+1
heinrichsweikamp
parents: 20
diff changeset
503 movlw LOW battery_devider
heinrichsweikamp
parents: 20
diff changeset
504 movwf xB+0
heinrichsweikamp
parents: 20
diff changeset
505 movlw HIGH battery_devider
heinrichsweikamp
parents: 20
diff changeset
506 movwf xB+1
heinrichsweikamp
parents: 20
diff changeset
507 call div16x16 ;xA/xB=xC with xA+0 as remainder, uses divB as temp variable
heinrichsweikamp
parents: 20
diff changeset
508 movff xC+0,batt_percent
heinrichsweikamp
parents: 20
diff changeset
509 return
heinrichsweikamp
parents: 20
diff changeset
510
heinrichsweikamp
parents: 20
diff changeset
511 global lt2942_charge_done
heinrichsweikamp
parents: 20
diff changeset
512 lt2942_charge_done: ; Reset accumulating registers to 0xFFFF
heinrichsweikamp
parents: 20
diff changeset
513 clrf i2c_temp
heinrichsweikamp
parents: 20
diff changeset
514 movlw 0x02 ; Point to accumulated charge registers
heinrichsweikamp
parents: 20
diff changeset
515 call I2C_TX_GAUGE
heinrichsweikamp
parents: 20
diff changeset
516 movlw 0xFF
heinrichsweikamp
parents: 20
diff changeset
517 movff WREG, SSP1BUF ; Data Byte
heinrichsweikamp
parents: 20
diff changeset
518 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
519 rcall I2C_WaitforACK
heinrichsweikamp
parents: 20
diff changeset
520 movlw 0xFF
heinrichsweikamp
parents: 20
diff changeset
521 movff WREG, SSP1BUF ; Data Byte
heinrichsweikamp
parents: 20
diff changeset
522 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
523 rcall I2C_WaitforACK
heinrichsweikamp
parents: 20
diff changeset
524 bsf SSP1CON2,PEN ; Stop condition
heinrichsweikamp
parents: 20
diff changeset
525 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
526 return
heinrichsweikamp
parents: 20
diff changeset
527
heinrichsweikamp
parents: 20
diff changeset
528 I2C_TX_GAUGE: ; Sends a byte to the LT2942 Gauge IC
heinrichsweikamp
parents: 20
diff changeset
529 movwf i2c_temp+1 ; Data byte
heinrichsweikamp
parents: 20
diff changeset
530 bsf SSP1CON2,SEN ; Start condition
heinrichsweikamp
parents: 20
diff changeset
531 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
532 movlw b'11001000' ; Address byte + Write bit
heinrichsweikamp
parents: 20
diff changeset
533 movwf SSP1BUF ; control byte
heinrichsweikamp
parents: 20
diff changeset
534 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
535 rcall I2C_WaitforACK
heinrichsweikamp
parents: 20
diff changeset
536 movff i2c_temp+1, SSP1BUF ; Data Byte
heinrichsweikamp
parents: 20
diff changeset
537 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
538 rcall I2C_WaitforACK
heinrichsweikamp
parents: 20
diff changeset
539 return
heinrichsweikamp
parents: 20
diff changeset
540
heinrichsweikamp
parents: 20
diff changeset
541 I2C_RX_GAUGE:
heinrichsweikamp
parents: 20
diff changeset
542 bsf SSP1CON2,SEN ; Start condition
heinrichsweikamp
parents: 20
diff changeset
543 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
544 movlw b'11001001' ; Address byte + Read bit
heinrichsweikamp
parents: 20
diff changeset
545 movwf SSP1BUF ; control byte
heinrichsweikamp
parents: 20
diff changeset
546 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
547 rcall I2C_WaitforACK
heinrichsweikamp
parents: 20
diff changeset
548 bsf SSP1CON2, RCEN ; Enable recieve mode
heinrichsweikamp
parents: 20
diff changeset
549 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
550 return
heinrichsweikamp
parents: 20
diff changeset
551
heinrichsweikamp
parents: 20
diff changeset
552
0
heinrichsweikamp
parents:
diff changeset
553
heinrichsweikamp
parents:
diff changeset
554 END