The file avr/io.h contains definitions for registers that are available only on AVR architecture. If your project needs that include it means that you're using some feature available only on AVR hardware (and should be rewritten to use an equivalent SAM3X feature if you want to make it run on the Due).

One check that you can do is:

remove the #include <avr/io.h> from your biggest project, try to compile it for Mega, and look where it fails: these are the places that needs to be ported.

The call to avr/io.h was shown in the compiler error statement as coming from line 25 in twi.c. I added my work-around using the __SAM3X8E__ trick just assuming that sam/pio.h was the equivalent. However, the trick partially worked but sam/pio.h was not found. There are going to be a lot of hardware discrepancies where AVR calls don't work. Since I don't know what the Due equivalent will be, I'll just have to wait until someone else sorts this problem out satisfactorily. There is also a problem with paths in the IDE. When I supply the absolute path to a .H file, it still says it can't find it. Maybe a sketch won't work because it's AVR specific but it should at least find it. All of the #include errors are coming from within included libraries and not my sketch. Some of the substitute files for the Due haven't been created yet so I'm at a stand-still. I'll continue with the Mega and watch the forum for future progress.

I understand, but my point was that the avr/io.h equivalent for ARM doesn't exist and its not going to exist. You'll never find a "sam/pio.h" that works as a drop-in replacement for avr/io.h, because it can't be done.

The call to avr/io.h was shown in the compiler error statement as coming from line 25 in twi.c.

This is strange because the Wire library is one of the first library that was ported to Due, and I saw many reports from users that used it successfully. Are you using the Wire library found in arduino-1.5.1?

My V1.5.1r2 has two copies in the unzipped folder. One is in avr/libraries and the other is in sam/libraries. Both are dated 11/23/12. There is also an original in Documents/Arduino/libraries. I assume the compiler knows which one to use since I've told it to compile for the Due. The same sketch works if I select the Mega board. When I use a more complete path to Wire.h it says file or folder not found.

C:\Users\xxxx\Documents\Arduino\libraries\Wire\utility\twi.c:25: fatal error: avr/io.h: No such file or directory

The IDE prioritize the libraries found in {sketchbook_folder}\libraries. Try to move the Wire folder in sketchbook elsewhere, and the IDE should find the correct library (the one inside sam/libraries).

Moving the Wire library from the sketch folder to some other place, eliminates the avr/io.h error. The sketch still compiles when selecting the Mega. However, now I get another error about a missing item, square. Including math.h does not solve the problem. There is still a path problem when selecting the Due.

C:\Users\xxxxx\Documents\Arduino\libraries\PlainFFT\PlainFFT.cpp:143: error: 'square' was not declared in this scope

I've also got this problem, using Arduino 1.5.6.r2 trying to use the wire library with a Due board I get the C:\Users\xxxx\Documents\Arduino\libraries\Wire\utility\twi.c:25: fatal error: avr/io.h: No such file or directoryerror.

Yet, other people have reported that they can use the wire i2c protocol with a due board. I have noticed that those who resolved the problem were using Ubuntu or some flavor of linux i'm Windows user. Currently i am running this on my laptop running Windows 7.

So far-using Windows 7-the Wire library for SAM runs OK in my DUE (both controllers TWI0 and TWI1). The twi.c file you mention belongs to AVR. That's why is linked with avr/io.h. I know it because the AVR TWI is located under a utility folder unlike the SAM TWI which is under \libsam\source. This happens after import the Wire library using IDE 1.0.X.Solution: Close your IDE 1.5.X, delete the Wire folder from your ...\Arduino\libraries\, open again yout IDE 1.5.X and run your sketch. Regards!

EDIT: If you need to use the AVR Wire library, just run your sketch (you don't need to import the library). This works for me with 1.04 and newer.

Palliser - Thanks, I read to delete or move, the directory, which i did and it didn't find the wire.h at all. But, now i realize i had about 4-5 ide-sketches open, so closing one didn't release the library. Closed them all and reopened - finally it is now using the due library. You would think the arduino programmers would have taken care of this sometime back as i see this is an old and on-going issue with trying to work with the due (and now Gallileo - people report the same prob).