Change occupation 8-Owhat should I do?
That's a nice ideaChange occupation
interrupt [USART_RXC] void usart_rx_isr(void)
{
char status,temp;
#asm("cli")
status=UCSRA;
temp=UDR;
//Break
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))!=0)
{
DmxRxstate=Break;
PORTA.7=~PORTA.7;
return;
}
//Start Code
if (DmxRxstate==Break)
{
DmxRxstate=Data;
//StartCode=temp;
PORTA.6=~PORTA.6;
Dmxcnt=0;
return;
}
//Data
if (DmxRxstate==Data)
{
if(Dmxcnt<channel)
{
Dmx_Data[Dmxcnt]=temp;
Dmxcnt++;
PORTA.5=~PORTA.5;
}
else
{
DmxRxstate=MarkBB;
PORTA.4=~PORTA.4;
}
return;
}
DmxRxstate=MarkBB;
#asm("sei")
}
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
char dmxstr[3],numstr[3];
TCCR1B=0x00;
//PORTA|=0x0F;
//PORTA.3=~PORTA.3;
#asm("cli")
PORTD.4=1;
Rx_dis;
output=LCD_out;
printf("number= %d\nDmx Rx ch10= %d",i,Dmx_Data[10]);
i++;
Rx_en;
PORTD.4=0;
#asm("sei")
TCCR1B=0x03;
}
noDid you check the model/memory settings i code vision?
no there is only a LCD and MAX485 in my boardIs there something in the board that can cause a reset (like a relay?)
it's 512 byteWhat about your stack size, can it be a problem?
Using recursive interrupts usually is not a good idea and can get out of hand, it can be the cause of the problem if a stack overflow occurs
I check it and it's 512 byteIn codevision the stack size is set manually in the project configuration, compiler tab.
No I don't have any hardware debuggerHave you tried a debugger to see the point where you get the reset?
//Data
if (DmxRxstate==Data)
{
if(Dmxcnt<channel)
{
Dmx_Data[Dmxcnt]=temp;
Dmxcnt++;
PORTA.5=~PORTA.5;
}
else
{
DmxRxstate=MarkBB;
PORTA.4=~PORTA.4;
}
return; // <-- Return from the ISR without enabling the interrupts.
}
DmxRxstate=MarkBB;
#asm("sei") // <-- Interrupts are enabled here!
the first time that I write this code there isn't any cli and sei but there are some reset and after that I added these codesSo your current code may become in a state that interrupts get disabled in general. And maybe this state is what you define a 'reset'. I suggest you reconsider your usage of 'cli' and 'sei'.
Regards...
I write it for DMX512 receiverYour code is not commented and it's hard to analyze it
Although AVR interrupts have priorities, they are prioritized only if they occur simultaneously. From this I mean a lower or higher priority interrupt cannot break into the ISR (Interrupt Service Routine) of another interrupt
I don't know dmx512 protocol so I still don't know what your code is trying to achieve.I write it for DMX512 receiver
I think if you know this portcol it's easy to understand
If you are saying what I thing you are saying then this seems wrong.
The priority only affects interrupts which are triggered simultaneously or are pending, in these cases the interrupts are served at an order based on the priority they have (vector table order).
If you enable nested interrupts inside an interrupt then the interrupt can be interrupted from any interrupt, not just itself.
So your current code may become in a state that interrupts get disabled in general. And maybe this state is what you define a 'reset'. I suggest you reconsider your usage of 'cli' and 'sei'.
Using 'cli' thus generally disabling interrupts in an ISR has no effect as this bit is already cleared automatically when entering the ISR. The opposite (the 'sei' command) however enables the interruption of the ISR by another interrupt.
return; // <-- Return from the ISR without enabling the interrupts.
}
DmxRxstate=MarkBB;
#asm("sei") // <-- Interrupts are enabled here!
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?