I'm trying to learn how to link a DUE arduino board ( with a SAM3X8E) and a temperature sensor by I2C in C on atmel Studio 7.
Until now I could only find a library adapted to the SAM architecture (TWI), but I didn't manage to understand what parameters I had to give to the functions to be able to initialize the i2c bus, in particular the "p_twi" pointer.
Could someone explain me what kind of variable the function expects? Or give me some basic code so I can understand how it works.
It seems like you're trying to solve a problem that doesn't exist.
The entire Arduino ecosystem is based on C++ which is (more or less) a super-set of C. If you prefer, you can avoid using the C++ OOP constructs (which most newbies do) and your code will look pretty much like C.
So I tried to import the Wire library in my project.
I started by trying to import it directly into my main.c using the externs method:
#ifdef __cplusplus
extern "C"{
#endif
I got a lot of errors like unknown c++ classes or missing characters. I thought that these errors came from the conversion from C++ to C, so I tried another method:
I recreated my project in C++ to import directly the library and a simple code, but again, I got a compile error saying that my library is not found. (I specified the access path two lines above)
I guess I missed that on first reading. Arduino libraries (like Wire) can probably only be used if you have the entire Arduino support environment. If you insist on using the Atmel tool, your question might be better answered in an Atmel forum.
To make extensive progress in C/C++ Language, Arduino UNO and the IDE constitute what is termed as an Excellent Platform for learning both Microcontroller Hardware and C/C++ Language.
The IDE contains a C/C++ Compiler to convert source codes into binary codes, a Communication Interface to download the binary codes (as Intel-Hex Formatted File) into the UNO board, a Programming Interface to burn the binary codes into the flash of the MCU, and a Serial Monitor to see the results of the program (the sketch in Arduino vocabulary).
DUE contains an advanced 32-bit MCU of type SAM3X8E which can be learnt later after being conversant with the UNO which contains an 8-bit MCU of type ATmega328P.