BSS138 level shifter causing problems
I thought a BSS138 was just a single Nch FET. You don't have any pullup R's but you don't need it anyways.
The L298 works off of 2.3V logic to 5V logic
Vil &lt;= 1.5 V
Vih &gt;= 2.3V
Also with Vce(sat) on hi/lo outputs you need at least 2.5V more than motor rated voltage for full RPM + torque.  CMOS or FET power half or full H bridge drivers are better
This is not TTL input which has a threshold of 2 diode drops or 1.3 so the Vil &lt;=0.8V and Vih&gt;=2V.  What does the datasheet tell you for Ih, Il?  ( no issue ).
So you don't need the level shifter.