Question

A lot of hardware comes with a Tx/Rx status LED, but what if your hardware doesn't and you want to see if data is transmitting? If you just set the LED to the value of the line it may go on and off before you even see it (<1/100th of a sec.).

My question is, how do I write an interrupt driven function to drive the LED state? I've searched the internet and found nothing and I could use a counter with a modulus, but that seems clunky. Any other ideas?

PS - I'd like to use this in either Arduino or Mbed, but I doubt it makes a difference to the question as to which one...

Was it helpful?

Solution

void receive_or_transmit_interrupt()
{
     g_traffic = true;
     /* other stuff. */
}

void timer_that_fires_every_100_milliseconds()
{
     if ( led == ON)
     {
          led = OFF;
          g_traffic = false;
     }
     else if ( g_traffic )
     {
          led = ON;
     }
}

If you don't want the timer to always be firing even when there's not traffic, you could change the receive_or_transmit_interrupt to enable the timer, and the timer could disable itself when it turns off the LED.

OTHER TIPS

A simple way is to switch the LED on in the Tx/Rx interrupt and initiate a timer of say 200ms (long enough to perceive). You then switch the LED off in the timer ISR.

That way the indicator is extinguished 200 ms after the last tx/rx activity. If the activity is sustained, the indicator will remain illuminated.

If the tx/rx bursts are intermittent with greater than 200ms gaps, the indicator will flicker. So the states of off, on and flickering give a broad indication of the data activity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top