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

I am using the NRF2840 and WaveShare's 2.9 epaper display to make a cutdown tool, but I am facing some problems.

I have realized the cutdown function with the examples. But now I want to reflesh the number I have published, which means that I first publish a number, then I want to publish a new number. But now, the new number i published can't preemptive the old number. I want to know how to replace the old number. Thanks for all of your effort.

yours sincerely,

Leo Li.

  • I have update some of my code in the reply to Edvin. Maybe that will help you to understand my thoughts. I just can't abort the countdown, maybe it's because of that the Nordic UART Service is FIFO?

    Thank you for your continuous attention to my questions.

  • I just can't abort the countdown

    Why not?

    What's the problem?

    maybe it's because of that the Nordic UART Service is FIFO

    Why would that be a problem?

    It's your code that does the countdown - so you should know how to abort it!

    Can you get this working on its own - without the added complication of BLE?

    It sounds like a problem with your system design ...

  • Ok, I see.

    The issue is that you are handling your entire countdown in the nus_data_handler(). Hence, when a new number enters, it is not able to handle that callback until you finish the handler that you are in now. They are two equal events with the same priority, so the new number is not called until the previous has returned.

    I suggest you do something like this:

    volatile uint32_t time_now_s = 0;       // remember to use volatile
    volatile bool start_countdown = false;  // remember to use volatile
    static void nus_data_handler(...)
    {
        if (p_evt->type == BLE_NUS_EVT_RX_DATA)
        {
            time_now_s = atoi((char*)p_evt->params.rx_...;
            start_countdown = true;
        }
    }
    
    static void start_my_countdown()
    {
        while(time_now_s > 0)
        {
            time_now_s--;
            ...
        }
    }
    
    main()
    {
        ...
        for(;;)
        {
            if(start_countdown)
            {
                start_my_countdown();
                start_countdown = false;
            }
        }
    }

    But that is also not perfect. You should really use a timer that has a timeout of 1 second or whatever resolution you need, and use the timeout handler to decrement time_now_s and update the display. This way, you will allow the nRF to go to sleep to save some power while you are running the countdown as well.

  • That's exactly what I mean. I solved the problem with your help. Thank you very much for your kindly help these days.

  • It's indeed the problem of my design. But I have solved that problem with Edvin's help. Thank you very much for your insistent attention to my problem.

Related