@@ -31,6 +31,15 @@ void pinMode(uint8_t pin, PinMode mode)
3131 uint8_t bit_pos = digitalPinToBitPosition (pin );
3232
3333 if ((bit_pos == NOT_A_PIN )|| (mode > INPUT_PULLUP )) return ;
34+
35+ /* Check if TWI is operating on double bonded pin (Master Enable is high
36+ in both Master and Slave mode for bus error detection, so this can
37+ indicate an active state for Wire) */
38+ if (((pin == PIN_A4 ) || (pin == PIN_A5 )) && (TWI0 .MCTRLA & TWI_ENABLE_bm )) return ;
39+
40+ /* Special check for SPI_SS double bonded pin -- no action if SPI is active
41+ (Using SPI Enable bit as indicator of SPI activity) */
42+ if ((pin == 10 ) && (SPI0 .CTRLA & SPI_ENABLE_bm )) return ;
3443
3544 PORT_t * port = digitalPinToPortStruct (pin );
3645 if (port == NULL ) return ;
@@ -137,6 +146,15 @@ void digitalWrite(uint8_t pin, PinStatus val)
137146 /* Get bit mask for pin */
138147 uint8_t bit_mask = digitalPinToBitMask (pin );
139148 if (bit_mask == NOT_A_PIN ) return ;
149+
150+ /* Check if TWI is operating on double bonded pin (Master Enable is high
151+ in both Master and Slave mode for bus error detection, so this can
152+ indicate an active state for Wire) */
153+ if (((pin == PIN_A4 ) || (pin == PIN_A5 )) && (TWI0 .MCTRLA & TWI_ENABLE_bm )) return ;
154+
155+ /* Special check for SPI_SS double bonded pin -- no action if SPI is active
156+ (Using SPI Enable bit as indicator of SPI activity) */
157+ if ((pin == 10 ) && (SPI0 .CTRLA & SPI_ENABLE_bm )) return ;
140158
141159 /* Turn off PWM if applicable */
142160
@@ -210,6 +228,15 @@ PinStatus digitalRead(uint8_t pin)
210228 /* Get bit mask and check valid pin */
211229 uint8_t bit_mask = digitalPinToBitMask (pin );
212230 if (bit_mask == NOT_A_PIN ) return LOW ;
231+
232+ /* Check if TWI is operating on double bonded pin (Master Enable is high
233+ in both Master and Slave mode for bus error detection, so this can
234+ indicate an active state for Wire) */
235+ if (((pin == PIN_A4 ) || (pin == PIN_A5 )) && (TWI0 .MCTRLA & TWI_ENABLE_bm )) return LOW ;
236+
237+ /* Special check for SPI_SS double bonded pin -- no action if SPI is active
238+ (Using SPI Enable bit as indicator of SPI activity) */
239+ if ((pin == 10 ) && (SPI0 .CTRLA & SPI_ENABLE_bm )) return ;
213240
214241 // If the pin that support PWM output, we need to turn it off
215242 // before getting a digital reading.
0 commit comments