@@ -44,7 +44,7 @@ void Lin_TJA1020::setMode(const Mode mode)
4444{
4545 // we don't need to act, if we're allready there
4646 // see "setMode(sleep)" in the switch below
47- if (mode == _currentMode )
47+ if (mode == getMode () )
4848 {
4949 return ;
5050 }
@@ -103,7 +103,7 @@ void Lin_TJA1020::setMode(const Mode mode)
103103 default : // = Sleep
104104 // no direct step from Standby to Sleep, but we don't know if we're in
105105 // we're going over _writingSlope
106- setMode (_writingSlope );
106+ setMode (Mode::NormalSlope );
107107
108108 // rising edge on /SLP while TXD = 1
109109 digitalWrite (txPin, HIGH);
@@ -131,12 +131,30 @@ void Lin_TJA1020::setMode(const Mode mode)
131131 }
132132} // void Lin_TJA1020::setMode(TJA1020_Mode newMode)
133133
134- // / Defines standard slope, to be used, when writing to the bus
135- void Lin_TJA1020::setSlope (const Mode slope)
134+ Lin_TJA1020::Mode Lin_TJA1020::getMode ()
136135{
137- _writingSlope = slope;
138- if (_writingSlope == Mode::Sleep)
139- {
140- _writingSlope = Mode::NormalSlope;
136+ if (_currentMode == Mode::Sleep) {
137+
138+ // test MCU PullUp against TJA Pulldown
139+ pinMode (txPin, INPUT);
140+ delayMicroseconds (1 ); // settle time
141+ bool hasWeakPullDn = !digitalRead (txPin);
142+
143+ pinMode (txPin, INPUT_PULLUP);
144+ delayMicroseconds (1 ); // settle time
145+ bool hasStrongPullDn = !digitalRead (txPin);
146+
147+ // revert setting
148+ pinMode (txPin, INPUT);
149+
150+ if (hasWeakPullDn && !hasStrongPullDn)
151+ {
152+ // TXD has weak pull-down on remote wake-up
153+ _currentMode = Mode::StandbyWakeupRemote;
154+ } else {
155+ // TXD has strong pull-down on local wake-up (caused by /WAKE pin)
156+ _currentMode = Mode::StandbyWakeupLocal;
157+ }
141158 }
159+ return _currentMode;
142160}
0 commit comments