wait for one bitlength between bytes. disable collision detection.

This commit is contained in:
Martin Preuss
2025-05-29 21:04:30 +02:00
parent fa6acd8e52
commit 36050b14c5

View File

@@ -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