Getting OX2 test app to build in AVRStudio

Sorry I’m such a noob here but I’m struggling to get the OX2 test app to load and build under AVRStudio. I’ve downloaded and installed winavr along with AVRStudio. I’ve loaded the test application OX2m644_test into AVRStudio. I’ve also downloaded the lcd and spi libraries but I’m getting a number of errors when I try to build that aren’t clear to me. First off, for better or worse, I put the lcd.h/.c and spi.h/.c files in the same directory as the main apps .c file.

When I try to build it - following is one of several errors that are more less the same.
…/SPI.c:65: error: ‘SPCR0’ undeclared (first use in this function)

this error indicates that PSCRO is never properly declared which to the best of my ability is true - its not nor are any of about 10 other values referenced in the spi.c file - but since this code is obviously running on the OX2 I’ve got I’d think this is an error in my configuration as opposed to a missing declaration in the code.

Thanks for any help!

regards,

wenger

here is the complete build output:
Build started 5.8.2007 at 10:36:19
avr-gcc.exe -I"C:\projects\robotics\pololu\ox2m644_test…\orangutanX2" -mmcu=atmega644 -Wall -gdwarf-2 -DF_CPU=20000000UL -O0 -fsigned-char -MD -MP -MT SPI.o -MF dep/SPI.o.d -c …/SPI.c
…/SPI.c: In function ‘SPIInit’:
…/SPI.c:65: error: ‘SPCR0’ undeclared (first use in this function)
…/SPI.c:65: error: (Each undeclared identifier is reported only once
…/SPI.c:65: error: for each function it appears in.)
…/SPI.c:65: error: ‘SPE0’ undeclared (first use in this function)
…/SPI.c:65: error: ‘MSTR0’ undeclared (first use in this function)
…/SPI.c:65: error: ‘SPR00’ undeclared (first use in this function)
…/SPI.c:66: error: ‘SPSR0’ undeclared (first use in this function)
…/SPI.c: In function ‘SPITransmit’:
…/SPI.c:78: error: ‘SPSR0’ undeclared (first use in this function)
…/SPI.c:78: error: ‘SPIF0’ undeclared (first use in this function)
…/SPI.c:79: error: ‘SPDR0’ undeclared (first use in this function)
…/SPI.c: In function ‘SPIReceive’:
…/SPI.c:88: error: ‘SPSR0’ undeclared (first use in this function)
…/SPI.c:88: error: ‘SPIF0’ undeclared (first use in this function)
…/SPI.c:91: error: ‘SPDR0’ undeclared (first use in this function)
…/SPI.c:98: warning: control reaches end of non-void function
…/SPI.c: In function ‘fastSerialRead’:
…/SPI.c:609: error: ‘SPSR0’ undeclared (first use in this function)
…/SPI.c:609: error: ‘SPIF0’ undeclared (first use in this function)
…/SPI.c:614: error: ‘SPDR0’ undeclared (first use in this function)
make: *** [SPI.o] Error 1
Build failed with 16 errors and 1 warnings…

Hello.

The first thing that comes to mind is that perhaps you somehow have your AVR Studio project configured to use the wrong device. You can check this by going to the Project menu and selecting Configuration Options. Make sure the device is listed as atmega644. Although, looking at your compile flags, it seems that you do have mmcu set as atmega644…

SPI.c includes the file <avr/io.h> (/WinAVR/avr/include/avr/io.h). This file should include <avr/iom644.h> if the device flag is set for the atmega644, which in turn includes <avr/iomxx4.h>. This last file should define the registers SPCR0, SPE0, MSTR0, etc. If your device is correctly set as “atmega644”, I would recommend you take a look at <avr/iomxx4.h> to see what it’s defining. Perhaps you have an older or newer version that uses slightly different definitions.

If you have your device set wrong (such as to atmega168), you would instead be including different files (such as <avr/iomx8.h>, which defines those same registers as SPCR, SPE, MSTR, etc). If all else fails, see if the compiler complains if you replace in SPI.c all the references to “SPCR0” with “SPCR”.

- Ben

Hey Ben,

Thanks for the post - that’s at least given some directions in which rocks to look under.

I’ve verified that the 644 is the selected MCU - I didn’t change it since that was what was already there - but it was good to verify just the same.

The iom644.h file has almost nothing in it but it does reference another file iomxx4.h does have most of these things defined. But here is the interesting part - iomxx4.h does have SPCR defined but not SPCR0 (nor any of the sub SPCR values). The same is true with almost all of the other values from my original post - e.g. SPE is defined but not SPE0, and so on.

here is the section of the header where these values are defined in iomxx4.h:
#define SPCR _SFR_IO8(0x2C)
#define SPIE 7
#define SPE 6
#define DORD 5
#define MSTR 4
#define CPOL 3
#define CPHA 2
#define SPR1 1
#define SPR0 0

As I mentioned previously I just downloaded the latest version of winavr - could this have been changed?

Any other ideas? And I take it no one else is having this issue?

Thanks,

wenger

btw, I can compile the main test(.c) file if I just compile a single file - I think this is happening by using the prebuild .o files (lcd.o and spi.o) in the dep directory - but it makes me a little uncomfortable that things aren’t building correctly.

Ben,

Ok - I had to read your post more carefully and closely - my bad.

I did make a number of changes to spi.c as well as to spi.h to change the references from SPCR0 to SPCR along with several other similar changes which are more less obvious from my last post - but after making these changes it does appear I can get the spi.c to compile properly.

Just thought I’d post this up here so if anyone else runs into this maybe this will help.

Thanks for the help.

wenger

I did some checking; apparently the most recent version of WinAVR changed iomxx4.h. I’ll update SPI.c and SPI.h so they handle this newest version of WinAVR more gracefully. Thanks for bringing this problem to my attention.

  • Ben

Update: The SPI command wrappers hosted on the Orangutan X2 page should now work with the latest version of WinAVR. I added some #defines to SPI.h so that it will continue to work with older versions of WinAVR.