Mercurial > public > hwos_code
comparison src/i2c.asm @ 657:c2e97f94c55f default tip
bump to 10.93 / 3.32
| author | heinrichsweikamp |
|---|---|
| date | Tue, 27 Jan 2026 11:01:04 +0100 |
| parents | 8af5aefbcdaf |
| children |
comparison
equal
deleted
inserted
replaced
| 656:8af5aefbcdaf | 657:c2e97f94c55f |
|---|---|
| 996 global I2CReset | 996 global I2CReset |
| 997 I2CReset: | 997 I2CReset: |
| 998 clrf SSP1CON1 ; reset entire module | 998 clrf SSP1CON1 ; reset entire module |
| 999 clrf SSP1CON2 ; ... | 999 clrf SSP1CON2 ; ... |
| 1000 clrf SSP1STAT ; ... | 1000 clrf SSP1STAT ; ... |
| 1001 bcf TRISC,3 ; SCL as OUTPUT | 1001 bcf TRISC,3 ; SCL as OUTPUT |
| 1002 bsf TRISC,4 ; SDA as input | 1002 bsf TRISC,4 ; SDA as input |
| 1003 bcf PORTC,3 ; SCL = 0 | 1003 bcf PORTC,3 ; SCL = 0 |
| 1004 movlw d'9' ; clock-out 9 clock cycles manually | 1004 movlw d'9' ; clock-out 9 clock cycles manually |
| 1005 movwf i2c_temp1 ; ... | 1005 movwf i2c_temp1 ; ... |
| 1006 I2CReset_1: | 1006 I2CReset_1: |
| 1007 bsf PORTC,3 ; SCL = 1 | 1007 bsf PORTC,3 ; SCL = 1 |
| 1008 nop ; pause for 4 CPU cycles | 1008 nop ; pause for 4 CPU cycles |
| 1009 nop ; ... | 1009 nop ; ... |
| 1010 nop ; ... | 1010 nop ; ... |
| 1011 nop ; ... | 1011 nop ; ... |
| 1012 btfsc PORTC,4 ; SDA = 1 ? | 1012 btfsc PORTC,4 ; SDA = 1 ? |
| 1013 bra I2CReset_2 ; YES - SDA has been released from slave | 1013 bra I2CReset_2 ; YES - SDA has been released from slave |
| 1014 bcf PORTC,3 ; NO - set SCL = 0 | 1014 bcf PORTC,3 ; NO - set SCL = 0 |
| 1015 nop ; - pause for 2 CPU cycles | 1015 nop ; - pause for 2 CPU cycles |
| 1016 nop ; - ... | 1016 nop ; - ... |
| 1017 bcf PORTC,3 ; - SCL = 0 | 1017 bcf PORTC,3 ; - SCL = 0 |
| 1018 nop ; - pause for 2 CPU cycles | 1018 nop ; - pause for 2 CPU cycles |
| 1019 nop ; - ... | 1019 nop ; - ... |
| 1020 decfsz i2c_temp1,F ; - clock counter, all cycles done? | 1020 decfsz i2c_temp1,F ; - clock counter, all cycles done? |
| 1021 bra I2CReset_1 ; NO - loop | 1021 bra I2CReset_1 ; NO - loop |
| 1022 I2CReset_2: | 1022 I2CReset_2: |
| 1023 bsf TRISC,3 ; SCL as input | 1023 bsf TRISC,3 ; SCL as input |
| 1024 clrf SSP1CON1 ; setup I2C mode | 1024 clrf SSP1CON1 ; setup I2C mode |
| 1025 rcall I2C_WAIT_100US ; ISR-Safe 100µs wait | 1025 rcall I2C_WAIT_100US ; ISR-Safe 100µs wait |
| 1026 movlw b'00000000' ; enable slew rate control | 1026 movlw b'00000000' ; enable slew rate control |
| 1027 movwf SSP1STAT ; ... | 1027 movwf SSP1STAT ; ... |
| 1028 movlw b'00101000' ; configure I2C module | 1028 movlw b'00101000' ; configure I2C module |
| 1030 movlw b'00000000' ; ... | 1030 movlw b'00000000' ; ... |
| 1031 movwf SSP1CON2 ; ... | 1031 movwf SSP1CON2 ; ... |
| 1032 movlw i2c_speed_value | 1032 movlw i2c_speed_value |
| 1033 movwf SSP1ADD ; ... | 1033 movwf SSP1ADD ; ... |
| 1034 rcall I2C_WAIT_100US ; ISR-Safe 100µs wait | 1034 rcall I2C_WAIT_100US ; ISR-Safe 100µs wait |
| 1035 banksel i2c_error_counter | |
| 1035 movlw .1 | 1036 movlw .1 |
| 1036 addwf i2c_error_counter+0 | 1037 addwf i2c_error_counter+0,F |
| 1037 movlw .0 | 1038 movlw .0 |
| 1038 addwfc i2c_error_counter+1 ; +1 on the error counter | 1039 addwfc i2c_error_counter+1,F ; +1 on the error counter |
| 1040 banksel common | |
| 1039 btfss press_sensor_type ; =1: pressure sensor MS5837, =0: Pressure sensor MS5541 | 1041 btfss press_sensor_type ; =1: pressure sensor MS5837, =0: Pressure sensor MS5541 |
| 1040 return ; MS5541, Done. | 1042 return ; MS5541, Done. |
| 1043 btfss i2c_reinit_sensor2 ; Sensor ok? | |
| 1044 return ; Yes, Done. | |
| 1041 ; reset the sensor | 1045 ; reset the sensor |
| 1042 rcall I2C_SEN ; start condition | 1046 rcall I2C_SEN ; start condition |
| 1043 movlw 0xEC ; address byte + write bit | 1047 movlw 0xEC ; address byte + write bit |
| 1044 rcall I2C_TX ; send byte | 1048 rcall I2C_TX ; send byte |
| 1045 movlw 0x1E | 1049 movlw 0x1E |
| 1046 rcall I2C_TX ; send byte | 1050 rcall I2C_TX ; send byte |
| 1047 rcall I2C_PEN ; stop condition | 1051 rcall I2C_PEN ; stop condition |
| 1048 WAITMS .5 ; 2.8ms according to datasheet | 1052 movlw .50 |
| 1053 movwf i2c_temp1 | |
| 1054 I2CReset_3: | |
| 1055 rcall I2C_WAIT_100US ; ISR-Safe 100µs wait | |
| 1056 decfsz i2c_temp1,F | |
| 1057 bra I2CReset_3 ; ~5ms delay | |
| 1058 ; WAITMS .5 ; 2.8ms according to datasheet | |
| 1049 return ; done | 1059 return ; done |
| 1050 | 1060 |
| 1051 | 1061 |
| 1052 ;----------------------------------------------------------------------------- | 1062 ;----------------------------------------------------------------------------- |
| 1053 ; Helper Function - Initialize Gauge IC again after an UVLO Event | 1063 ; Helper Function - Initialize Gauge IC again after an UVLO Event |
