comparison src/i2c.asm @ 640:8c1f1f334275

3.13 release
author heinrichsweikamp
date Thu, 29 Oct 2020 09:29:15 +0100
parents 4050675965ea
children 7d8a4c60ec1a 5b7fe7777425
comparison
equal deleted inserted replaced
639:0ff82370991d 640:8c1f1f334275
1001 global lt2942_init 1001 global lt2942_init
1002 lt2942_init: 1002 lt2942_init:
1003 movlw 0x01 ; point to control reg B 1003 movlw 0x01 ; point to control reg B
1004 rcall I2C_TX_GAUGE ; send byte to the LT2942 gauge IC 1004 rcall I2C_TX_GAUGE ; send byte to the LT2942 gauge IC
1005 movlw b'11111000' ; automatic conversion every two seconds 1005 movlw b'11111000' ; automatic conversion every two seconds
1006 movff WREG,SSP1BUF ; data byte TODO: movwf ?? 1006 movwf SSP1BUF ; data byte
1007 rcall WaitMSSP ; wait for TX to complete 1007 rcall WaitMSSP ; wait for TX to complete
1008 rcall I2C_Check_ACK ; check for acknowledge by receiver 1008 rcall I2C_Check_ACK ; check for acknowledge by receiver
1009 bsf SSP1CON2,PEN ; stop condition 1009 bsf SSP1CON2,PEN ; stop condition
1010 bra WaitMSSP ; wait for TX to complete and return 1010 bra WaitMSSP ; wait for TX to complete and return
1011 1011
1012 ;-----------------------------------------------------------------------------
1013 ; Sleep Gauge IC
1014 ;
1015 global lt2942_sleep
1016 lt2942_sleep:
1017 movlw 0x01 ; point to control reg B
1018 rcall I2C_TX_GAUGE ; send byte to the LT2942 gauge IC
1019 movlw b'00111000' ; sleep
1020 movwf SSP1BUF ; data byte
1021 rcall WaitMSSP ; wait for TX to complete
1022 rcall I2C_Check_ACK ; check for acknowledge by receiver
1023 bsf SSP1CON2,PEN ; stop condition
1024 bra WaitMSSP ; wait for TX to complete and return
1012 1025
1013 ;----------------------------------------------------------------------------- 1026 ;-----------------------------------------------------------------------------
1014 ; Read Gauge IC - Status Register 1027 ; Read Gauge IC - Status Register
1015 ; 1028 ;
1016 global lt2942_get_status 1029 global lt2942_get_status
1081 1094
1082 ; check if battery is being charged right now 1095 ; check if battery is being charged right now
1083 btfss cc_active ; in CC charging mode? 1096 btfss cc_active ; in CC charging mode?
1084 return ; NO - not charging, done 1097 return ; NO - not charging, done
1085 1098
1099 ; ignore false readings (>125°C)
1100 movlw LOW .3307
1101 movwf sub_a+0
1102 movlw HIGH .3307
1103 movwf sub_a+1
1104 MOVII battery_temperature, sub_b
1105 call cmpU16 ; sub_a - sub_b (with UNSIGNED values)
1106 btfsc neg_flag ; result negative?
1107 return ; YES - temperature > 125°C, not possible here. Skip test.
1108
1086 ; check for over-temperature while charging 1109 ; check for over-temperature while charging
1087 MOVLI max_battery_charge_temp,sub_a 1110 MOVLI max_battery_charge_temp,sub_a
1088 MOVII battery_temperature, sub_b 1111 MOVII battery_temperature, sub_b
1089 call cmpU16 ; sub_a - sub_b (with UNSIGNED values) 1112 call cmpU16 ; sub_a - sub_b (with UNSIGNED values)
1090 btfss neg_flag ; result negative? 1113 btfss neg_flag ; result negative?
1091 return ; NO - temperature <= threshold, ok, done 1114 return ; NO - temperature <= threshold, ok, done
1115 return
1092 ; YES - too hot, disable charging circuitry 1116 ; YES - too hot, disable charging circuitry
1093 bsf charge_disable ; - set charging-inhibit signal 1117 bsf charge_disable ; - set charging-inhibit signal
1094 bcf charge_enable ; - activate charging-inhibit signal 1118 bcf charge_enable ; - activate charging-inhibit signal
1095 bsf battery_overtemp ; - flag that the battery charging over-temperature protection has tripped 1119 bsf battery_overtemp ; - flag that the battery charging over-temperature protection has tripped
1096 return ; - done 1120 return ; - done