So I've seen a lot of posts on making timers generate interrupts and the like, but I'm looking to get the time an interrupt occurs. It says you can't use millis() or delay() in an ISR, so how can you figure out what time an interrupt occurred? I'd like my ISR to take the current time, send out a header byte, sent the time, and restart the main loop.
My backup idea is to just have an interrupt flag. If it's true, the first thing the main loop will do is send out the time package and reset the flag. Else it will execute the normal code. The ISR could just set that flag and return to the top of the main loop. That way I'd only lose a few micro seconds and wouldn't have to wait for the whole loop to cycle.
You can call millis() inside your ISR. Don't call delay(), it will hang.
You will need to think about doing the sending as well... depending on your baud rate you might take too long and lose a timer interrupt. I think I'd just right the timestamp to a global variable in the ISR and let the loop() notice the timestamp was written and do the sending.
Ya, I saw millis() wasn't causing any noticeable problems. I'm not sure what you mean about losing the timer interrupt when sending. I was thinking I'd put the sending of the time stamp set by the interrupt at the top of the main loop. That way if the interrupt comes in the middle of sending out a bunch of data, I won't return from the ISR and finish sending the now useless data. I'll actually complete sending my original packet before I send out the interrupt time stamp.