You need to log in to create posts and topics.

External Interrupt ATMEGA328

Hello, everyone!

 

I need help with External Interrupt (INT0). I tried a simple circuit design to test this feature. When PD2 is activated, the flag INTF0 is correctly set, but Program Counter doesn't load interrupt vector value (0x0002). My SIMULIDE version is 1.1.0.

 

.ORG 0x0000
    RJMP CONFIGURACAO
    
.ORG 0x0002 EINT0:
    RCALL TRATAMENTO_INT0
 RETI   
    
    
.ORG 0x0034 CONFIGURACAO:
    LDI R16,0b11101011
    OUT DDRD,R16
    CLR R16
    OUT PORTD,R16
    
    LDI R16,0b00000011 ;<== RISING EDGE OF INT0
    STS EICRA,R16
    LDI R16,0b00000001
    OUT EIMSK,R16
    SEI
    
PRINCIPAL:
    RJMP PRINCIPAL
    

    
SALVAR_STATUS:
    IN R17,SREG
    RET

CARREGAR_STATUS:
    OUT SREG,R17
    RET
    
PAUSAR_INTERRUPCAO:
   CLI
   RET
   
PAUSAR_CONTAGEM:
    CLR R16
    OUT TCCR0B,R16
    OUT TCNT0,R16
    RET
    
TRATAMENTO_INT0:
    RCALL SALVAR_STATUS
    RCALL PAUSAR_INTERRUPCAO
    IN R16,PORTD
    LDI R18,0x00000001
    EOR R16,R18
    OUT PORTD,R16
    RCALL CARREGAR_STATUS
    RET

 

 

 

Hi.

Seems that Stack Pointer is not initiallized in Simulide.
Until this issue is fixed you can initialize it in your CONFIGURACAO routine:

;Initialise stack
    ldi SysValueCopy,high(RAMEND)
    out SPH, SysValueCopy
    ldi SysValueCopy,low(RAMEND)
    out SPL, SysValueCopy

 

Ragmar has reacted to this post.
Ragmar