@@ -44,7 +44,7 @@ void Lin_TJA1020::setMode(const Mode mode)
44
44
{
45
45
// we don't need to act, if we're allready there
46
46
// see "setMode(sleep)" in the switch below
47
- if (mode == _currentMode )
47
+ if (mode == getMode () )
48
48
{
49
49
return ;
50
50
}
@@ -103,7 +103,7 @@ void Lin_TJA1020::setMode(const Mode mode)
103
103
default : // = Sleep
104
104
// no direct step from Standby to Sleep, but we don't know if we're in
105
105
// we're going over _writingSlope
106
- setMode (_writingSlope );
106
+ setMode (Mode::NormalSlope );
107
107
108
108
// rising edge on /SLP while TXD = 1
109
109
digitalWrite (txPin, HIGH);
@@ -131,12 +131,30 @@ void Lin_TJA1020::setMode(const Mode mode)
131
131
}
132
132
} // void Lin_TJA1020::setMode(TJA1020_Mode newMode)
133
133
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 ()
136
135
{
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
+ }
141
158
}
159
+ return _currentMode;
142
160
}
0 commit comments