Using SPI on AT32UC3C

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

Hi,

I am a beginner with embedded system. Today, I learned some tutorial about SPI of AVR board. However, when I tried to mimic the same thing, I got the problem with the library. Can anyone help me please ? Or a tutorial is extremely good. I tried to search but it seems like there is no.

 

#ifndef F_CPU
#define F_CPU 16000000UL
#endif
 
#include <avr32/io.h>
#include <interrupt.h>
#include <util/delay.h>
#include "lcd.h"
 
#define ACK 0x7E
 
void spi_init_slave (void)
{
    DDRB=(1<<6);                                  //MISO as OUTPUT
    SPCR=(1<<SPE);                                //Enable SPI
}
 
//Function to send and receive data
unsigned char spi_tranceiver (unsigned char data)
{
    SPDR = data;                                  //Load data into buffer
    while(!(SPSR & (1<<SPIF) ));                  //Wait until transmission complete
    return(SPDR);                                 //Return received data
}
 
int main(void)
{
    lcd_init(LCD_DISP_ON_CURSOR_BLINK);           //Initialize LCD
    spi_init_slave();                             //Initialize slave SPI
    unsigned char data, buffer[10];
    DDRA  = 0x00;                                 //Initialize PORTA as INPUT
    PORTA = 0xFF;                                 //Enable Pull-Up Resistors
    while(1)
    {
        lcd_clrscr();                             //LCD Clear screen
        lcd_home();                               //LCD move cursor to home
        lcd_puts("Testing");
        lcd_gotoxy(0,1);
        data = spi_tranceiver(ACK);               //Receive data, send ACK
        itoa(data, buffer, 10);                   //Convert integer into string
        lcd_puts(buffer);                         //Display received data
        _delay_ms(20);                            //Wait
    }
}

 

Error:

 

 

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

Those error messages are usually a result of not having the include directories set up for you project.  Basically, your compiler simply can't find the files.

How you set that up will depend very much on the IDE you're using (and I can tell you're using one from the image of the error, but not which one).

On Eclipse, you set include files by right-clicking on the project and selecting "Properties".  Then go to "C/C++ Build"->"Settings"->"MCU GCC Compiler"->"Includes" and add the directories where those files can be found.

On Atmel Studio 6.2 (and I think 7.0 but I don't have it running right now), right-click the project, select "Properties" and go to "Toolchain"->"AVR32/GNU C Compiler"->"Directories" and/or "Toolchain"->"AVR32/GNU C++ Compiler"->"Directories" and add the folders there.

(Note that Atmel Studio differentiates between C and C++)

 

Good luck.

Geoff

 

--
Geoff Field
Professional Geek, Amateur Stage Levelling Gauge

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

Hi,

Thank you for your reply. However, I am in the situation that I don't know if I am using the right method for configuring SPI on AVR32 uc3 or the libraries are not connected. 

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

I'm not sure about your version of the SPI driver - it looks like you're setting up a basic slave SPI module, which requires a master module somewhere to drive its clock signal.

 

Having said that, I'm not familiar with those specific header files and the interfaces contained therein.

 

My point was not that you have a configuration problem (you might or might not).  Instead, you have a compilation problem.  Until your compiler can read the files, you won't be able to tell whether there are any other problems.

 

Regards,

 

Geoff

--
Geoff Field
Professional Geek, Amateur Stage Levelling Gauge

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

1) That code is for the AVR8 architecture., the AVR32 architecture is very different., you will need to refer to the datasheet to understand what is happening and what the names mean.

2) If you are using AVR Studio you can create a blank project and then use the ASF wizard to add the SPI and GPIO drivers, then use those ASF routines to configure/use the GPIO and SPI modules.

3) AVR Studio has some example projects which can be examined/adapted/rewritten to suit your needs.

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

Hi Mikech,

 

If you look at the OP's actual error reports, you will see they have nothing to do with the architecture.  They're classic #include file path issues.

 

Having said that, you are most certainly right.  I'm currently using the same micro (an AVR32 UC3 variant) as the OP and none of the APIs I've seen bear much resemblance to the OP's code.

Your advice on using the ASF and the supplied example code is good. (What else should I expect? ;-)

 

Regards,

 

Geoff

--
Geoff Field
Professional Geek, Amateur Stage Levelling Gauge

Last Edited: Sun. Feb 5, 2017 - 10:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

Thank you for all of yours help. However, right now, I am in the situation that I do not have the boards with me to connect and use ASF :( Is there any other way that I can create a simple SPI or I2C project for AVR32 without connecting the boards ? Because it will come soon but not right now. I want to prepare for that.

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

trongtriet wrote:
I am a beginner with embedded system.

 

Stage Leveller wrote:
If you look at the OP's actual error reports ... They're classic #include file path issues.

Indeed.

 

Which suggests that the OP is not just a beginner with embedded systems, but a beginner with 'C' programming in general.

 

Common advice here is that it may be easier to learn 'C' programming on a PC first, then add the extra complications of small embedded systems once that foundation is established ...

 

Here are some 'C' starting references & resources: http://blog.antronics.co.uk/2011...

 

And some Getting Started tips for microcontrollers: http://www.avrfreaks.net/comment...

 

A basic understanding of electronics is necessary; here's a good beginner's site: https://electronicsclub.info/

 

And, of course, there's the tutorials section of this very forum: http://www.avrfreaks.net/forums/...

 

Be sure to check-out what's available on the 'Documents' tab of the chip's Product Page; eg, http://www.atmel.com/devices/AT3...

 

Lots of stuff on Atmel's YouTube channel: https://www.youtube.com/user/Atm...

 

 

#GettingStarted #Beginner

Last Edited: Sun. Feb 12, 2017 - 01:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

trongtriet wrote:
I do not have the boards with me to connect and use ASF

You don't need any board connected to use ASF!

 

 a simple SPI or I2C project for AVR32 

For a beginner, these aren't really "simple" projects to start with.

 

These are the simple steps you need first: http://www.avrfreaks.net/comment...

 

 

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

Hi,

Thanks you very much. I just replied the message and I saw your comment. I will start to learn from that.

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

awneil wrote:
Atmel's (sic?) YouTube channel: https://www.youtube.com/user/Atm... 

 

Although it still has "Atmel" in the URL, it's now called the "Microchip Makes" channel ...

 

http://www.avrfreaks.net/forum/b...

 

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

Hi,

I tried to use ASF and include all drivers that added before. However, when i run the program. It still does not work. I tried to find some tutorial from the forum as well as some sample codes, but it is still so confusing. Can you please give me one, just one that I can read and run :( I am using AT32UC3L family. :(

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

trongtriet wrote:
I tried to find some tutorial from the forum as well as some sample codes,

That's always going to be a problem with AVR32: it is (or, rather, was?) a "niche" product - so there is simply not the community around it to provide loads of tutorials, examples, etc.

 

And it's not going to get any beetter for AVR32 - as it is now considered "legacy" or "end-of-life":

 

http://www.avrfreaks.net/forum/a...

 

http://www.avrfreaks.net/forum/u...

 

http://www.avrfreaks.net/comment...

 

http://www.avrfreaks.net/comment...

 

http://www.avrfreaks.net/comment...

 

etc, etc

 

trongtriet wrote:
I am a beginner with embedded system.

it is still so confusing

 

Probably learning on AVR8 would be better - it's a simpler chip, with a great community and loads of support ...

 

#legacy #eol #EndOfLife

Last Edited: Tue. Feb 14, 2017 - 09:32 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

It is quite sad to hear. unfortunately, my school project requires that kind of board :( oh dear.

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

Well, if it's a school project then you should be going to your teachers for help with it!

 

You might also want to point out to them that the AVR32  may not be a great choice ...

 

(or maybe it's deliberate: they know there's not much on the interwebs, and they want to force you to have to do it yourself...)

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

Hi,

I just got the board *UC3-A3 xplained*. However, I was so noob that I cannot program with this. Can you show me how can I connect the board with the PC ? I tried the one "press the button and connect through usb" but it seems like atmel studio does not recognize the board ? Please.