From e232b4adbf02b6b64fa7a85e0f1c326448c3c07a Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 20 Oct 2024 23:35:26 +0200 Subject: [PATCH] avr: fixed a few errors in new uart_bitbang module. --- avr/devices/n14/n14_defs.asm | 3 ++- avr/modules/uart_bitbang/bytelevel.asm | 12 +++++++----- avr/modules/uart_bitbang/main.asm | 2 +- avr/modules/uart_bitbang/packetlevel.asm | 4 +--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/avr/devices/n14/n14_defs.asm b/avr/devices/n14/n14_defs.asm index 57e3535..7636a81 100644 --- a/avr/devices/n14/n14_defs.asm +++ b/avr/devices/n14/n14_defs.asm @@ -66,7 +66,8 @@ .equ COM_TXD_PIN = PORTB1 .equ COM_RXD_DDR = DDRB -.equ COM_RXD_DATA = PINB +.equ COM_RXD_INPUT = PINB +.equ COM_RXD_OUTPUT = PORTB .equ COM_RXD_PIN = PORTB1 .equ COM_ATTN_DDR = DDRB diff --git a/avr/modules/uart_bitbang/bytelevel.asm b/avr/modules/uart_bitbang/bytelevel.asm index 6c52da1..344dc37 100644 --- a/avr/modules/uart_bitbang/bytelevel.asm +++ b/avr/modules/uart_bitbang/bytelevel.asm @@ -96,7 +96,7 @@ uartBitbang_SendByte_setHigh: cbi COM_TXD_DDR, COM_TXD_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_RXD_DATA, COM_RXD_PIN ; +1 if no skip, +2 if skipped + sbis COM_RXD_INPUT, COM_RXD_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 uartBitbang_SendByte_loopEnd: @@ -126,6 +126,8 @@ uartBitbang_SendByte_error: ; @clobbers R16, R20, R21, R22 (R17) uartBitbang_ReceiveByte: + cbi COM_RXD_OUTPUT, COM_RXD_PIN ; disable internal pullup for RXD + cbi COM_RXD_DDR, COM_RXD_PIN ; set RXD port as input ldi r21, 8 ; bits left clr r20 ; byte currently receiving ; wait for startbit @@ -135,8 +137,8 @@ uartBitbang_ReceiveByte: uartBitbang_ReceiveByte_loop: Utils_WaitNanoSecs COM_BIT_LENGTH, 8, r22 ; 8 cycles used in the complete loop between waits sec ; +1 - sbic COM_RXD_DATA, COM_RXD_PIN ; LOW: +2, HIGH: +1 - rjmp uartBitbang_ReceiveByte_shiftIn ; HIGH: +2, rjmp, use set CFLAG + sbic COM_RXD_INPUT, COM_RXD_PIN ; LOW: +2, HIGH: +1 + rjmp uartBitbang_ReceiveByte_shiftIn ; HIGH: +2, rjmp, use set CFLAG clc ; LOW: +1 uartBitbang_ReceiveByte_shiftIn: ror r20 ; +1 @@ -162,7 +164,7 @@ uartBitbang_ReceiveByte_error: ; @clobbers R17, R22 uartBitbang_WaitForDataLow: - UART_BB_M_WAIT_FOR_PIN_LOW COM_RXD_DATA, COM_RXD_PIN + UART_BB_M_WAIT_FOR_PIN_LOW COM_RXD_INPUT, COM_RXD_PIN ret ; @end @@ -176,7 +178,7 @@ uartBitbang_WaitForDataLow: ; @clobbers R17, R22 uartBitbang_WaitForDataHigh: - UART_BB_M_WAIT_FOR_PIN_LOW COM_RXD_DATA, COM_RXD_PIN + UART_BB_M_WAIT_FOR_PIN_HIGH COM_RXD_INPUT, COM_RXD_PIN ret ; @end diff --git a/avr/modules/uart_bitbang/main.asm b/avr/modules/uart_bitbang/main.asm index 48b01a3..5f613fd 100644 --- a/avr/modules/uart_bitbang/main.asm +++ b/avr/modules/uart_bitbang/main.asm @@ -62,7 +62,7 @@ UART_BitBang_Init: cbi COM_TXD_DATA, COM_TXD_PIN ; disable internal pullup for TXD cbi COM_TXD_DDR, COM_TXD_PIN ; set TXD port as input - cbi COM_RXD_DATA, COM_RXD_PIN ; disable internal pullup for RXD + cbi COM_RXD_OUTPUT, COM_RXD_PIN ; disable internal pullup for RXD cbi COM_RXD_DDR, COM_RXD_PIN ; set RXD port as input cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable internal pullup for ATTN diff --git a/avr/modules/uart_bitbang/packetlevel.asm b/avr/modules/uart_bitbang/packetlevel.asm index 5c8e4b2..ea6e5ee 100644 --- a/avr/modules/uart_bitbang/packetlevel.asm +++ b/avr/modules/uart_bitbang/packetlevel.asm @@ -29,9 +29,7 @@ uartBitbang_ReceivePacketIntoBuffer: rcall uartBitbang_ReceiveByte ; read byte (R16, R17, R20, R21, R22) pop r17 ; pop from R16 to R17 brcc uartBitbang_ReceivePacketIntoBuffer_ioError -#ifdef COM_ACCEPT_ALL_DEST ; accept every destination address - rjmp uartBitbang_ReceivePacketIntoBuffer_acceptAddr -#else +#ifndef COM_ACCEPT_ALL_DEST ; accept every destination address ; compare destination address (accept "FF" and own address) cp r16, r17 breq uartBitbang_ReceivePacketIntoBuffer_acceptAddr