2014-12-16 02:03 AM
I try to create a robot car, using a MCU stm32f3 Discovery, an ultrasonic sensor HC-SR04, two motors and H-Bridge L298N to control the DC motors a , and a conversor RS232 to USB, for to see the distance in my pc.
The problem is: When i supply the MCU STM32 Discovery by USB, i can see without problems the distance.The HC-SR04 and conversor works fine.But when i supply the MCU (5V) through the L928N H-Bridge, the ultrasonic sensor don´t works correctly and , just can see some characters.To supply the L298N i use a mobile phone charger, and they debit a 12V DC . In send in annex the hardware Diagram. Thanks for any help. Greetins2014-12-16 02:44 AM
But when i supply the MCU (5V) through the L928N H-Bridge, ...
Citing from the L298 datasheet:An additional supply input is provided so that the logic works at a lower voltage.
You can't supply your MCU/sensor, etc., from the L298 (as I understood you are trying). The other way around, you need to provide a stable 5V to the VSS pins (9 or 12, depending on package).
2014-12-17 06:04 AM
Thaks for answer.
But i also tried with a 9V battery, for supplie the L298N and the sensor dont works.So, how i can supplie the L298N (and motors ) and the HC-SR04 correctly?.What is the best away?2014-12-17 08:35 AM
But i also tried with a 9V battery, for supplie the L298N and the sensor dont works.
Not sure what you mean by that. You need two supply voltages for the L298N, one +5V (digital logic) and one for the motor (e.g. 12V in your case). Your sensor needs +5V, the discovery board too (the 5V input). To interface the sensor, make sure you use 5 volt - tolerant GPIOs, and that output to the sensor achieves a sufficient level. The datasheet only specifies ''TTL''. Only the L298N needs/accepts a higher voltage, e.g. 9V or 12V in your case. If you had the sensor and the discovery board hooked up to that, they might already be dead. I would be wary of EMI issues. A motor's back-EMF can kill you sensor + discovery board.
2014-12-17 03:00 PM
2014-12-18 02:51 AM
Sounds like you have a problem with logic levels.
When supplied by USB, the discovery board actually sees about 4.7V, and about 3.1V for the MCU. Both thanks to Shottky diodes in the supply lines. The trigger output (from the MCU to the sensor) might have sufficient level when the sensor is supplied with 4.7V, but not when supplied with 5.0V, as threshold levels move with supply voltage. You can try to configure the output as open drain and add a pull-up resistor, or use an external transistor.2014-12-18 03:17 AM
2014-12-18 09:14 AM
So, i have to use the another 5v from MCU and install a resistor (by hardware)?
Not sure what you mean with that, but no.
Or , i have to use a PIN output, for example PD2 and configure by software as a open drain and add a pull-up resistor?
If PD2 is the output to drive the sensor trigger signal, yes.
The internal pull-ups are tied to 3.3V (3.1V, actually) and are obviously not sufficient. So you need an external pull-up resistor to 5V.
Since the sensor datasheet is rather unspecific about driving requirements for the trigger input, I would start with 5 ... 10kOhm.
BTW, if you have a scope, you could try to analyze the situation.
I can only guess.
2014-12-19 02:56 AM
2014-12-19 05:35 AM
But i gone tray with a resistor into the line of 5V from MCU to Sensor, and see what happen.
Again, I'm not sure what you mean by that. The pull-up resistor needs to be from PD2 (the trigger output) to +5V. You presumably need a higher trigger pulse level, as 3V seem not to work, when you properly support the sensor with 5V. If unsure, look up ''pull-up resistor'' in your favourite search engine.