1 Reply Latest reply on Feb 14, 2018 1:28 AM by anks

    Having trouble with ISR, need help ASAP

    cblinney_2276156

      I am having trouble with an ISR that I really need to work properly, but a little background on the project might be needed.  I am writing code to talk to a flight controller on a drone, and I am testing an ultrasonic sensor on it as well pointed down to help hold its altitude.  The problem I have currently is that the flight controller uses SBUS, an inverted UART signal at 100k baud, which is all fine and well, but each frame is 3ms long and they need to have fairly closely to 6ms delay between frames.  We had code written that worked ok using CyDelay(6000), but because it wasn't using an ISR, any code added made that 6ms longer.  Unfortunately if it gets too far from that, the flight controller gets confused and tosses a wobbly (with the possibility of it going full throttle unexpectedly), and I now have a bunch of stitches in one hand, and when my other hand heals I will likely not have a couple fingerprints anymore.  So its imperative that I get the communication set up to run at the same time constantly.

       

      The problem I am having is I moved the code for sending what is needed over the UART/SBUS into an ISR, however it does not function as it did before.  Inserting breakpoints I can see it hitting it each time, but it is not sending correct values.  I am wondering if I am allowed to change variables in the main function and also have them used in the ISR?  I have also tried having the ISR just jump to the function we had originally for sending the data, and having the variables declared outside of the functions so both could use it, however that does not work either.  I have been fighting with this for a few days and haven't come up with a solution, and other project members are getting antsy to test but can't because its unsafe to do so currently.

       

      I attached the archive file, it has the ISR as well as the function for sending over UART/SBUS in the main.c file as I am not sure which method will work better.