No SCKs on SPI?

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

I am trying to use the SPIC on PORTC on an xmega32a4u. I have the SPI channel configured as a master. To send data, I chip-select my slave device, write a data byte to the SPI.DATA register, and then wait for the SPI.STATUS register interrupt flag to set.

When I probe the SCK line during transfers, it only strobes high and low once as opposed to continuously pulsing. I have set up the xmega to utilize the internal 32MHz oscillator and have confirmed that the peripheral clock is running at the expected frequency.

Are there any other parameters I may have to configure to run the SPI properly?

Thanks.

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

Hmm. Doesn't sound quite right. When you put a byte out, the sck should go 8 times. Here's the code I use:

/* Defines needed to make this work
   Usually defined in Config.h

   #define SPIPort PORTC
   #define SPIMO   7
   #define SPIMI   6
   #define SPISC   5
   #define SPISS   4

   */

uint8_t SPIDir = 0 ;

void spiopen(void)
{
	SPIDir = SPIPort.DIR ;
	SPIPort.DIRCLR = (1<<SPIMI);
	SPIPort.DIRSET = (1<<SPIMO) | (1<<SPISC) | (1<<SPISS) ; // Make sure slave select is an output
	SPIC.CTRL = SPI_ENABLE_bm | SPI_MASTER_bm | SPI_MODE_0_gc | SPI_PRESCALER_DIV64_gc;
}



void spiclose(void)
{
	SPIC.CTRL = 0;
	SPIPort.DIR = SPIDir ;
	//SPIPort.DIRSET = (1<<SPIMI);
}

uint8_t spi(uint8_t val)
{
	SPIC.DATA = val ;
	while(!(SPIC.STATUS & (1<<7)));
	return SPIC.DATA;
}

I use spiopen to prepare the port for spi, and spiclose to return the port to other uses because one device I used the 4 spi pins for other io too. Rather silly of me.

The largest known prime number: 282589933-1

Without adult supervision.

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

Does the Xmega suffer from the same SPISS gotcha as the tiny/mega did?

(that is that if the SS pin is left floating and goes low the SPI switches from master to slave so writing the data register no longer triggers 8 SCKs)

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

It might! It might not show here, but be sure the SS pin is configured for an output.

The largest known prime number: 282589933-1

Without adult supervision.

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

Just ran into a similar problem tonight. I think Torby's code has the answer. You need to set both the clock and data pins as outputs via PORTC.DIRSET.

Don