From 36050b14c5517ad5e8f67797bb77852d9a59f3f7 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Thu, 29 May 2025 21:04:30 +0200 Subject: [PATCH] wait for one bitlength between bytes. disable collision detection. --- avr/modules/uart_bitbang2/lowlevel.asm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/avr/modules/uart_bitbang2/lowlevel.asm b/avr/modules/uart_bitbang2/lowlevel.asm index 226c886..bd7f8a5 100644 --- a/avr/modules/uart_bitbang2/lowlevel.asm +++ b/avr/modules/uart_bitbang2/lowlevel.asm @@ -93,7 +93,7 @@ uartBitbang_SendByte: cbi COM_DATA_OUTPUT, COM_DATA_PIN ; +2 set DATA low Utils_WaitNanoSecs COM_BIT_LENGTH, 1, r22 ; wait for one bit duration ; send data bits -uartBitbang_SendByte_loop: ; 9 for low bit +uartBitbang_SendByte_loop: ; 11 for low bit lsr r16 ; 1+ bit to send -> CARRY brcs uartBitbang_SendByte_setHigh ; HI: +2, LO: +1 uartBitbang_SendByte_setLow: @@ -102,15 +102,20 @@ uartBitbang_SendByte_setLow: Utils_WaitNanoSecs COM_BIT_LENGTH, 11, r22 rjmp uartBitbang_SendByte_loopEnd ; +2 uartBitbang_SendByte_setHigh: +#if 0 cbi COM_DATA_DDR, COM_DATA_PIN ; +2 set DATA as input, pullup R makes it ONE nop ; +1 (to make pin change available) Utils_WaitNanoSecs COM_HALFBIT_LENGTH, 0, r22 ; wait for half a bit length for line to safely settle sbis COM_DATA_INPUT, COM_DATA_PIN ; +1 if no skip, +2 if skipped rjmp uartBitbang_SendByte_error ; +2 if error (collision: we wanted line to be high but it is low) Utils_WaitNanoSecs COM_HALFBIT_LENGTH, 11, r22 +#else + cbi COM_DATA_DDR, COM_DATA_PIN ; +2 set DATA as input, pullup R makes it ONE + Utils_WaitNanoSecs COM_BIT_LENGTH, 8, r22 +#endif uartBitbang_SendByte_loopEnd: dec r21 ; +1 - brne uartBitbang_SendByte_loop ; +2, sum per loop: 10 cycles + brne uartBitbang_SendByte_loop ; +2, sum per loop: 11 cycles ; send stopbit cbi COM_DATA_DDR, COM_DATA_PIN ; +2 set DATA as input, pullup R makes it ONE Utils_WaitNanoSecs COM_BIT_LENGTH, 0, r22 ; wait for one bit length @@ -303,6 +308,8 @@ uartBitbang_SendPacket: inc r17 ; account for crc byte uartBitbang_SendPacket_loop: + rcall uartBitbang_WaitForOneBitLength ; wait for one bit duration (R22) + ld r16, X+ rcall uartBitbang_SendByte ; send byte (R16, R21, R22) brcc uartBitbang_SendPacket_releaseBusRet