diff --git a/JK-BMSToPylontechCAN/EasyButtonAtInt01.h b/JK-BMSToPylontechCAN/EasyButtonAtInt01.h index 8d4a95b..19e03c1 100644 --- a/JK-BMSToPylontechCAN/EasyButtonAtInt01.h +++ b/JK-BMSToPylontechCAN/EasyButtonAtInt01.h @@ -26,7 +26,7 @@ * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the See the See the GNU General Public License for more details. + * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . diff --git a/JK-BMSToPylontechCAN/EasyButtonAtInt01.hpp b/JK-BMSToPylontechCAN/EasyButtonAtInt01.hpp index eaa1fb9..7c35eb4 100644 --- a/JK-BMSToPylontechCAN/EasyButtonAtInt01.hpp +++ b/JK-BMSToPylontechCAN/EasyButtonAtInt01.hpp @@ -28,7 +28,7 @@ * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the See the See the GNU General Public License for more details. + * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . diff --git a/JK-BMSToPylontechCAN/SoftI2CMaster.h b/JK-BMSToPylontechCAN/SoftI2CMaster.h index 528c06e..5388325 100644 --- a/JK-BMSToPylontechCAN/SoftI2CMaster.h +++ b/JK-BMSToPylontechCAN/SoftI2CMaster.h @@ -1,9 +1,9 @@ /* Arduino SoftI2C library. * SoftI2CMaster.h * - * Version 2.1.8 + * Version 2.1.9 * - * Copyright (C) 2013-2021, Bernhard Nebel and Peter Fleury + * Copyright (C) 2013-2023, Bernhard Nebel and Peter Fleury * * This is a very fast and very light-weight software I2C-master library * written in assembler. It is based on Peter Fleury's I2C software @@ -20,7 +20,7 @@ * * This Library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License @@ -98,9 +98,9 @@ #error "Not an AVR MCU! Use 'SlowSoftI2CMaster' library instead of 'SoftI2CMaster'!" #else /* - * No Guard here! + * The Guard was moved after the declarations! * If we include it with USE_SOFT_I2C_MASTER_H_AS_PLAIN_INCLUDE defined, - * we must allow, that it can be included again without USE_SOFT_I2C_MASTER_H_AS_PLAIN_INCLUDE defined + * we must allow, that it can be included again without USE_SOFT_I2C_MASTER_H_AS_PLAIN_INCLUDE defined. */ #include #include @@ -142,11 +142,13 @@ uint8_t __attribute__ ((noinline)) i2c_read(bool last) __attribute__ ((used)); */ void i2c_write_byte(uint8_t addr, uint8_t byte); -void i2c_read_buffer_from_register(uint8_t addr, uint8_t register_number, uint8_t * byte_buffer, uint8_t number_of_bytes_to_read); -void i2c_write_buffer_to_register(uint8_t addr, uint8_t register_number, uint8_t * byte_buffer, uint8_t number_of_bytes_to_write) ; +void i2c_read_buffer_from_register(uint8_t addr, uint8_t register_number, uint8_t *byte_buffer, uint8_t number_of_bytes_to_read); +void i2c_write_buffer_to_register(uint8_t addr, uint8_t register_number, uint8_t *byte_buffer, uint8_t number_of_bytes_to_write); -void i2c_read_buffer_from_16bit_register(uint8_t addr, uint16_t register_number, uint8_t * byte_buffer, uint8_t number_of_bytes_to_read); -void i2c_write_buffer_to_16bit_register(uint8_t addr, uint16_t register_number, uint8_t * byte_buffer, uint8_t number_of_bytes_to_write); +void i2c_read_buffer_from_16bit_register(uint8_t addr, uint16_t register_number, uint8_t *byte_buffer, + uint8_t number_of_bytes_to_read); +void i2c_write_buffer_to_16bit_register(uint8_t addr, uint16_t register_number, uint8_t *byte_buffer, + uint8_t number_of_bytes_to_write); // Read word from register, low byte first uint16_t i2c_read_word_from_register(uint8_t addr, uint8_t register_number); @@ -286,11 +288,11 @@ void i2c_delay_half(void) { // function call 3 cycles => 3C #else __asm__ __volatile__ ( - " ldi r25, %[DELAY] ;load delay constant ;; 4C \n\t" - "_Lidelay: \n\t" - " dec r25 ;decrement counter ;; 4C+xC \n\t" - " brne _Lidelay ;;5C+(x-1)2C+xC\n\t" - " ret ;; 9C+(x-1)2C+xC = 7C+xC" + " ldi r25, %[DELAY] ;load delay constant ;; 4C \n\t" + "_Lidelay: \n\t" + " dec r25 ;decrement counter ;; 4C+xC \n\t" + " brne _Lidelay ;;5C+(x-1)2C+xC\n\t" + " ret ;; 9C+(x-1)2C+xC = 7C+xC" : : [DELAY] "M" I2C_DELAY_COUNTER : "r25"); // 7 cycles + 3 times x cycles #endif @@ -300,14 +302,14 @@ void i2c_wait_scl_high(void) { #if I2C_TIMEOUT <= 0 __asm__ __volatile__ ("_Li2c_wait_stretch: \n\t" - " sbis %[SCLIN],%[SCLPIN] ;wait for SCL high \n\t" + " sbis %[SCLIN],%[SCLPIN] ;wait for SCL high \n\t" #if __AVR_HAVE_JMP_CALL__ - " jmp _Li2c_wait_stretch \n\t" + " jmp _Li2c_wait_stretch \n\t" #else - " rjmp _Li2c_wait_stretch \n\t" + " rjmp _Li2c_wait_stretch \n\t" #endif - " cln ;signal: no timeout \n\t" - " ret " + " cln ;signal: no timeout \n\t" + " ret " : : [SCLIN] "I" (SCL_IN), [SCLPIN] "I" (SCL_PIN)); #else // I2C_TIMEOUT <= 0 __asm__ __volatile__ @@ -317,9 +319,9 @@ void i2c_wait_scl_high(void) { " clr __tmp_reg__ ;do next loop 255 times \n\t" "_Lwait_stretch_inner_loop: \n\t" #if __AVR_HAVE_JMP_CALL__ - " call _Lcheck_scl_level ;call check function ;; 12C \n\t" + " call _Lcheck_scl_level ;call check function ;; 12C \n\t" #else - " rcall _Lcheck_scl_level ;call check function ;; 12C \n\t" + " rcall _Lcheck_scl_level ;call check function ;; 12C \n\t" #endif " brpl _Lstretch_done ;done if N=0 ;; +1 = 13C\n\t" " dec __tmp_reg__ ;dec inner loop counter;; +1 = 14C\n\t" @@ -343,9 +345,9 @@ void i2c_wait_scl_high(void) { " cln ;; +1C = 4C \n\t" " sbic %[SCLIN],%[SCLPIN] ;skip if SCL still low ;; +2C = 6C \n\t" #if __AVR_HAVE_JMP_CALL__ - " jmp _Lscl_high ;; +0C = 6C \n\t" + " jmp _Lscl_high ;; +0C = 6C \n\t" #else - " rjmp _Lscl_high ;; +0C = 6C \n\t" + " rjmp _Lscl_high ;; +0C = 6C \n\t" #endif " sen ;; +1 = 7C\n\t " "_Lscl_high: " @@ -395,25 +397,25 @@ bool i2c_init(void) { __asm__ __volatile__ (" cbi %[SDADDR],%[SDAPIN] ;release SDA \n\t" - " cbi %[SCLDDR],%[SCLPIN] ;release SCL \n\t" + " cbi %[SCLDDR],%[SCLPIN] ;release SCL \n\t" #if I2C_PULLUP - " sbi %[SDAOUT],%[SDAPIN] ;enable SDA pull-up\n\t" + " sbi %[SDAOUT],%[SDAPIN] ;enable SDA pull-up\n\t" #else - " cbi %[SDAOUT],%[SDAPIN] ;clear SDA output value \n\t" + " cbi %[SDAOUT],%[SDAPIN] ;clear SDA output value \n\t" #endif #if I2C_PULLUP - " sbi %[SCLOUT],%[SCLPIN] ;enable SCL pull-up\n\t" + " sbi %[SCLOUT],%[SCLPIN] ;enable SCL pull-up\n\t" #else - " cbi %[SCLOUT],%[SCLPIN] ;clear SCL output value \n\t" -#endif - " clr r24 ;set return value to false \n\t" - " clr r25 ;set return value to false \n\t" - " sbis %[SDAIN],%[SDAPIN] ;check for SDA high\n\t" - " ret ;if low return with false \n\t" - " sbis %[SCLIN],%[SCLPIN] ;check for SCL high \n\t" - " ret ;if low return with false \n\t" - " ldi r24,1 ;set return value to true \n\t" - " ret " + " cbi %[SCLOUT],%[SCLPIN] ;clear SCL output value \n\t" +#endif + " clr r24 ;set return value to false \n\t" + " clr r25 ;set return value to false \n\t" + " sbis %[SDAIN],%[SDAPIN] ;check for SDA high\n\t" + " ret ;if low return with false \n\t" + " sbis %[SCLIN],%[SCLPIN] ;check for SCL high \n\t" + " ret ;if low return with false \n\t" + " ldi r24,1 ;set return value to true \n\t" + " ret " : : [SCLDDR] "I" (SCL_DDR), [SCLPIN] "I" (SCL_PIN), [SCLIN] "I" (SCL_IN), [SCLOUT] "I" (SCL_OUT), @@ -467,26 +469,26 @@ bool i2c_start(uint8_t addr) __asm__ __volatile__ ( #if I2C_NOINTERRUPT - " cli ;clear IRQ bit \n\t" + " cli ;clear IRQ bit \n\t" #endif - " sbis %[SCLIN],%[SCLPIN] ;check for clock stretching slave\n\t" + " sbis %[SCLIN],%[SCLPIN] ;check for clock stretching slave\n\t" #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_wait_scl_high ;wait until SCL=H\n\t" + " call ass_i2c_wait_scl_high ;wait until SCL=H\n\t" #else - " rcall ass_i2c_wait_scl_high ;wait until SCL=H\n\t" + " rcall ass_i2c_wait_scl_high ;wait until SCL=H\n\t" #endif #if I2C_PULLUP - " cbi %[SDAOUT],%[SDAPIN] ;disable pull-up \n\t" + " cbi %[SDAOUT],%[SDAPIN] ;disable pull-up \n\t" #endif - " sbi %[SDADDR],%[SDAPIN] ;force SDA low \n\t" + " sbi %[SDADDR],%[SDAPIN] ;force SDA low \n\t" #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;wait T/2 \n\t" - " call ass_i2c_write ;now write address \n\t" + " call ass_i2c_delay_half ;wait T/2 \n\t" + " call ass_i2c_write ;now write address \n\t" #else - " rcall ass_i2c_delay_half ;wait T/2 \n\t" - " rcall ass_i2c_write ;now write address \n\t" + " rcall ass_i2c_delay_half ;wait T/2 \n\t" + " rcall ass_i2c_write ;now write address \n\t" #endif - " ret" + " ret" : : [SDADDR] "I" (SDA_DDR), [SDAPIN] "I" (SDA_PIN), [SDAOUT] "I" (SDA_OUT), [SCLOUT] "I" (SCL_OUT), [SCLIN] "I" (SCL_IN),[SCLPIN] "I" (SCL_PIN)); @@ -505,53 +507,53 @@ bool i2c_rep_start(uint8_t addr) ( #if I2C_NOINTERRUPT - " cli \n\t" + " cli \n\t" #endif #if I2C_PULLUP - " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" + " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" #endif - " sbi %[SCLDDR],%[SCLPIN] ;force SCL low \n\t" + " sbi %[SCLDDR],%[SCLPIN] ;force SCL low \n\t" #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;delay T/2 \n\t" + " call ass_i2c_delay_half ;delay T/2 \n\t" #else - " rcall ass_i2c_delay_half ;delay T/2 \n\t" + " rcall ass_i2c_delay_half ;delay T/2 \n\t" #endif - " cbi %[SDADDR],%[SDAPIN] ;release SDA \n\t" + " cbi %[SDADDR],%[SDAPIN] ;release SDA \n\t" #if I2C_PULLUP - " sbi %[SDAOUT],%[SDAPIN] ;enable SDA pull-up \n\t" + " sbi %[SDAOUT],%[SDAPIN] ;enable SDA pull-up \n\t" #endif #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;delay T/2 \n\t" + " call ass_i2c_delay_half ;delay T/2 \n\t" #else - " rcall ass_i2c_delay_half ;delay T/2 \n\t" + " rcall ass_i2c_delay_half ;delay T/2 \n\t" #endif - " cbi %[SCLDDR],%[SCLPIN] ;release SCL \n\t" + " cbi %[SCLDDR],%[SCLPIN] ;release SCL \n\t" #if I2C_PULLUP - " sbi %[SCLOUT],%[SCLPIN] ;enable SCL pull-up \n\t" + " sbi %[SCLOUT],%[SCLPIN] ;enable SCL pull-up \n\t" #endif #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;delay T/2 \n\t" + " call ass_i2c_delay_half ;delay T/2 \n\t" #else - " rcall ass_i2c_delay_half ;delay T/2 \n\t" + " rcall ass_i2c_delay_half ;delay T/2 \n\t" #endif - " sbis %[SCLIN],%[SCLPIN] ;check for clock stretching slave\n\t" + " sbis %[SCLIN],%[SCLPIN] ;check for clock stretching slave\n\t" #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_wait_scl_high ;wait until SCL=H\n\t" + " call ass_i2c_wait_scl_high ;wait until SCL=H\n\t" #else - " rcall ass_i2c_wait_scl_high ;wait until SCL=H\n\t" + " rcall ass_i2c_wait_scl_high ;wait until SCL=H\n\t" #endif #if I2C_PULLUP - " cbi %[SDAOUT],%[SDAPIN] ;disable SDA pull-up\n\t" + " cbi %[SDAOUT],%[SDAPIN] ;disable SDA pull-up\n\t" #endif - " sbi %[SDADDR],%[SDAPIN] ;force SDA low \n\t" + " sbi %[SDADDR],%[SDAPIN] ;force SDA low \n\t" #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;delay T/2 \n\t" - " call ass_i2c_write \n\t" + " call ass_i2c_delay_half ;delay T/2 \n\t" + " call ass_i2c_write \n\t" #else - " rcall ass_i2c_delay_half ;delay T/2 \n\t" - " rcall ass_i2c_write \n\t" + " rcall ass_i2c_delay_half ;delay T/2 \n\t" + " rcall ass_i2c_write \n\t" #endif - " ret" + " ret" : : [SCLDDR] "I" (SCL_DDR), [SCLPIN] "I" (SCL_PIN), [SCLIN] "I" (SCL_IN), [SCLOUT] "I" (SCL_OUT), [SDAOUT] "I" (SDA_OUT), [SDADDR] "I" (SDA_DDR), [SDAPIN] "I" (SDA_PIN)); @@ -620,54 +622,54 @@ bool i2c_start_wait(uint8_t addr) { __asm__ __volatile__ ( - " push r24 ;save original parameter \n\t" + " push r24 ;save original parameter \n\t" #if I2C_MAXWAIT - " ldi r31, %[HIMAXWAIT] ;load max wait counter \n\t" - " ldi r30, %[LOMAXWAIT] ;load low byte \n\t" + " ldi r31, %[HIMAXWAIT] ;load max wait counter \n\t" + " ldi r30, %[LOMAXWAIT] ;load low byte \n\t" #endif - "_Li2c_start_wait1: \n\t" - " pop r24 ;restore original parameter\n\t" - " push r24 ;and save again \n\t" + "_Li2c_start_wait1: \n\t" + " pop r24 ;restore original parameter\n\t" + " push r24 ;and save again \n\t" #if I2C_NOINTERRUPT - " cli ;disable interrupts \n\t" + " cli ;disable interrupts \n\t" #endif - " sbis %[SCLIN],%[SCLPIN] ;check for clock stretching slave\n\t" + " sbis %[SCLIN],%[SCLPIN] ;check for clock stretching slave\n\t" #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_wait_scl_high ;wait until SCL=H\n\t" + " call ass_i2c_wait_scl_high ;wait until SCL=H\n\t" #else - " rcall ass_i2c_wait_scl_high ;wait until SCL=H\n\t" + " rcall ass_i2c_wait_scl_high ;wait until SCL=H\n\t" #endif #if I2C_PULLUP - " cbi %[SDAOUT],%[SDAPIN] ;disable pull-up \n\t" + " cbi %[SDAOUT],%[SDAPIN] ;disable pull-up \n\t" #endif - " sbi %[SDADDR],%[SDAPIN] ;force SDA low \n\t" + " sbi %[SDADDR],%[SDAPIN] ;force SDA low \n\t" #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;delay T/2 \n\t" - " call ass_i2c_write ;write address \n\t" + " call ass_i2c_delay_half ;delay T/2 \n\t" + " call ass_i2c_write ;write address \n\t" #else - " rcall ass_i2c_delay_half ;delay T/2 \n\t" - " rcall ass_i2c_write ;write address \n\t" + " rcall ass_i2c_delay_half ;delay T/2 \n\t" + " rcall ass_i2c_write ;write address \n\t" #endif - " tst r24 ;if device not busy -> done \n\t" - " brne _Li2c_start_wait_done \n\t" + " tst r24 ;if device not busy -> done \n\t" + " brne _Li2c_start_wait_done \n\t" #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_stop ;terminate write & enable IRQ \n\t" + " call ass_i2c_stop ;terminate write & enable IRQ \n\t" #else - " rcall ass_i2c_stop ;terminate write & enable IRQ \n\t" + " rcall ass_i2c_stop ;terminate write & enable IRQ \n\t" #endif #if I2C_MAXWAIT - " sbiw r30,1 ;decrement max wait counter\n\t" - " breq _Li2c_start_wait_done ;if zero reached, exit with false -> r24 already zero!\n\t" + " sbiw r30,1 ;decrement max wait counter\n\t" + " breq _Li2c_start_wait_done ;if zero reached, exit with false -> r24 already zero!\n\t" #endif #if __AVR_HAVE_JMP_CALL__ - " jmp _Li2c_start_wait1 ;device busy, poll ack again \n\t" + " jmp _Li2c_start_wait1 ;device busy, poll ack again \n\t" #else - " rjmp _Li2c_start_wait1 ;device busy, poll ack again \n\t" + " rjmp _Li2c_start_wait1 ;device busy, poll ack again \n\t" #endif - "_Li2c_start_wait_done: \n\t" - " clr r25 ;clear high byte of return value\n\t" - " pop __tmp_reg__ ;pop off orig argument \n\t" - " ret " + "_Li2c_start_wait_done: \n\t" + " clr r25 ;clear high byte of return value\n\t" + " pop __tmp_reg__ ;pop off orig argument \n\t" + " ret " : : [SDADDR] "I" (SDA_DDR), [SDAPIN] "I" (SDA_PIN), [SDAOUT] "I" (SDA_OUT), [SCLIN] "I" (SCL_IN), [SCLPIN] "I" (SCL_PIN), [HIMAXWAIT] "M" (I2C_MAXWAIT>>8), @@ -698,44 +700,44 @@ void i2c_stop(void) __asm__ __volatile__ ( #if I2C_PULLUP - " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" + " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" #endif - " sbi %[SCLDDR],%[SCLPIN] ;force SCL low \n\t" + " sbi %[SCLDDR],%[SCLPIN] ;force SCL low \n\t" #if I2C_PULLUP - " cbi %[SDAOUT],%[SDAPIN] ;disable pull-up \n\t" + " cbi %[SDAOUT],%[SDAPIN] ;disable pull-up \n\t" #endif - " sbi %[SDADDR],%[SDAPIN] ;force SDA low \n\t" + " sbi %[SDADDR],%[SDAPIN] ;force SDA low \n\t" #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;T/2 delay \n\t" + " call ass_i2c_delay_half ;T/2 delay \n\t" #else - " rcall ass_i2c_delay_half ;T/2 delay \n\t" + " rcall ass_i2c_delay_half ;T/2 delay \n\t" #endif - " cbi %[SCLDDR],%[SCLPIN] ;release SCL \n\t" + " cbi %[SCLDDR],%[SCLPIN] ;release SCL \n\t" #if I2C_PULLUP - " sbi %[SCLOUT],%[SCLPIN] ;enable SCL pull-up \n\t" + " sbi %[SCLOUT],%[SCLPIN] ;enable SCL pull-up \n\t" #endif #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;T/2 delay \n\t" + " call ass_i2c_delay_half ;T/2 delay \n\t" #else - " rcall ass_i2c_delay_half ;T/2 delay \n\t" + " rcall ass_i2c_delay_half ;T/2 delay \n\t" #endif - " sbis %[SCLIN],%[SCLPIN] ;check for clock stretching slave\n\t" + " sbis %[SCLIN],%[SCLPIN] ;check for clock stretching slave\n\t" #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_wait_scl_high ;wait until SCL=H\n\t" + " call ass_i2c_wait_scl_high ;wait until SCL=H\n\t" #else - " rcall ass_i2c_wait_scl_high ;wait until SCL=H\n\t" + " rcall ass_i2c_wait_scl_high ;wait until SCL=H\n\t" #endif - " cbi %[SDADDR],%[SDAPIN] ;release SDA \n\t" + " cbi %[SDADDR],%[SDAPIN] ;release SDA \n\t" #if I2C_PULLUP - " sbi %[SDAOUT],%[SDAPIN] ;enable SDA pull-up \n\t" + " sbi %[SDAOUT],%[SDAPIN] ;enable SDA pull-up \n\t" #endif #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half \n\t" + " call ass_i2c_delay_half \n\t" #else - " rcall ass_i2c_delay_half \n\t" + " rcall ass_i2c_delay_half \n\t" #endif #if I2C_NOINTERRUPT - " sei ;enable interrupts again!\n\t" + " sei ;enable interrupts again!\n\t" #endif : : [SCLDDR] "I" (SCL_DDR), [SCLPIN] "I" (SCL_PIN), [SCLIN] "I" (SCL_IN), [SDAOUT] "I" (SDA_OUT), [SCLOUT] "I" (SCL_OUT), @@ -771,141 +773,141 @@ bool i2c_write(uint8_t value) { __asm__ __volatile__ ( - " sec ;set carry flag \n\t" - " rol r24 ;shift in carry and shift out MSB \n\t" + " sec ;set carry flag \n\t" + " rol r24 ;shift in carry and shift out MSB \n\t" #if __AVR_HAVE_JMP_CALL__ - " jmp _Li2c_write_first \n\t" + " jmp _Li2c_write_first \n\t" #else - " rjmp _Li2c_write_first \n\t" + " rjmp _Li2c_write_first \n\t" #endif - "_Li2c_write_bit:\n\t" - " lsl r24 ;left shift into carry ;; 1C\n\t" - "_Li2c_write_first:\n\t" - " breq _Li2c_get_ack ;jump if TXreg is empty;; +1 = 2C \n\t" + "_Li2c_write_bit:\n\t" + " lsl r24 ;left shift into carry ;; 1C\n\t" + "_Li2c_write_first:\n\t" + " breq _Li2c_get_ack ;jump if TXreg is empty;; +1 = 2C \n\t" #if I2C_PULLUP - " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" -#endif - " sbi %[SCLDDR],%[SCLPIN] ;force SCL low ;; +2 = 4C \n\t" - " nop \n\t" - " nop \n\t" - " nop \n\t" - " brcc _Li2c_write_low ;;+1/+2=5/6C\n\t" - " nop ;; +1 = 7C \n\t" - " cbi %[SDADDR],%[SDAPIN] ;release SDA ;; +2 = 9C \n\t" + " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" +#endif + " sbi %[SCLDDR],%[SCLPIN] ;force SCL low ;; +2 = 4C \n\t" + " nop \n\t" + " nop \n\t" + " nop \n\t" + " brcc _Li2c_write_low ;;+1/+2=5/6C\n\t" + " nop ;; +1 = 7C \n\t" + " cbi %[SDADDR],%[SDAPIN] ;release SDA ;; +2 = 9C \n\t" #if I2C_PULLUP - " sbi %[SDAOUT],%[SDAPIN] ;enable SDA pull-up \n\t" + " sbi %[SDAOUT],%[SDAPIN] ;enable SDA pull-up \n\t" #endif #if __AVR_HAVE_JMP_CALL__ - " jmp _Li2c_write_high ;; +2 = 11C \n\t" + " jmp _Li2c_write_high ;; +2 = 11C \n\t" #else - " rjmp _Li2c_write_high ;; +2 = 11C \n\t" + " rjmp _Li2c_write_high ;; +2 = 11C \n\t" #endif - "_Li2c_write_low: \n\t" + "_Li2c_write_low: \n\t" #if I2C_PULLUP - " cbi %[SDAOUT],%[SDAPIN] ;disable pull-up \n\t" + " cbi %[SDAOUT],%[SDAPIN] ;disable pull-up \n\t" #endif - " sbi %[SDADDR],%[SDAPIN] ;force SDA low ;; +2 = 9C \n\t" + " sbi %[SDADDR],%[SDAPIN] ;force SDA low ;; +2 = 9C \n\t" #if __AVR_HAVE_JMP_CALL__ - " jmp _Li2c_write_high ;;+2 = 11C \n\t" + " jmp _Li2c_write_high ;;+2 = 11C \n\t" #else - " rjmp _Li2c_write_high ;;+2 = 11C \n\t" + " rjmp _Li2c_write_high ;;+2 = 11C \n\t" #endif - "_Li2c_write_high: \n\t" + "_Li2c_write_high: \n\t" #if I2C_DELAY_COUNTER >= 1 # if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;delay T/2 ;;+X = 11C+X\n\t" + " call ass_i2c_delay_half ;delay T/2 ;;+X = 11C+X\n\t" # else - " rcall ass_i2c_delay_half ;delay T/2 ;;+X = 11C+X\n\t" + " rcall ass_i2c_delay_half ;delay T/2 ;;+X = 11C+X\n\t" # endif #endif - " cbi %[SCLDDR],%[SCLPIN] ;release SCL ;;+2 = 13C+X\n\t" + " cbi %[SCLDDR],%[SCLPIN] ;release SCL ;;+2 = 13C+X\n\t" #if I2C_PULLUP - " sbi %[SCLOUT],%[SCLPIN] ;enable SCL pull-up \n\t" + " sbi %[SCLOUT],%[SCLPIN] ;enable SCL pull-up \n\t" #endif - " cln ;clear N-bit ;;+1 = 14C+X\n\t" - " nop \n\t" - " nop \n\t" - " nop \n\t" - " sbis %[SCLIN],%[SCLPIN] ;check for SCL high ;;+2 = 16C+X\n\t" + " cln ;clear N-bit ;;+1 = 14C+X\n\t" + " nop \n\t" + " nop \n\t" + " nop \n\t" + " sbis %[SCLIN],%[SCLPIN] ;check for SCL high ;;+2 = 16C+X\n\t" #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_wait_scl_high \n\t" + " call ass_i2c_wait_scl_high \n\t" #else - " rcall ass_i2c_wait_scl_high \n\t" + " rcall ass_i2c_wait_scl_high \n\t" #endif - " brpl _Ldelay_scl_high ;;+2 = 18C+X\n\t" - "_Li2c_write_return_false: \n\t" - " clr r24 ; return false because of timeout \n\t" + " brpl _Ldelay_scl_high ;;+2 = 18C+X\n\t" + "_Li2c_write_return_false: \n\t" + " clr r24 ; return false because of timeout \n\t" #if __AVR_HAVE_JMP_CALL__ - " jmp _Li2c_write_return \n\t" + " jmp _Li2c_write_return \n\t" #else - " rjmp _Li2c_write_return \n\t" + " rjmp _Li2c_write_return \n\t" #endif - "_Ldelay_scl_high: \n\t" + "_Ldelay_scl_high: \n\t" #if I2C_DELAY_COUNTER >= 1 # if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;delay T/2 ;;+X= 18C+2X\n\t" + " call ass_i2c_delay_half ;delay T/2 ;;+X= 18C+2X\n\t" # else - " rcall ass_i2c_delay_half ;delay T/2 ;;+X= 18C+2X\n\t" + " rcall ass_i2c_delay_half ;delay T/2 ;;+X= 18C+2X\n\t" # endif #endif #if __AVR_HAVE_JMP_CALL__ - " jmp _Li2c_write_bit \n\t" + " jmp _Li2c_write_bit \n\t" #else - " rjmp _Li2c_write_bit \n\t" + " rjmp _Li2c_write_bit \n\t" #endif - " ;; +2 = 20C +2X for one bit-loop \n\t" - "_Li2c_get_ack: \n\t" + " ;; +2 = 20C +2X for one bit-loop \n\t" + "_Li2c_get_ack: \n\t" #if I2C_PULLUP - " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" + " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" #endif - " sbi %[SCLDDR],%[SCLPIN] ;force SCL low ;; +2 = 5C \n\t" - " nop \n\t" - " nop \n\t" - " cbi %[SDADDR],%[SDAPIN] ;release SDA ;;+2 = 7C \n\t" + " sbi %[SCLDDR],%[SCLPIN] ;force SCL low ;; +2 = 5C \n\t" + " nop \n\t" + " nop \n\t" + " cbi %[SDADDR],%[SDAPIN] ;release SDA ;;+2 = 7C \n\t" #if I2C_PULLUP - " sbi %[SDAOUT],%[SDAPIN] ;enable SDA pull-up \n\t" + " sbi %[SDAOUT],%[SDAPIN] ;enable SDA pull-up \n\t" #endif #if I2C_DELAY_COUNTER >= 1 # if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;delay T/2 ;; +X = 7C+X \n\t" + " call ass_i2c_delay_half ;delay T/2 ;; +X = 7C+X \n\t" # else - " rcall ass_i2c_delay_half ;delay T/2 ;; +X = 7C+X \n\t" + " rcall ass_i2c_delay_half ;delay T/2 ;; +X = 7C+X \n\t" # endif #endif - " clr r25 ;; 17C+2X \n\t" - " clr r24 ;return 0 ;; 14C + X \n\t" - " cbi %[SCLDDR],%[SCLPIN] ;release SCL ;; +2 = 9C+X\n\t" + " clr r25 ;; 17C+2X \n\t" + " clr r24 ;return 0 ;; 14C + X \n\t" + " cbi %[SCLDDR],%[SCLPIN] ;release SCL ;; +2 = 9C+X\n\t" #if I2C_PULLUP - " sbi %[SCLOUT],%[SCLPIN] ;enable SCL pull-up \n\t" + " sbi %[SCLOUT],%[SCLPIN] ;enable SCL pull-up \n\t" #endif - "_Li2c_ack_wait: \n\t" - " cln ; clear N-bit ;; 10C + X\n\t" - " nop \n\t" - " sbis %[SCLIN],%[SCLPIN] ;wait SCL high ;; 12C + X \n\t" + "_Li2c_ack_wait: \n\t" + " cln ; clear N-bit ;; 10C + X\n\t" + " nop \n\t" + " sbis %[SCLIN],%[SCLPIN] ;wait SCL high ;; 12C + X \n\t" #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_wait_scl_high \n\t" + " call ass_i2c_wait_scl_high \n\t" #else - " rcall ass_i2c_wait_scl_high \n\t" + " rcall ass_i2c_wait_scl_high \n\t" #endif - " brmi _Li2c_write_return_false ;; 13C + X \n\t " - " sbis %[SDAIN],%[SDAPIN] ;if SDA hi -> return 0 ;; 15C + X \n\t" - " ldi r24,1 ;return true ;; 16C + X \n\t" + " brmi _Li2c_write_return_false ;; 13C + X \n\t " + " sbis %[SDAIN],%[SDAPIN] ;if SDA hi -> return 0 ;; 15C + X \n\t" + " ldi r24,1 ;return true ;; 16C + X \n\t" #if I2C_DELAY_COUNTER >= 1 # if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;delay T/2 ;; 16C + 2X \n\t" + " call ass_i2c_delay_half ;delay T/2 ;; 16C + 2X \n\t" # else - " rcall ass_i2c_delay_half ;delay T/2 ;; 16C + 2X \n\t" + " rcall ass_i2c_delay_half ;delay T/2 ;; 16C + 2X \n\t" # endif #endif - "_Li2c_write_return: \n\t" - " nop \n\t " - " nop \n\t " + "_Li2c_write_return: \n\t" + " nop \n\t " + " nop \n\t " #if I2C_PULLUP - " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" + " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" #endif - " sbi %[SCLDDR],%[SCLPIN] ;force SCL low so SCL=H is short\n\t" - " ret \n\t" - " ;; + 4 = 17C + 2X for acknowldge bit" + " sbi %[SCLDDR],%[SCLPIN] ;force SCL low so SCL=H is short\n\t" + " ret \n\t" + " ;; + 4 = 17C + 2X for acknowldge bit" :: [SCLDDR] "I" (SCL_DDR), [SCLPIN] "I" (SCL_PIN), [SCLIN] "I" (SCL_IN), [SDAOUT] "I" (SDA_OUT), [SCLOUT] "I" (SCL_OUT), @@ -933,117 +935,117 @@ uint8_t i2c_read(bool last) { __asm__ __volatile__ ( - " ldi r23,0x01 \n\t" - "_Li2c_read_bit: \n\t" + " ldi r23,0x01 \n\t" + "_Li2c_read_bit: \n\t" #if I2C_PULLUP - " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" + " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" #endif - " sbi %[SCLDDR],%[SCLPIN] ;force SCL low ;; 2C \n\t" - " cbi %[SDADDR],%[SDAPIN] ;release SDA(prev. ACK);; 4C \n\t" + " sbi %[SCLDDR],%[SCLPIN] ;force SCL low ;; 2C \n\t" + " cbi %[SDADDR],%[SDAPIN] ;release SDA(prev. ACK);; 4C \n\t" #if I2C_PULLUP - " sbi %[SDAOUT],%[SDAPIN] ;enable SDA pull-up \n\t" + " sbi %[SDAOUT],%[SDAPIN] ;enable SDA pull-up \n\t" #endif - " nop \n\t" - " nop \n\t" - " nop \n\t" + " nop \n\t" + " nop \n\t" + " nop \n\t" #if I2C_DELAY_COUNTER >= 1 # if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;delay T/2 ;; 4C+X \n\t" + " call ass_i2c_delay_half ;delay T/2 ;; 4C+X \n\t" # else - " rcall ass_i2c_delay_half ;delay T/2 ;; 4C+X \n\t" + " rcall ass_i2c_delay_half ;delay T/2 ;; 4C+X \n\t" # endif #endif - " cbi %[SCLDDR],%[SCLPIN] ;release SCL ;; 6C + X \n\t" + " cbi %[SCLDDR],%[SCLPIN] ;release SCL ;; 6C + X \n\t" #if I2C_PULLUP - " sbi %[SCLOUT],%[SCLPIN] ;enable SCL pull-up \n\t" + " sbi %[SCLOUT],%[SCLPIN] ;enable SCL pull-up \n\t" #endif #if I2C_DELAY_COUNTER >= 1 # if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;delay T/2 ;; 6C + 2X \n\t" + " call ass_i2c_delay_half ;delay T/2 ;; 6C + 2X \n\t" # else - " rcall ass_i2c_delay_half ;delay T/2 ;; 6C + 2X \n\t" + " rcall ass_i2c_delay_half ;delay T/2 ;; 6C + 2X \n\t" # endif #endif - " cln ; clear N-bit ;; 7C + 2X \n\t" - " nop \n\t " - " nop \n\t " - " nop \n\t " - " sbis %[SCLIN], %[SCLPIN] ;check for SCL high ;; 9C +2X \n\t" + " cln ; clear N-bit ;; 7C + 2X \n\t" + " nop \n\t " + " nop \n\t " + " nop \n\t " + " sbis %[SCLIN], %[SCLPIN] ;check for SCL high ;; 9C +2X \n\t" #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_wait_scl_high \n\t" + " call ass_i2c_wait_scl_high \n\t" #else - " rcall ass_i2c_wait_scl_high \n\t" + " rcall ass_i2c_wait_scl_high \n\t" #endif - " brmi _Li2c_read_return ;return if timeout ;; 10C + 2X\n\t" - " clc ;clear carry flag ;; 11C + 2X\n\t" - " sbic %[SDAIN],%[SDAPIN] ;if SDA is high ;; 11C + 2X\n\t" - " sec ;set carry flag ;; 12C + 2X\n\t" - " rol r23 ;store bit ;; 13C + 2X\n\t" - " brcc _Li2c_read_bit ;while receiv reg not full \n\t" - " ;; 15C + 2X for one bit loop \n\t" + " brmi _Li2c_read_return ;return if timeout ;; 10C + 2X\n\t" + " clc ;clear carry flag ;; 11C + 2X\n\t" + " sbic %[SDAIN],%[SDAPIN] ;if SDA is high ;; 11C + 2X\n\t" + " sec ;set carry flag ;; 12C + 2X\n\t" + " rol r23 ;store bit ;; 13C + 2X\n\t" + " brcc _Li2c_read_bit ;while receiv reg not full \n\t" + " ;; 15C + 2X for one bit loop \n\t" - "_Li2c_put_ack: \n\t" + "_Li2c_put_ack: \n\t" #if I2C_PULLUP - " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" + " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" #endif - " sbi %[SCLDDR],%[SCLPIN] ;force SCL low ;; 2C \n\t" - " cpi r24,0 ;; 3C \n\t" - " breq _Li2c_put_ack_low ;if (ack=0) ;; 5C \n\t" - " cbi %[SDADDR],%[SDAPIN] ;release SDA \n\t" + " sbi %[SCLDDR],%[SCLPIN] ;force SCL low ;; 2C \n\t" + " cpi r24,0 ;; 3C \n\t" + " breq _Li2c_put_ack_low ;if (ack=0) ;; 5C \n\t" + " cbi %[SDADDR],%[SDAPIN] ;release SDA \n\t" #if I2C_PULLUP - " sbi %[SDAOUT],%[SDAPIN] ;enable SDA pull-up \n\t" + " sbi %[SDAOUT],%[SDAPIN] ;enable SDA pull-up \n\t" #endif #if __AVR_HAVE_JMP_CALL__ - " jmp _Li2c_put_ack_high \n\t" + " jmp _Li2c_put_ack_high \n\t" #else - " rjmp _Li2c_put_ack_high \n\t" + " rjmp _Li2c_put_ack_high \n\t" #endif - "_Li2c_put_ack_low: ;else \n\t" + "_Li2c_put_ack_low: ;else \n\t" #if I2C_PULLUP - " cbi %[SDAOUT],%[SDAPIN] ;disable pull-up \n\t" + " cbi %[SDAOUT],%[SDAPIN] ;disable pull-up \n\t" #endif - " sbi %[SDADDR],%[SDAPIN] ;force SDA low ;; 7C \n\t" - "_Li2c_put_ack_high: \n\t" - " nop \n\t " - " nop \n\t " - " nop \n\t " + " sbi %[SDADDR],%[SDAPIN] ;force SDA low ;; 7C \n\t" + "_Li2c_put_ack_high: \n\t" + " nop \n\t " + " nop \n\t " + " nop \n\t " #if I2C_DELAY_COUNTER >= 1 # if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;delay T/2 ;; 7C + X \n\t" + " call ass_i2c_delay_half ;delay T/2 ;; 7C + X \n\t" # else - " rcall ass_i2c_delay_half ;delay T/2 ;; 7C + X \n\t" + " rcall ass_i2c_delay_half ;delay T/2 ;; 7C + X \n\t" # endif #endif - " cbi %[SCLDDR],%[SCLPIN] ;release SCL ;; 9C +X \n\t" + " cbi %[SCLDDR],%[SCLPIN] ;release SCL ;; 9C +X \n\t" #if I2C_PULLUP - " sbi %[SCLOUT],%[SCLPIN] ;enable SCL pull-up \n\t" + " sbi %[SCLOUT],%[SCLPIN] ;enable SCL pull-up \n\t" #endif - " cln ;clear N ;; +1 = 10C\n\t" - " nop \n\t " - " nop \n\t " - " sbis %[SCLIN],%[SCLPIN] ;wait SCL high ;; 12C + X\n\t" + " cln ;clear N ;; +1 = 10C\n\t" + " nop \n\t " + " nop \n\t " + " sbis %[SCLIN],%[SCLPIN] ;wait SCL high ;; 12C + X\n\t" #if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_wait_scl_high \n\t" + " call ass_i2c_wait_scl_high \n\t" #else - " rcall ass_i2c_wait_scl_high \n\t" + " rcall ass_i2c_wait_scl_high \n\t" #endif #if I2C_DELAY_COUNTER >= 1 # if __AVR_HAVE_JMP_CALL__ - " call ass_i2c_delay_half ;delay T/2 ;; 11C + 2X\n\t" + " call ass_i2c_delay_half ;delay T/2 ;; 11C + 2X\n\t" # else - " rcall ass_i2c_delay_half ;delay T/2 ;; 11C + 2X\n\t" + " rcall ass_i2c_delay_half ;delay T/2 ;; 11C + 2X\n\t" #endif #endif - "_Li2c_read_return: \n\t" - " nop \n\t " - " nop \n\t " + "_Li2c_read_return: \n\t" + " nop \n\t " + " nop \n\t " #if I2C_PULLUP - " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" + " cbi %[SCLOUT],%[SCLPIN] ;disable SCL pull-up \n\t" #endif - "sbi %[SCLDDR],%[SCLPIN] ;force SCL low so SCL=H is short\n\t" - " mov r24,r23 ;; 12C + 2X \n\t" - " clr r25 ;; 13 C + 2X\n\t" - " ret ;; 17C + X" + "sbi %[SCLDDR],%[SCLPIN] ;force SCL low so SCL=H is short\n\t" + " mov r24,r23 ;; 12C + 2X \n\t" + " clr r25 ;; 13 C + 2X\n\t" + " ret ;; 17C + X" :: [SCLDDR] "I" (SCL_DDR), [SCLPIN] "I" (SCL_PIN), [SCLIN] "I" (SCL_IN), [SDAOUT] "I" (SDA_OUT), [SCLOUT] "I" (SCL_OUT), @@ -1084,8 +1086,8 @@ void i2c_write_byte(uint8_t addr, uint8_t byte) { i2c_stop(); } -void i2c_read_buffer_from_register(uint8_t addr, uint8_t register_number, uint8_t * byte_buffer, uint8_t number_of_bytes_to_read){ - i2c_start (addr); +void i2c_read_buffer_from_register(uint8_t addr, uint8_t register_number, uint8_t *byte_buffer, uint8_t number_of_bytes_to_read) { + i2c_start(addr); i2c_write(register_number); i2c_rep_start(addr | I2C_READ); // restart for reading int8_t i = 0; @@ -1095,8 +1097,9 @@ void i2c_read_buffer_from_register(uint8_t addr, uint8_t register_number, uint8_ byte_buffer[i] = i2c_read(true); } -void i2c_read_buffer_from_16bit_register(uint8_t addr, uint16_t register_number, uint8_t * byte_buffer, uint8_t number_of_bytes_to_read){ - i2c_start (addr); +void i2c_read_buffer_from_16bit_register(uint8_t addr, uint16_t register_number, uint8_t *byte_buffer, + uint8_t number_of_bytes_to_read) { + i2c_start(addr); i2c_write(register_number >> 8); i2c_write(register_number & 0xFF); i2c_rep_start(addr | I2C_READ); // restart for reading @@ -1107,21 +1110,22 @@ void i2c_read_buffer_from_16bit_register(uint8_t addr, uint16_t register_number, byte_buffer[i] = i2c_read(true); } -void i2c_write_buffer_to_16bit_register(uint8_t addr, uint16_t register_number, uint8_t * byte_buffer, uint8_t number_of_bytes_to_write) { - i2c_start (addr); +void i2c_write_buffer_to_16bit_register(uint8_t addr, uint16_t register_number, uint8_t *byte_buffer, + uint8_t number_of_bytes_to_write) { + i2c_start(addr); i2c_write(register_number >> 8); i2c_write(register_number & 0xFF); for (uint8_t i = 0; i < number_of_bytes_to_write; i++) { - i2c_write (byte_buffer[i]); + i2c_write(byte_buffer[i]); } i2c_stop(); } -void i2c_write_buffer_to_register(uint8_t addr, uint8_t register_number, uint8_t * byte_buffer, uint8_t number_of_bytes_to_write) { - i2c_start (addr); +void i2c_write_buffer_to_register(uint8_t addr, uint8_t register_number, uint8_t *byte_buffer, uint8_t number_of_bytes_to_write) { + i2c_start(addr); i2c_write(register_number); for (uint8_t i = 0; i < number_of_bytes_to_write; i++) { - i2c_write (byte_buffer[i]); + i2c_write(byte_buffer[i]); } i2c_stop(); } diff --git a/JK-BMSToPylontechCAN/SoftwareSerialTX.cpp b/JK-BMSToPylontechCAN/SoftwareSerialTX.cpp index 3e9b7fc..fefd921 100644 --- a/JK-BMSToPylontechCAN/SoftwareSerialTX.cpp +++ b/JK-BMSToPylontechCAN/SoftwareSerialTX.cpp @@ -1,5 +1,5 @@ /* -SoftwareSerialTX.h (from SoftSerial.h) - +SoftwareSerialTX.h (from SoftSerial.h) - Multi-instance software serial library for Arduino/Wiring -- Transmit-only imoplementation -- reduce footprint in code memory and RAM compared to SoftwareSerial @@ -13,8 +13,8 @@ version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software @@ -26,9 +26,9 @@ The latest version of this library can always be found at */ #if defined(__AVR_ATmega168__) ||defined(__AVR_ATmega168P__) ||defined(__AVR_ATmega328P__) -// +// // Includes -// +// #include #include #include "SoftwareSerialTX.h" @@ -36,7 +36,7 @@ The latest version of this library can always be found at // // Constructor // -SoftwareSerialTX::SoftwareSerialTX(uint8_t transmitPin) +SoftwareSerialTX::SoftwareSerialTX(uint8_t transmitPin) { setTX(transmitPin); } @@ -77,7 +77,7 @@ size_t SoftwareSerialTX::write(uint8_t b) SREG = oldSREG; // turn interrupts back on _delay_loop_2(delay); - + return 1; } @@ -123,4 +123,4 @@ size_t SoftwareSerialTX::write(const uint8_t *buffer, size_t size) } #else #error unsupported platform -#endif \ No newline at end of file +#endif diff --git a/JK-BMSToPylontechCAN/SoftwareSerialTX.h b/JK-BMSToPylontechCAN/SoftwareSerialTX.h index 826e9fe..4e67e8e 100644 --- a/JK-BMSToPylontechCAN/SoftwareSerialTX.h +++ b/JK-BMSToPylontechCAN/SoftwareSerialTX.h @@ -13,7 +13,7 @@ version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public diff --git a/README.md b/README.md index 7a9bbbb..4302a64 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,8 @@ If CAN communications breaks, the inverter may use different values for controll | ![My installation](https://github.com/ArminJo/JK-BMSToPylontechCAN/blob/main/pictures/CompleteInstallation.jpg) | ![Automatic brightness](https://github.com/ArminJo/JK-BMSToPylontechCAN/blob/main/pictures/AutomaticBrightness.jpg) | | Breadboard detail | | | ![Breadboard detail](https://github.com/ArminJo/JK-BMSToPylontechCAN/blob/main/pictures/BreadboardDetail.jpg) | | +| Breadboard without BMS connected | Standalone test | +| ![Breadboard detail](https://github.com/ArminJo/JK-BMSToPylontechCAN/blob/main/pictures/BreadboardSimple.jpg) | ![Standalone test](https://github.com/ArminJo/JK-BMSToPylontechCAN/blob/main/pictures/StandaloneTest.jpg) | | No-breadboard version overview | No-breadboard version overview | | ![Overview no breadboard](https://github.com/ArminJo/JK-BMSToPylontechCAN/blob/main/pictures/NoBreadboardOverview1.jpg) | ![Overview no breadboard](https://github.com/ArminJo/JK-BMSToPylontechCAN/blob/main/pictures/NoBreadboardOverview2.jpg) | | Nano top view | Nano bottom view | @@ -142,7 +144,7 @@ On the Deye, connect cable before setting `Battery Mode` to `Lithium`, to avoid [EasyEda shematics by Ngoc Dang Dinh](https://easyeda.com/editor#id=0d1a2556b7634c8bbd22e9c0474cd401|8c434b5057fc4d769d664a0dc9c7d66c) -![EasyEda shematics by Ngoc Dang Dinh](https://user-images.githubusercontent.com/8839597/271840357-741d3036-e734-4fbe-8635-64cbb7f3fe25.png) +![EasyEda shematics by Ngoc Dang Dinh](https://github.com/ArminJo/JK-BMSToPylontechCAN/blob/main/pictures/EasyEda_shematics_by_Ngoc_Dang_Dinh.png) ### Board pinout diagrams @@ -235,6 +237,7 @@ This program uses the following libraries, which are already included in this re # Revision History ### Version 2.2 +- Fixed LCD backlight timeout bug introduced in 1.3.0. - Long press of page button instead of debug button. - Do not use sleep any more by default. diff --git a/pictures/BreadboardSimple.jpg b/pictures/BreadboardSimple.jpg new file mode 100644 index 0000000..9363220 Binary files /dev/null and b/pictures/BreadboardSimple.jpg differ diff --git a/pictures/EasyEda_shematics_by_Ngoc_Dang_Dinh.png b/pictures/EasyEda_shematics_by_Ngoc_Dang_Dinh.png new file mode 100644 index 0000000..c6a084c Binary files /dev/null and b/pictures/EasyEda_shematics_by_Ngoc_Dang_Dinh.png differ diff --git a/pictures/StandaloneTest.jpg b/pictures/StandaloneTest.jpg new file mode 100644 index 0000000..95a9c4e Binary files /dev/null and b/pictures/StandaloneTest.jpg differ