This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to use BLE UART interrupt to jump out of a loop

I am trying to figure out how to exit a loop of my program using a button press on the nRF Toolbox UART app. Say it's button 4 for sake of giving it a value. I am using an Adafruit Feather 32u4 BLE microcontroller. I can start the motor from the app by pressing button 1 which sends a 1 value to the microcontroller. I can't leave the motor loop though unless I tell it how many times to loop. The loop is running the stepper motor clockwise and counter-clockwise and will need to be stopped at random times to explain what the motor is turning during a presentation. Waiting for the motor to stop will hamper the presentation. This is probably a simple question, so I apologize for my lack of knowledge on using interrupts. Any help would be great.

Parents
  • Received data through BLE UART ends up here

    static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
    

    So in that function add a little test that compares p_data to some key and then call your stop function/set your stop flag when p_data represents the right instruction.

  • So one doesn't need an interrupt then? The static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length) is constantly running in the background? I can then run a string comparison of "p_data" to "data" (the information sent from the nRF UART app) and if they equal 4 (the value sent by the button), then I can just go to a different loop or portion of the program? Interesting. I will let you know how that works.

Reply
  • So one doesn't need an interrupt then? The static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length) is constantly running in the background? I can then run a string comparison of "p_data" to "data" (the information sent from the nRF UART app) and if they equal 4 (the value sent by the button), then I can just go to a different loop or portion of the program? Interesting. I will let you know how that works.

Children
No Data
Related