MEGA3208 (0-series) SPI Gotcha

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

I've just spent an hour scratching my head as to why I couldn't get SPI Slave working on an ATMEGA3208

 

The 0-Series manual states this for the SPI registers:

Reserved shown for register 0x02

 

But the register at offset 0x02 is not reserved - it is the INTCTRL register, and you need to enable the individual register bits to enable the interrupts!

It is defined in iom3208.h as SPI0_INTCTRL

 

I finally found this error/omission in the manual by creating an Atmel Start project for the XMEGA3208 and enabling SPI as slave, then comparing the setup code to mine.

 

 

SpiderKenny
@spiderelectron
www.spider-e.com

 

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

This is the data sheet that I own.

 

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

I must have an old datasheet!

... skulks off slowly, hangs head in shame....

SpiderKenny
@spiderelectron
www.spider-e.com

 

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

New datasheet downloaded. Old datasheet sent for recycling!

Thanks @kabasan!

SpiderKenny
@spiderelectron
www.spider-e.com

 

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

It was good to be helpful.

Last Edited: Wed. Jun 26, 2019 - 03:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BTW if you ever doubt the datasheet for these new AVRs have a look in the relevant ADTF - it's much "closer" to the chip and much more likely to convey an accurate description of the layout of things.

 

PS in this case the 1.3.300 pack for Atmega3208 has this in ATmega3208.atdf:

 

    <module caption="Serial Peripheral Interface" id="I2107" name="SPI">
      <register-group caption="Serial Peripheral Interface" name="SPI" size="0x8">
        <register caption="Control A" initval="0x00" name="CTRLA" offset="0x0" rw="RW" size="1">
          <bitfield caption="Enable Double Speed" mask="0x10" name="CLK2X" rw="RW"/>
          <bitfield caption="Data Order Setting" mask="0x40" name="DORD" rw="RW"/>
          <bitfield caption="Enable Module" mask="0x1" name="ENABLE" rw="RW"/>
          <bitfield caption="Master Operation Enable" mask="0x20" name="MASTER" rw="RW"/>
          <bitfield caption="Prescaler" mask="0x6" name="PRESC" rw="RW" values="SPI_PRESC"/>
        </register>
        <register caption="Control B" initval="0x00" name="CTRLB" offset="0x1" rw="RW" size="1">
          <bitfield caption="Buffer Mode Enable" mask="0x80" name="BUFEN" rw="RW"/>
          <bitfield caption="Buffer Write Mode" mask="0x40" name="BUFWR" rw="RW"/>
          <bitfield caption="SPI Mode" mask="0x3" name="MODE" rw="RW" values="SPI_MODE"/>
          <bitfield caption="Slave Select Disable" mask="0x4" name="SSD" rw="RW"/>
        </register>
        <register caption="Data" name="DATA" offset="0x4" rw="RW" size="1"/>
        <register caption="Interrupt Control" name="INTCTRL" offset="0x2" rw="RW" size="1">
          <bitfield caption="Data Register Empty Interrupt Enable" mask="0x20" name="DREIE" rw="RW"/>
          <bitfield caption="Interrupt Enable" mask="0x1" name="IE" rw="RW"/>
          <bitfield caption="Receive Complete Interrupt Enable" mask="0x80" name="RXCIE" rw="RW"/>
          <bitfield caption="Slave Select Trigger Interrupt Enable" mask="0x10" name="SSIE" rw="RW"/>
          <bitfield caption="Transfer Complete Interrupt Enable" mask="0x40" name="TXCIE" rw="RW"/>
        </register>
        <register caption="Interrupt Flags" initval="0x00" name="INTFLAGS" offset="0x3" rw="RW" size="1">
          <mode name="BUFFERED">
            <bitfield caption="Buffer Overflow" mask="0x1" name="BUFOVF" rw="RW"/>
            <bitfield caption="Data Register Empty Interrupt Flag" mask="0x20" name="DREIF" rw="RW"/>
            <bitfield caption="Receive Complete Interrupt Flag" mask="0x80" name="RXCIF" rw="RW"/>
            <bitfield caption="Slave Select Trigger Interrupt Flag" mask="0x10" name="SSIF" rw="RW"/>
            <bitfield caption="Transfer Complete Interrupt Flag" mask="0x40" name="TXCIF" rw="RW"/>
          </mode>
          <mode name="DEFAULT">
            <bitfield caption="Interrupt Flag" mask="0x80" name="IF" rw="RW"/>
            <bitfield caption="Write Collision" mask="0x40" name="WRCOL" rw="RW"/>
          </mode>
        </register>
      </register-group>
      <value-group caption="Prescaler select" name="SPI_PRESC">
        <value caption="System Clock / 4" name="DIV4" value="0x00"/>
        <value caption="System Clock / 16" name="DIV16" value="0x01"/>
        <value caption="System Clock / 64" name="DIV64" value="0x02"/>
        <value caption="System Clock / 128" name="DIV128" value="0x03"/>
      </value-group>
      <value-group caption="SPI Mode select" name="SPI_MODE">
        <value caption="SPI Mode 0" name="0" value="0x00"/>
        <value caption="SPI Mode 1" name="1" value="0x01"/>
        <value caption="SPI Mode 2" name="2" value="0x02"/>
        <value caption="SPI Mode 3" name="3" value="0x03"/>
      </value-group>
    </module>

Clearly this mentions INTCTRL at offset 0x02.

 

PPS can't help noticing that Kabasan's picture of the "latest" datasheet shows two INTFLAGS registers both at offset 0x03 - Quod Erat Demonstrandum !

 

Later still...  Ah OK, from the XML it is two interpretations of the same thing depending on "BUFFERED" or "DEFAULT" mode. I see. (I wasn't getting that distinction from the PDF but it's more obvious in the XML)

Last Edited: Wed. Jun 26, 2019 - 03:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How do you find the atdf files? Not a "Windows Person".

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

ka7ehk wrote:

How do you find the atdf files? Not a "Windows Person".

 

Jim

 

Well, on windows, in the same directory where the AS7 or MPLAB-X executable lives, there is a subdirectory called "packs". Dive in and you will eventually reach the atdf directory, where the atdf files are.

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

Atmel Packs

Microchip Packs Repository

[select 'Download' for ATmega]

it's a zip file, unzip, directory atdf, file ATmega3208.atdf

 

"Dare to be naïve." - Buckminster Fuller

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

Thanks

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Indeed it is C:\Program Files (x86)\Atmel\Studio\7.0\packs\atmel\  by default. Beneath that are various directories:

 Directory of C:\Program Files (x86)\Atmel\Studio\7.0\packs\atmel

24/09/2018  13:00    <DIR>          .
24/09/2018  13:00    <DIR>          ..
24/09/2018  12:58    <DIR>          ATautomotive_DFP
19/02/2019  15:28    <DIR>          ATmega_DFP
19/02/2019  15:28    <DIR>          ATtiny_DFP
24/09/2018  13:00    <DIR>          SAM3A_DFP
etc etc

In any directory like ATmega_DFP you may find that you have more than one sub-directory:

 Directory of C:\Program Files (x86)\Atmel\Studio\7.0\packs\atmel\ATmega_DFP

19/02/2019  15:28    <DIR>          .
19/02/2019  15:28    <DIR>          ..
24/09/2018  12:58    <DIR>          1.2.209
19/02/2019  15:29    <DIR>          1.3.300
               0 File(s)              0 bytes
               4 Dir(s)  275,132,366,848 bytes free

These are the different issue of the packs - usually study the highest numbered one (1.3.300 in this case).