Skip to content

Commit 1f9ac9e

Browse files
committed
Set TX bit in defined, recessive state (for in case it is wired)
1 parent 9171d97 commit 1f9ac9e

5 files changed

Lines changed: 20 additions & 1 deletion

File tree

examples/LiveWebPage/LiveWebPage.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@
9292
#ifdef ARDUINO_ARCH_ESP32
9393
#ifdef CONFIG_IDF_TARGET_ESP32S2
9494
#define RX_PIN GPIO_NUM_33
95+
#define TX_PIN GPIO_NUM_18
9596
#else
9697
// Note: GPIO_NUM_22 is also LED pin on Lilygo TTGO T7 V1.3 Mini32
9798
#define RX_PIN GPIO_NUM_22
99+
#define TX_PIN GPIO_NUM_21
98100
#endif
99101
#else // ! ARDUINO_ARCH_ESP32
100102
#if defined ARDUINO_ESP8266_GENERIC || defined ARDUINO_ESP8266_ESP01
@@ -106,6 +108,7 @@
106108
//#define RX_PIN D3 // GPIO0 - pulled up - Boot fails
107109
//#define RX_PIN D4 // GPIO2 - pulled up
108110
//#define RX_PIN D8 // GPIO15 - pulled to GND - Boot fails
111+
#define TX_PIN D3
109112
#endif // ARDUINO_ARCH_ESP32
110113

111114
// TODO - reduce size of large JSON packets like the ones containing guidance instruction icons
@@ -1082,6 +1085,7 @@ void setup()
10821085
#define STR(x) #x
10831086
Serial.printf_P(PSTR("Setting up VAN bus receiver on pin %s (GPIO%u)\n"), XSTR(RX_PIN), RX_PIN);
10841087
VanBusRx.Setup(RX_PIN, VAN_PACKET_QUEUE_SIZE);
1088+
VanBusRx.SetTxPinRecessive(TX_PIN);
10851089
Serial.printf_P(PSTR("VanBusRx queue of size %d is set up\n"), VanBusRx.QueueSize());
10861090

10871091
IrSetup();

examples/PacketParser/PacketParser.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@
5959
#ifdef ARDUINO_ARCH_ESP32
6060
#ifdef CONFIG_IDF_TARGET_ESP32S2
6161
#define RX_PIN GPIO_NUM_33
62+
#define TX_PIN GPIO_NUM_18
6263
#else
6364
// Note: GPIO_NUM_22 is also LED pin on Lilygo TTGO T7 V1.3 Mini32
6465
#define RX_PIN GPIO_NUM_22
65-
66+
#define TX_PIN GPIO_NUM_21
6667
#endif
6768
#else // ! ARDUINO_ARCH_ESP32
6869
#if defined ARDUINO_ESP8266_GENERIC || defined ARDUINO_ESP8266_ESP01
@@ -71,6 +72,7 @@
7172
#endif // defined ARDUINO_ESP8266_GENERIC || defined ARDUINO_ESP8266_ESP01
7273
// For WEMOS D1 mini board we use D2 (GPIO 4)
7374
#define RX_PIN D2
75+
#define TX_PIN D3
7476
#endif // ARDUINO_ARCH_ESP32
7577

7678
// Packet parsing
@@ -3994,6 +3996,7 @@ void setup()
39943996
// set up the receive queue a bit larger than the default of 15
39953997
#define VAN_PACKET_QUEUE_SIZE 60
39963998
VanBusRx.Setup(RX_PIN, VAN_PACKET_QUEUE_SIZE);
3999+
VanBusRx.SetTxPinRecessive(TX_PIN);
39974000
Serial.printf_P(PSTR("VanBusRx queue of size %d is set up\n"), VanBusRx.QueueSize());
39984001
} // setup
39994002

examples/VanBusDump/VanBusDump.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@
7474
#ifdef ARDUINO_ARCH_ESP32
7575
#ifdef CONFIG_IDF_TARGET_ESP32S2
7676
#define RX_PIN GPIO_NUM_33
77+
#define TX_PIN GPIO_NUM_18
7778
#else
7879
// Note: GPIO_NUM_22 is also LED pin on Lilygo TTGO T7 V1.3 Mini32
7980
#define RX_PIN GPIO_NUM_22
81+
#define TX_PIN GPIO_NUM_21
8082
#endif
8183
#else // ! ARDUINO_ARCH_ESP32
8284
#if defined ARDUINO_ESP8266_GENERIC || defined ARDUINO_ESP8266_ESP01
@@ -85,6 +87,7 @@
8587
#endif // defined ARDUINO_ESP8266_GENERIC || defined ARDUINO_ESP8266_ESP01
8688
// For WEMOS D1 mini board we use D2 (GPIO 4)
8789
#define RX_PIN D2
90+
#define TX_PIN D3
8891
#endif // ARDUINO_ARCH_ESP32
8992

9093
void setup()
@@ -128,6 +131,7 @@ void setup()
128131
#define STR(x) #x
129132
Serial.printf_P(PSTR("Setting up VAN bus receiver on pin %s (GPIO%u)\n"), XSTR(RX_PIN), RX_PIN);
130133
VanBusRx.Setup(RX_PIN);
134+
VanBusRx.SetTxPinRecessive(TX_PIN);
131135
Serial.printf_P(PSTR("VanBusRx queue of size %d is set up\n"), VanBusRx.QueueSize());
132136
} // setup
133137

src/VanBusRx.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,13 @@ bool TVanPacketRxQueue::Setup(uint8_t rxPin, int queueSize)
13201320
return true;
13211321
} // TVanPacketRxQueue::Setup
13221322

1323+
// If the TX pin is connected: make sure it does not affect the bus
1324+
void TVanPacketRxQueue::SetTxPinRecessive(uint8_t txPin)
1325+
{
1326+
pinMode(txPin, OUTPUT);
1327+
digitalWrite(txPin, VAN_BIT_RECESSIVE); // Set bus state to 'recessive' (CANH and CANL: not driven)
1328+
} // TVanPacketRxQueue::SetTxPinRecessive
1329+
13231330
// Copy a VAN packet out of the receive queue, if available. Otherwise, returns false.
13241331
// If a valid pointer is passed to 'isQueueOverrun', will report then clear any queue overrun condition.
13251332
bool TVanPacketRxQueue::Receive(TVanPacketRxDesc& pkt, bool* isQueueOverrun)

src/VanBusRx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ class TVanPacketRxQueue
381381
{ }
382382

383383
bool Setup(uint8_t rxPin, int queueSize = VAN_DEFAULT_RX_QUEUE_SIZE);
384+
void SetTxPinRecessive(uint8_t txPin);
384385
bool Available() const { ISR_SAFE_GET(bool, tail->state == VAN_RX_DONE); }
385386
bool Receive(TVanPacketRxDesc& pkt, bool* isQueueOverrun = NULL);
386387

0 commit comments

Comments
 (0)