Hi all!!
I was using with success an Atmega 8 to rebuild a RS-232 signal that is coded in 5uSeg NRZ left. Rebuild this signal is easy using a monostable timer.
For some reason this works great in several atmega8, but in a few this rebuild fails.
The code is realy simple, i'm using only an external interrupt, an output PIN and a delay like this:
void Rs232(){
detachInterrupt(0);
digitalWrite(TxLoop,LOW);
delayMicroseconds(400); //(1/2400Bps) + proccess delays
digitalWrite(TxLoop,HIGH);
attachInterrupt(0, Rs232, RISING);
Al the uP use a modified bootloader with 3V3 and 8Mhz clock. All this for a At mega 8.. what can be happenning?.. bad fuses? i was using the same for all the uPs and in some works great and in others fails.
Is valid use delay() function into a interrupt function's call??
Ideas? =(
Best Regards
Frank
If you search a little, I think you will find several posts that say delay() does not work in the interrupt service routines.
Never tried it myself.
Yeap.. i was suspecting that, i think that the rigth way to use an interrupt for this application will be use the TMR0..TMRx and trigger it at the interrupt service, and let to the timmer interrupt change the output pin state.
I will test this!
Best Regards
Frank
Are you just trying to reproduce the serial waveform on another pin?
Rob
Yeap, i got two options, reproduce the signal and reinsert to the UART.. what today is working, or use a modified SoftSerial library to decode this signal without rebuild it.
For now the first thing will be code a timer int() to tigger it when the pulse starts at the input int()
Best Regards
Frank
If you just need to reproduce the signal I see three options
a) forget the Arduino, just use a wire
b) if you don't have to do anything else then don't bother with timers and interrupts, OUT_PORT_PIN = IN_PORT_PIN
c) if you do have other processing to do then attachInterrupt (serialPortPin, CHANGE); in the ISR, OUT_PORT_PIN = IN_PORT_PIN
There may be some jitter because of the millis() interrupt but that will be the case with any approach I think unless you disable it.
Rob