Mikromedia for xmega

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

I recently purchased a Mikromedia for xmega development system. http://www.mikroe.com/eng/products/view/688/mikromedia-for-xmega/
Since playing around with this device, a couple of things I have noticed are that all the examples provided by the company are specifically made to be compiled with their MicroC compiler. I get that they want you to use their software and pay the $250 to license it, but I use Winavr and don't particularly want to buy it. Trying to compile the code in Winavr is troublesome and I get allot of errors.

One of the examples is to utilise the accelerometer on board. This is the first piece of code that wont compile:

// TFT module connections
char TFT_DataPort at PORTK_OUT;
char TFT_DataPort_Direction at PORTK_DIR;
sbit TFT_RST at PORTJ_OUT.B1;
sbit TFT_BLED at PORTJ_OUT.B0;
sbit TFT_RS at PORTJ_OUT.B4;
sbit TFT_CS at PORTJ_OUT.B5;
sbit TFT_RD at PORTJ_OUT.B2;
sbit TFT_WR at PORTJ_OUT.B3;
sbit TFT_RST_Direction at PORTJ_DIR.B1;
sbit TFT_BLED_Direction at PORTJ_DIR.B0;
sbit TFT_RS_Direction at PORTJ_DIR.B4;
sbit TFT_CS_Direction at PORTJ_DIR.B5;
sbit TFT_RD_Direction at PORTJ_DIR.B2;
sbit TFT_WR_Direction at PORTJ_DIR.B3;

This is my first experience with Xmega and now understand how to write C code for ports / registers etc. But I need help getting this to compile.

I will attach the whole Accel folder with all the source code if anyone cares to see all if it and possibly help me out.

These are the errors that Winavr return for this snippet of code:

In file included from ACCEL_Test.c:29:
resources.h:2: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'at'
resources.h:3: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'at'
resources.h:4: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'TFT_RST'
resources.h:5: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'TFT_BLED'
resources.h:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'TFT_RS'
resources.h:7: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'TFT_CS'
resources.h:8: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'TFT_RD'
resources.h:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'TFT_WR'
resources.h:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'TFT_RST_Direction'
resources.h:11: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'TFT_BLED_Direction'
resources.h:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'TFT_RS_Direction'
resources.h:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'TFT_CS_Direction'
resources.h:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'TFT_RD_Direction'
resources.h:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'TFT_WR_Direction'
resources.h:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'char'
resources.h:219: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'char'

I figure if I can understand the differences in this code between the two compilers I can get the other examples to work too.

Attachment(s): 

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

I'd suggest you read the Bit Manipulation 101 thread in Tutorial Forum and on page 5 or 6 you will find an attachment from "danni" called sbit.h - the technique he shows in that will allow you define something very close to what they are using here. It's true that danni's file is for mega not xmega but this is really just the difference between PORTG and PORTG_OUT etc.

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

Thanks Clawson, I found sbit.h and ill read the original tutorial.

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

after looking at "danni's" sbit.h this is what i came up with compared to the original code...

#define	TFT_RST		SBIT(PORTJ_OUT, 1)
#define TFT_BLED    SBIT(PORTJ_OUT, 0)
#define TFT_RS 		SBIT(PORTJ_OUT, 4)
#define TFT_CS 		SBIT(PORTJ_OUT, 5)
#define TFT_RD 		SBIT(PORTJ_OUT, 2)
#define TFT_WR 		SBIT(PORTJ_OUT, 3)
#define TFT_RST_Direction  	SBIT(PORTJ_DIR, 1)
#define TFT_BLED_Direction 	SBIT(PORTJ_DIR, 0)
#define TFT_RS_Direction 	SBIT(PORTJ_DIR, 4)
#define TFT_CS_Direction  	SBIT(PORTJ_DIR, 5)
#define TFT_RD_Direction  	SBIT(PORTJ_DIR, 2)
#define TFT_WR_Direction 	SBIT(PORTJ_DIR, 3)

or is this completely wrong?

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

Yeah that looks like it would work. Or you could even edit sbit.h for Xmega and change all the PORTx to PORTx_OUT then your code becomes:

#define   TFT_RST      PORT_J1
#define TFT_BLED       PORT_J0
#define TFT_RS         PORT_J4
etc.

But what you've done looks like it should work. What does the compiler and the generated code say about it?

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

well it does not produce any errors, which is a good sign.
However, I'm not sure what to do with these:

char TFT_DataPort at PORTK_OUT;
char TFT_DataPort_Direction at PORTK_DIR;
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simply replace those with #define's:

#define TFT_DataPort           PORTK_OUT;
#define TFT_DataPort_Direction PORTK_DIR;