This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP432P401R: Code Composer Studio code for HC-SR04 Ultrasonic sensors

Part Number: MSP432P401R

Tool/software: Code Composer Studio

I have been working on a project where I need to use an HC-SR04 Ultrasonic sensor with my Red MSP432, but have been having a lot of trouble trying to get any actual distance readings from it.

For various reasons, I cannot use Energia for this, and so I was hoping to get some help with how to get this to work with CCS. I have so far been working on trying to adapt/work with Olivier Herrou's code from his post back in July 2017 along with the change to line 44 suggested on that post, but am not quite sure what I would need to do from here to get valid distance measurements.

Any help, advice, or alternate solutions here would be greatly appreciated.

Thanks, 

Aman

  • Aman,
    I would confirm that your hardware is working as expected - can you see the trigger and echo signals with a scope. Are they swinging between 0 and Vcc? Once you confirm that , then look at your code to see if the timer ISR is being entered.

    Based upon what I see in the code, it looks like interrupt is only measuring the delta between the rising and falling edge. I would have thought it would be based upon the delta between when the transmit pulse is sent on P1.5 and then received on P2.4. I am not familiar with the device, so please correct me if that is not the intended usage.

    Regards,
    Chris
  • Chris,

    I have checked the HC-SR04s, and they do work. I have gotten distance measeurements from them with the MSP432 using Energia, but as I said in the main post, I need to get them to work with CCS for this project.

    What you have said about how the sensor should work is correct. I am trying to use that code as a base so I have somewhere to start from, but I am not sure how to change it to behave the way it needs to. If you could tell me what to do, or point me in the right direction, I'd really appreciate it.

    Thanks,
    Aman
  • Aman,
    I was mistaken about the code, the ISR is only triggered on the rising edge, so ideally the first rising edge would be from the initial trigger and the second would be from the return pulse. What is the distance and what are you seeing as the delta between the first and second edges? Since you are using a launchpad you could use the leds on P1.0 and P2.0 to determine if the timing is correct. You would need to insert statements in your code to toggle the led for each capture. You could then use a scope to see what the time is and if that is in line with the actual transmit and receive information from the HC-SR04.

    Good luck.

    Chris

**Attention** This is a public forum