SPI Initialization on UC3B (no ASF)

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

Hello,

 

how do I initialize the SPI module on the UC3B without using the ASF? I found already found the topic here, but it doesen't work.

 

My code so far:

 


void SPI_Transmit()
{
    data = 0b00000001;          //dummy data
    AVR32_SPI.TDR.td = data;        //write data to the register
    while(!AVR32_SPI.SR.tdre)   //wait for buffer to be cleared
   {
	;
   }
}

int main (void)
{
    //clock setup

    AVR32_SPI.MR.mstr = 1;          //master mode
    AVR32_SPI.MR.pcs = 0b0111;  //periphal chip select
    AVR32_SPI.CSR0.scbr = 60;   //setting clockrate to 1 MHz
    AVR32_SPI.CR.spien = 1;     //Enable SPI
}

So, a pretty basic setup with SPI mode 0 and a SCK frequency of 1 MHz. But I don't see a clock signal on PA15 and the loop is never left by the program. Can someone help please smiley

Last Edited: Thu. Aug 10, 2017 - 09:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have configured, or are selecting, the wrong CSRn (Chip Select Register n)
MR.pcs = 0b0111 will use the configuration in CSR3.

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

Yup, got it. I changed it to AVR32_SPI.MR.ps = 1; think, that links it to the correct NCPS. But I got it working smiley You are very experienced in using the AVR32 without the ASF, aren't you?