UART problem

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

Hello,

I want to enable the E1 UART on an ATXmega256A3 (tx on PE7 and rx on PE6). I'm using the AVR1307 code.
The chip has an external crystal of 14.7456 MHz and I enabled the PLL x2. The WDT is set to 1s.

This is a small example:

#include 
#include 
#include 
#include "usart_driver.h"

#define USART USARTE1
USART_data_t USART_data;

ISR(USARTE1_RXC_vect) {
    USART_RXComplete(&USART_data);
}

ISR(USARTE1_DRE_vect) {
    USART_DataRegEmpty(&USART_data);
}

int main(void) {
    PORTE.OUT = PIN7_bm;
    PORTE.DIR = PIN7_bm;

    /* Clock */
    CLKSYS_XOSC_Config(OSC_FRQRANGE_12TO16_gc, false, OSC_XOSCSEL_XTAL_256CLK_gc);
    CLKSYS_Enable(OSC_XOSCEN_bm);
    while (CLKSYS_IsReady( OSC_XOSCRDY_bm ) == 0);
    CLKSYS_PLL_Config(OSC_PLLSRC_XOSC_gc, 2);
    CLKSYS_Enable(OSC_PLLEN_bm);
    while (CLKSYS_IsReady(OSC_PLLRDY_bm) == 0 );
    CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_PLL_gc );
    CLKSYS_Disable(OSC_RC2MEN_bm);
  	
    /* UART */
    USART_InterruptDriver_Initialize(&USART_data, &USART, USART_DREINTLVL_LO_gc);
    USART_Format_Set(USART_data.usart, USART_CHSIZE_8BIT_gc, USART_PMODE_DISABLED_gc, false);
    USART_RxdInterruptLevel_Set(USART_data.usart, USAR_RXCINTLVL_LO_gc);
    USART_Baudrate_Set(&USART, 15, 0); // 115200
    USART_Rx_Enable(USART_data.usart);
    USART_Tx_Enable(USART_data.usart);
    PMIC.CTRL |= PMIC_LOLVLEX_bm;

    sei();
		
    for(;;) {
	wdt_reset();
	_delay_ms(250);
        USART_TXBuffer_PutByte(&USART_data, 'a');               
    }
}

I get a steady high-level on PE7 instead of the transmission.
If I toggle a led in the main loop it flashes, so the MCU is working.

Reading the datasheet it seems I don't need further configuration. Anyway I also tried a "low level" way, setting each register by hand with no chance.

Do you see any error in my code?
Thanks!

Marco

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

Updates.

the code provided by Atmel seems wrong:

PMIC.CTRL |= PMIC_LOLVLEX_bm;

should be:

PMIC.CTRL |= PMIC_LOLVLEN_bm;

Why?

In fact now the other USARTs work fine.
I can't transmit on USART_E1 (PE7) in any case. Does it need a particular initialization?

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

Quote:
I can't transmit on USART_E1 (PE7) in any case. Does it need a particular initialization?

Is your part number ATXMEGA256A3 or ATXMEGA256A3B? If the second case is true, it has not USARTE1.

Ozhan KD
Knowledge is POWER

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

Oh no.
You're right.
I ordered the MCU from digikey and they don't have the A3 at stock. Honestly I didn't noticed the 'B' suffix. I thought it was a Digikey internal code.

Mouser don't have the A3 in stock too. It's so difficult to buy Atmel products :(

The 256A3 is the only XMEGA that has the 'B' version, indeed. Why? The differences seem to be only on USART.

Sgrunt.

Anyway, may you confirm that the Atmel code is wrong?

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

iw2nzm wrote:

The 256A3 is the only XMEGA that has the 'B' version, indeed. Why? The differences seem to be only on USART.

Anyway, may you confirm that the Atmel code is wrong?


ATXMEGA256A3B has a special feature for connecting a battery and apparently B stands for "Battery backup".
And about error in atmel code, I saw IAR headers and it is defined:

#define PMIC_LOLVLEX_bm 0x01 // Low Level Interrupt Executing bit mask

Ozhan KD
Knowledge is POWER

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

Yes, but the datasheet says that the PMIC.CTRL register doesn't have the LOLVLEX bit. Instead it has the LOLVLEN one (Low Level Interrupt Enable).

Fortunately both have the same definition (0x01) but we're just lucky :)

Thank you for the explanation of the 'B' suffix.