ATXMEGA

From MCS Wiki AVR
Jump to: navigation, search

The ATXMEGA is a great new chip. It has a lot of hardware on board and a huge amount of hardware registers.

Some changes in the architecture are however breaking compatibility with normal AVR (ATMEGA/ATTINY) processors.

 

The ATXMEGA bring a huge amount of interfaces like UART, I2C, SPI, Counter/Timer, 12-Bit Analog Input/Output and also new features like DMA (Direct Memory Access), the Event System or AES hardware encryption/decryption.

 

All ATXMEGA have their registers at the same address. Some chips might not have all registers because the hardware is not inside the chip, but all DAT* files are similar. And all hardware has a fixed offset. This allows to use dynamic code. For example Bascom-AVR can now use a variable for the UART and the code is only needed once because all hardware has a fixed offset.

 

  • DAT files are the register files. The register files are stored in the BASCOM-AVR application directory and they all have the DAT extension. The register file holds information about the chip such as the internal registers and interrupt addresses. The register file info is derived from ATMEL definition files.

 

The ATXMEGA work with 3.3V so please do not connect something which output 5V to the XMEGA Pin's. Use a Level Shifter for that.

The maximum rating for a ATXMEGA  Pin is 3.6 V.

When using the internal 32MHz oscillator you need at least 2.7V Vcc. The internal 32MHz oscillator is stable enough for a lot of applications. The maximum CPU Clock Frequency is 12MHz when using the XMEGA with just 1.6V Vcc.

 

Read Application Note AVR1012: XMEGA A Schematic Checklist for special considerations in your hardware design.

 

 

You can find Bascom samples for ATXMEGA in Bascom-AVR folder:

General samples ……..\BASCOM-AVR\SAMPLES\XMEGA
Bootloader samples in ………\BASCOM-AVR\SAMPLES\BOOT
For chips like xm128a1 in …….\BASCOM-AVR\SAMPLES\CHIPS

 

Contents

Manuals for ATXMEGA:  There are 2 manuals available from ATMEL for every ATXMEGA Chip

 

1. One Family Manual like for example for a ATXMEGA128A1 it is Atmel AVR XMEGA A Manual
2. Another Manual for the single chips like for example for an ATXMEGA128A1 it is the ATxmega64A1/128A1/192A1/256A1/384A1 Manual. In this Manual you find for example the Alternate Pin Functions. So you can find which Pin on Port C is the SDA and SCL Pin when you want to use the I2C/TWI Interface of this Port.

 

Beside the Manuals for the ATXMEGA chips there are a lot of Appliaction Notes available on the ATMEL website which explain for example the ATXMEGA Event System or Direct Memory Access (DMA) and so forth.

 

What you need to get started with ATXMEGA and BASCOM-AVR

 

1. The latest Bascom-AVR FULL Version (The Demo Version of Bascom-AVR do not support ATXMEGA).
2. An evaluation board like the Atmel AVR XMEGA® Xplained evaluation kit or any other ATXMEGA evaluation board with PDI (Program and Debug Interface) header.
3. A Programmer like AVRISP MKII or any other PDI or JTAG programmer which support ATXMEGA.
4. Latest AVR-Studio 4.X or 5.X only for setting fuse bits and to flash Bootloader to ATXMEGA.
5. Programming the ATXMEGA can be done direct from BASCOM-IDE. See also LIBUSB for further information.

 

The most important parts of an Bascom-AVR Program for XMEGA are:

 

1. The Register file for the chip, crystal init and Stacks

 

$regfile = "xm128a1def.dat"
$crystal = 32000000                     '32MHz
$hwstack = 64
$swstack = 40
$framesize = 64

 

2. Enable and configure  the oscillator of your choice:

 

Config Osc = Enabled , 32mhzosc = Enabled         ' enable 2 MHz and 32 MHz internal oscillators

 

3. Select the oscillator source for the system clock and prescaler (this must match with $crystal = XXXXXX). The following configure the internal 32MHz oscillator as system clock without prescaler so the system clock is 32MHz which match with $crystal = 32000000

 

Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1  

 

4. If you intend to use interrupts you need to configure it before you use the Enable Interrupt command. Bascom-AVR will automatically enable the medium level interrupt when Enable Interrupt is in the code but not the low and high level interrupts.

 

Config Priority = Static , Vector = Application , Lo = Enabled , Med = Enabled , Hi = enabled

 

5. Also when you want to use EEPROM you need to configure it before you can use it:

 

Config Eeprom = Mapped             'Setup memory mode for EEPROM in XMEGA

 

 

6. After this you can add Enable Interrupts and your code in the Main Loop.

 

Do
'Insert your code
Loop

 

7. End

 

End                                               'end program      

 

 

FAQ - ATXMEGA

 

Q: How to program/flash an ATXMEGA ?

A: There is no ISP programming support. Only JTAG and PDI is supported. Of course the MCS Bootloader can be used         but you need to program the chip first with for example an AVRISP MKII programmer. After this programming the

   ATXMEGA can be done direct from BASCOM-IDE

  Important is also that the AVRISP MKII programmer need 3.3V supply voltage from the Target.

 

Q: Is there a special boot loader source code I can use for ATXMEGA ?

A: There are example boot loader in following Bascom-AVR folder (C:\......\BASCOM-AVR\SAMPLES\BOOT)

  like ATXMEGA32A4 or ATXEMGA128A1. For other ATXMEGA Chips the source code can be easily adapted.

 

Q: What is the Program and Debug Interface (PDI) ?

A: The Program and Debug Interface (PDI) is an Atmel proprietary interface for external programming and on-chip    

   debugging of a device.

 

  “The XMEGA doesnt have the SPI based In-System Programming (ISP) interface for

   external programming, which has been used for megaAVR. Nor does it have the

   debugWIRE interface. These have been replaced by a two wire “Programming and

   Debugging Interface” (PDI).” [from Atmel App Note AVR1005]

 

Q: How to read/write from/to ATXMEGA Register ?

A: If you want or need to write or read ATXMEGA Registers direct you just need to find the name by using the  

   ATXMEGA DAT file.

   For example if you want to read the ATXMEGA Revision there is the register Mcu_revid in the DAT file.

  The DAT files can be found in the BASCOM-AVR folder.

   Take care with protected registers. Before you can write to this registers you need to release it. An example for this       is the Software Reset.

 

Q: How to initiate a software Reset of an ATXMEGA ?

A: Before you can write the Software Reset Bit you need to release the write protection for this bit and register.

 'enable change of protected Registers for following 4 CPU Instruction Cycles
  CPU_CCP = &HD8
  'Initiate Software Reset by setting Bit0 of RST_CTRL Register
  Rst_ctrl.= 1                 'When this bit is set a software reset occur

 

Q: For what do I need Fuse Bits (Fuses) with ATXMEGA ?

A: “The Fuses are used to set important system function and can only be written from an external

   programming interface. The application software can read the fuses. The fuses are used to configure

   reset sources such as Brown-out Detector and Watchdog, Start-up configuration, JTAG

   enable and JTAG user ID, Bootloader…..An unprogrammed fuse or lock bit will have the value one, while a    

   programmed flash or lock bit will have the value zero..” [ATXEMGA A Manual]

 

Q: How to write to 16-Bit (Word) Register of ATXMEGA ?

A: You do not care about the 16-Bit (Word) Register because the compiler will handle this for you automatic.

   For this you can find the [WIO] (Word IO) Section in the DAT file. You can only write direct to 16-Bit Register over        the defined register in the [WIO] section of the DAT file

   If there is a need to manual write/read to/from 16-Bit register you always need to write/read the LOW Byte (LSB)

   and then the HIGH Byte (MSB).

 

Q: Is there also a linear memory architecture as with ATMEGA or ATTINY AVR's ?

A: The power of the AVR is/was the linear memory architecture. In the ATXMEGA this has been changed : the registers      are placed into a separate address space. This makes code like this fail:

 

   Clr r31

   Ldi r30,10   ; point to register R10

   Ld r24,z+   ; load value from R10 and inc pointer

 

   Of course LDS/STS will not work either on the registers.

   If your ASM code contains such code you need to rewrite it.

 

Q: Is the Bascom-AVR Demo version supporting ATXMEGA ?

A: ATXMEGA is not available in PDIP. This means that the ATXMEGA is not really suited for hobby projects.

  As a result, the DEMO version does not support the ATXMEGA.

 

 

Q: For what are Virtual Port Registers good for ?

A: “Virtual port registers allow for port registers in the extended I/O memory space to be mapped virtually

   in the I/O memory space. When mapping a port, writing to the virtual port register will be

   the same as writing to the real port register. This enables use of I/O memory specific instructions

   for bit-manipulation, and the I/O memory specific instructions IN and OUT on port register that

   normally resides in the extended I/O memory space. There are four virtual ports, so up to four

   ports can be mapped virtually at the same time. The mapped registers are IN, OUT, DIR and

   INTFLAGS.” [from ATXMEGA A Manual]

 

Q: Is Serialin and Serialout supported for UART Interfaces above COM4

A: No buffered serialin and buffered serialout is supported for the first 4 UARTS (COM1....COM4). For COM5....COM8 you      can use an interrupt routine or DMA (Direct Memory Access) as an alternative.

 

  For ATXMEGA the first 4 UARTS can use for example serialin:

  SERIALIN   : first UART/UART0        --> COM1
  SERIALIN1 : second UART/UART1 --> COM2
  SERIALIN2 : third UART/UART2        --> COM3
  SERIALIN3 : fourth UART/UART3        --> COM4
 

 

  For example with an ATXMEGA128A1 you get 8 UARTS:

  Every of the 8 USART’s has for example a Receive Interrupt which you can use to analyze incoming data:

 

    ATXMEGA128A1 Receive Interrupts:
    COM1 --> Usartc0_rxc
    COM2 --> Usartc1_rxc
    COM3 --> Usartd0_rxc
    COM4 --> Usartd1_rxc
    COM5 --> Usarte0_rxc
    COM6 --> Usarte1_rxc
    COM7 --> Usartf0_rxc
    COM8 --> Usartf1_rxc

 

   In the interrupt routine you need to use the inkey(#X) function because inkey(#X) is reading the data register and

   therefore reset the interrupt flag. Without reading the data register or resetting the interrupt flag manual the

   interrupt will fire again and again.

 

   Example the interrupt routine:

 

  Rxc_isr:
     Rs232 = Inkey(#1)
    'do something with the data
 Return

 

 

Q: How to get the reason for a reset of ATXMEGA (like power on, watchdog or software rest)

A: There is a special register for that RST_STATUS you can read and analyze.

 

 

Q: How to auto calibrate the internal 2MHz and 32MHz Oscillators during runtime ?

A: The automatic runtime calibration of internal oscillators is activated by enabling the DFLL (Digital Frequency-locked Loops) and autocalibration.

 

  'The internal 32.768 KHz Oscillator is used for calibration

Osc_dfllctrl = &B00000000

'Enable DFLL and autocalibration                                   
Set Dfllrc32m_ctrl.0                                      

 

   Additional hint from ATMEL for some chip revisions:

"....Both DFLLs and both oscillators has to be enabled for one to work

In order to use the automatic runtime calibration for the 2 MHz or the 32 MHz internal oscillators,

the DFLL for both oscillators and both oscillators has to be enabled for one to work.

Problem fix/Workarund

Enabled both DFLLs and oscillators when using automatic runtime calibration for one of the

internal oscillators....."

 

 

Q: How many Flash and EEPROM Write/Erase Cycles can be done with ATXMEGA ?

A: One write cycle consists of erasing a sector, followed by programming the same sector. You can find the maximum         numbers for an ATXMEGA128A1 here:

 

XMEGA Flash and EEPROM Write/Erase Cycles:

 

For ATxmega128A1 devices

 

Flash:

25°C - 10K Write/Erase cycles

85°C - 10KWrite/Erase cycles

 

EEPROM:

25°C 80K- Write/Erase cycles

85°C 30K- Write/Erase cycles

 

 

 

See also

CONFIG ADCX



Languages   English Deutsch  
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language