comparison src/i2c.asm @ 556:dd28d4efd4d2

fix a potential issue in the battery managment
author heinrichsweikamp
date Thu, 07 Dec 2017 09:58:40 +0100
parents e8351dd7bb90
children b7eb98dbd800
comparison
equal deleted inserted replaced
555:98c564a2d6cc 556:dd28d4efd4d2
636 rcall I2C_TX 636 rcall I2C_TX
637 bsf SSP1CON2,PEN ; Stop condition 637 bsf SSP1CON2,PEN ; Stop condition
638 rcall WaitMSSP 638 rcall WaitMSSP
639 return 639 return
640 640
641 lt2942_init_again:
642 clrf i2c_temp
643 movlw 0x02 ; Point to accumulated charge registers
644 rcall I2C_TX_GAUGE
645 movff battery_acumulated_charge+1,SSP1BUF ; Data Byte
646 rcall WaitMSSP
647 rcall I2C_WaitforACK
648 movff battery_acumulated_charge+0,SSP1BUF ; Data Byte
649 rcall WaitMSSP
650 rcall I2C_WaitforACK
651 bsf SSP1CON2,PEN ; Stop condition
652 rcall WaitMSSP; (and return)
653 movff battery_acumulated_charge+1,sub_a+1
654 movff battery_acumulated_charge+0,sub_a+0
655 ; and init again...
641 global lt2942_init 656 global lt2942_init
642 lt2942_init: ; Setup Control register B 657 lt2942_init: ; Setup Control register B
643 clrf i2c_temp 658 clrf i2c_temp
644 movlw 0x01 ; Point to control reg B 659 movlw 0x01 ; Point to control reg B
645 rcall I2C_TX_GAUGE 660 rcall I2C_TX_GAUGE
785 bsf SSP1CON2,PEN ; Stop condition 800 bsf SSP1CON2,PEN ; Stop condition
786 rcall WaitMSSP 801 rcall WaitMSSP
787 802
788 movff gauge_status_byte,sub_b+0 ; copy into bank common 803 movff gauge_status_byte,sub_b+0 ; copy into bank common
789 btfsc sub_b+0,0 ; =1: UVLO Event 804 btfsc sub_b+0,0 ; =1: UVLO Event
790 rcall lt2942_init 805 rcall lt2942_init_again
791 806
792 movff sub_a+1,battery_acumulated_charge+1 ; Save raw value 807 movff sub_a+1,battery_acumulated_charge+1 ; Save raw value
793 movff sub_a+0,battery_acumulated_charge+0 ; Save raw value 808 movff sub_a+0,battery_acumulated_charge+0 ; Save raw value
794 809
795 ; Compute batt_percent 810 ; Compute batt_percent