SPID STATUS not working. Help please.

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

Hi Guys, I haven't used my Xmega256D3 in a while and decided to write a comms program in assembler via SPID as the Master and another Xmega256D3 as the slave.

 

Every time I read the IF bit in SPID_STATUS it always reads 0 so my program halts at that point. Have I left something out in my code? Here is my init code.

  LDI R16,16+32+128   ;MOSI, SS, SCK OUTPUT. MISO INPUT.
  STS PORTD_DIR,R16
  LDI R17,64+16+128   ;ENABLE SPI D AS MASTER + ENABLE + X2 SPEED.
  STS SPID_CTRL,R17
  LDI R17,0     	;SPI INTERRUPTS OFF
  STS SPID_INTCTRL,R17

SPID_STATUS_READY:
  LDS R16,SPID_STATUS   ;CHECK IF SPID IS READY.
  SBRS R16,7
  RJMP SPID_STATUS_READY

  LDI R16,255
  STS PORTE_DIR,R16

LOOP1: LDI R16,POWER_LED           ;FLASH A LED ON PORTE0
  STS PORTE_OUTSET,R16
  RCALL DELAY_LONG
  LDI R16,POWER_LED
  STS PORTE_OUTCLR,R16
  RCALL DELAY_LONG
  RJMP LOOP1

The program just waits for the IF bit in the STATUS register to be set but it looks like the bit is always clear and I have no idea why.

Have I left out something in the SPI INIT register? Any help here would be muchly appreciated.

Thanks guys for your help.

Pete

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  LDI R16,16+32+128   ;MOSI, SS, SCK OUTPUT. MISO INPUT.

Who is going to try and look at that? Please use bit names if you want any help from anybody. wink

 

Of course your slave code is different???

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

John, aren't there any Assembler coders anymore? Are you guys all C programmers now?

 

The code makes sense to me and if I can understand it then experienced Xmega assembler coders will too with ease. 

 

If you can't understand it please don't reply. The comments after the mnemonics explains the bits 16+32+128 is. Bits 4,5 and 7. SPI D SS, MOSI and SCK to OUTPUT. MISO to input.

 

Does anyone else have the expertise to help with my Xmega problem?

 

Pete.

 

Last Edited: Tue. Aug 9, 2016 - 10:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John, aren't there any Assembler coders anymore?

Yes, my last project is about 8K in assembler but I have no idea what those numbers mean unless I waste some time looking at the data sheet.

the bits 16+32+128 is. Bits 4,5 and 7. SPI D SS, MOSI and SCK to OUTPUT.

Then why not put the bit NAMES as per the data sheet in your code? wink

 

ie

SBRS R16,IF (or whatever is called)

instead of


SBRS R16,7

unfortunately I have not used the Xmega SPI so can't be of much help.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

comments after the mnemonics explains the bits 16+32+128 is

Comments are not code.  The assembler can't tell if you're lying, or if you've made an error.

 

As far as I can tell, however, the device header for the Xmega256D3 has no macros for these bit names.  You'd have to define them yourself.

 

#define SCK  7
#define MISO 6
#define MOSI 5
#define SS   4
.
.
.
        ldi     r16,    (1<<SCK)|(1<<MOSI)|(1<<SS)

Self-documenting.

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Wed. Aug 10, 2016 - 03:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  LDI R17,64+16+128   ;ENABLE SPI D AS MASTER + ENABLE + X2 SPEED.
  STS SPID_CTRL,R17

For this one even if you were going to do it by bit positions don't most programmers think in hex or binary rather than decimal? At least use:

  LDI R17,0x40+0x10+0x80   ;ENABLE SPI D AS MASTER + ENABLE + X2 SPEED.
  STS SPID_CTRL,R17

which is surely preferable. Or perhaps:

  LDI R17,0b11010000   ;ENABLE SPI D AS MASTER + ENABLE + X2 SPEED.
  STS SPID_CTRL,R17

But (in the C/avr-as headers at least) there is:

/* SPI - Serial Peripheral Interface */
/* SPI.CTRL  bit masks and bit positions */
#define SPI_CLK2X_bm  0x80  /* Enable Double Speed bit mask. */
#define SPI_CLK2X_bp  7  /* Enable Double Speed bit position. */

#define SPI_ENABLE_bm  0x40  /* Enable Module bit mask. */
#define SPI_ENABLE_bp  6  /* Enable Module bit position. */

#define SPI_DORD_bm  0x20  /* Data Order Setting bit mask. */
#define SPI_DORD_bp  5  /* Data Order Setting bit position. */

#define SPI_MASTER_bm  0x10  /* Master Operation Enable bit mask. */
#define SPI_MASTER_bp  4  /* Master Operation Enable bit position. */

so much better would be:

  LDI R17,SPI_ENABLE_bm + SPI_MASTER_bm + SPI_ CLK2X_bm  ;ENABLE SPI D AS MASTER + ENABLE + X2 SPEED.
  STS SPID_CTRL,R17

(in which case you saved yourself having to type the comment as well!). I can't check now but I assume the device header for Atmel Asm 2 has similar definitions (it all comes out of the same XML file).

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

You have to put something in the SPID_data register, for it to work. Check out AVR1309 on Atmel's site under 8 bit MCUs ( Xmega ). There's really only rare cases when asm would need to be used, even then it would be only small code section(s), with C compilers being as good as they are nowadays. Life's just too short to be writing apps in asm ( To answer your question about asm programmers ).

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

Last Edited: Wed. Aug 17, 2016 - 06:15 AM