ATxmega32E5 USART

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Everybody

I used to work with USART and interrupts on ATxmega-AxU. Today I have ATxmega-E5 and never interrupts are triggered. Do i need to initialize XCL ? What is the simpliest way ?

Thanks for help

Regards

    Hervé

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

XCL has nothing to do with, and many people are using interrupt handling in xmegaE 's USART without any problems.
What kind of program code is it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you sure you configured the interrupt controller correctly? Try this for a start:

PMIC.CTRL |= PMIC_HILVLEN_bm |PMIC_MEDLVLEN_bm|PMIC_LOLVLEN_bm;
sei();

If you post your code, we can help you much better. But be sure to post only the relevant lines, nobody want's to read a thousand lines with only 10 relevant ones.

 

"Some people die at 25 and aren't buried until 75." -Benjamin Franklin

 

What is life's greatest illusion?"  "Innocence, my brother." -Skyrim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you Kabasan and Pawi

Here are some files : joined *.c and copied *.s (server don't accept it).

"

#include "ATxmega32E5def.incs"
#include "asm.h"
#include <avr/interrupt.h>

    .global USARTD0_RXC_vect        /* Reception Complete Interrupt */
    .global USARTD0_DRE_vect        /* Data Register Empty Interrupt */
    .global USARTD0_TXC_vect        /* Transmission Complete Interrupt */
    .global repondre
    .global test_int

test_int:
    cli
    ldi a,USART_SFDEN_bm|USART_RXEN_bm|USART_TXEN_bm
    sts    USARTD0_CTRLB,a
    ldi a,STX
    sts USARTD0_DATA,a            //premier caractère à transmettre
    ldi a,(USART_DRIE_bm|(med_lvl<<USART_RXCINTLVL_gp)|(med_lvl<<USART_TXCINTLVL_gp)|(med_lvl<<USART_DREINTLVL_gp));
    sts USARTD0_CTRLA,a
    sei
    ret

/************************************ programmes sous interruptions **********************************************/

USARTD0_RXC_vect:
    push a
    in a,SREG
    push a
    push yh
    push yl
    lds yl,PointeurRxD
    lds yh,PointeurRxD+1
    lds a,USARTD0_DATA
//    sts USARTD0_DATA,a            //echo
    st Y+,a
    sts PointeurRxD+1,yh
    sts PointeurRxD,yl
    cpi a,ETX
    brne pas_fin_message
    sbi flags_rs,mes_recu
    lds a,USARTD0_CTRLA
    cbr a,(med_lvl<<USART_RXCINTLVL_gp)
    sts USARTD0_CTRLA,a            //interdiction interruptions RxD ultérieures
pas_fin_message:
    pop yl
    pop yh
    pop a
    out SREG,a
    pop a
    reti

USARTD0_DRE_vect:
    push a
    in a,SREG
    push a
    lds a,lg_bufT
    dec a
    sts lg_bufT,a
    brne tst_sup_0
    ldi a,ETX
    sts USARTD0_DATA,a
    rjmp fin_int_tx
tst_sup_0:
    cpi a, 0xFF
    brne emettre
//    sbr flags_com,(1<<emission_terminee)
    ldi a,(1<<USART_TXCIF_bp)
    sts USARTD0_STATUS,a            //RAZ éventuel TXCIF
    ldi a,(USART_DRIE_bm|(med_lvl<<USART_RXCINTLVL_gp)|(med_lvl<<USART_TXCINTLVL_gp)|(disabled<<USART_DREINTLVL_gp));
    sts USARTD0_CTRLA,a
    rjmp fin_int_tx
emettre:
    push zl
    push zh
    lds zl,PointeurTxD
    lds zh,PointeurTxD+1
    ld a,Z+
    sts PointeurTxD,zl
    sts PointeurTxD+1,zh
    sts    USARTD0_DATA,a
    pop zh
    pop zl
    rjmp fin_int_tx

USARTD0_TXC_vect:
    push a
    in a,SREG
    push a
    ldi a,(USART_DRIE_bm|(med_lvl<<USART_RXCINTLVL_gp)|(disabled<<USART_TXCINTLVL_gp)|(disabled<<USART_DREINTLVL_gp));
    sts USARTD0_CTRLA,a

fin_int_tx:
    pop a
    out SREG,a
    pop a
    reti

"

and GCC correctly initialize vectors : part of *.lss

"

 98:    0c 94 6e 00     jmp    0xdc    ; 0xdc <__bad_interrupt>
  9c:    0c 94 6e 00     jmp    0xdc    ; 0xdc <__bad_interrupt>
  a0:    0c 94 7c 00     jmp    0xf8    ; 0xf8 <__vector_40>
  a4:    0c 94 9a 00     jmp    0x134    ; 0x134 <__vector_41>
  a8:    0c 94 c0 00     jmp    0x180    ; 0x180 <__vector_42>

"

 

I don't know what is wrong or what i forgot...

    Hervé

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Even if it shows such a long source code, I am in trouble.
You should buy a debugger.

Interruption is running after removing extra code.

 

 

/* main.c *//////////////////////////////////////////////////////////////////////
#define F_CPU 24000000UL

#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/sfr_defs.h>
#include <avr/sleep.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
void test_int(void);

#define BSEL    80        //Baud rate 921600 pour clk 24MHz
#define BSCALE    -7
#define BRR        (BSEL+(BSCALE<<12))

void init_uart()
{
    USARTD0.BAUDCTRLA=(char)BRR;
    USARTD0.BAUDCTRLB=(char)(BRR>>8);
    USARTD0.CTRLC=frame;
    USARTD0.CTRLA= USART_DRIE_bm | USART_RXCINTLVL_MED_gc | USART_TXCINTLVL_OFF_gc | USART_DREINTLVL_OFF_gc;
    USARTD0.CTRLB=((1<<USART_RXEN_bp)|(1<<USART_TXEN_bp));
}

int main(void)
{
    PMIC.CTRL |= (PMIC_HILVLEN_bm|PMIC_MEDLVLEN_bm|PMIC_LOLVLEN_bm);
    sei();
    init_uart();
    set_sleep_mode(SLEEP_MODE_IDLE);
    test_int();
    while (1) 
    {
        sleep_enable();
        sleep_cpu();
        sleep_disable();
        wdt_reset();
    }
}

 

/* asm.s */////////////////////////////////////////////////////////////////////////////////////
#include <avr/interrupt.h>
#define    a    r16
    .global USARTD0_RXC_vect        /* Reception Complete Interrupt */
    .global USARTD0_DRE_vect        /* Data Register Empty Interrupt */
    .global USARTD0_TXC_vect        /* Transmission Complete Interrupt */
    .global test_int

test_int:
    cli
    ldi a,USART_SFDEN_bm|USART_RXEN_bm|USART_TXEN_bm
    sts    USARTD0_CTRLB,a
    ldi a,0x02    // STX
    sts USARTD0_DATA,a
    ldi a,0b01101010
    sts USARTD0_CTRLA,a
    sei
    ret

////////////////////////////////////////////////////////////////////////////////////
USARTD0_RXC_vect:
    nop
    reti
////////////////////////////////////////////////////////////////////////////////////
USARTD0_DRE_vect:
    nop
    push a
    in a,SREG
    push a

    ldi a,0b01101000
    sts USARTD0_CTRLA,a

    pop a
    out SREG,a
    pop a
    reti
////////////////////////////////////////////////////////////////////////////////////
USARTD0_TXC_vect:
    nop
    reti

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Kabasan,

and thank you for help.

made a new project with "your" code : it works ! smiley

Now, i need to see where the differences are... i will not have time today, nor tomorrow. Perhaps in the evening.

Thanks a lot

   Hervé

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

How to correctly post source code: http://www.avrfreaks.net/comment...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

The program is working now. I added 2 other interrupt sources (TCC4 and ADCA) but I had to assign them different priority levels (High and low, USART is using medium level) or the program doesn't work. Does PMIC works as on other XMEGA ? I used XMEGA-AU microcontrollers before, with many interrupts on the same level. Or perhaps i forgot something with this program ?

...

regards

  Hervé