is possible detect a midi clock in from pin rx through the enabling interrupts?
i know what arduino has pin 2 y 3 (to change voltage), or timers overflow.
the byte for midi clock is 0xf8.
The MIDI clock in is just a serial byte with value 0xF8. Just read the serial port until you find a byte with that value.
ok, but the processor is continually read the port rx. I want acurate timming, if it's possible, while arduino work on other task.
more clear, on large code, when the input signal from rx has been read, and has detected a byte with 0xF8 value, more cycles of processor has been spend, more time has elapsed since entering the signal port, and the microprocessor have not done anything about it, until the processor reads the signal again on the next pass.
so I want to use interrupts if it's possible?
-sorry for my english -
Interrupts are part of Hardware Serial, where the incoming byte is noticed and placed into a buffer. So it is already done by interrupts. One way is to check Serial.available() as fast as possible so you notice the byte quickly.
If that isn't good enough you would need to make your own serial interrupt routine, which won't be too easy because Hardware Serial is automatically included in your project.
One way would be to make a copy of the whole IDE for this project, and then edit HardwareSerial.cpp. Assuming you are using the first serial port, effectively you would have to edit this part (simplified here):
SIGNAL(USART0_RX_vect)
{
unsigned char c = UDR0;
store_char(c, &rx_buffer);
}
In addition (or instead of) store_char you would call your own interrupt handler. Or maybe just have it note the time that each byte arrived.
thanks for the reply, nick.
this is more complicated than I thought, I'll try and see what happens.