Basic question about I2c on SAM3X8E (TWI)

Hello everyone

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.

Thanks in advance

Does you DUE support the standard Arduino "Wire" library? That abstracts TWI into a more user-friendly API.

Thanks for your quick answer,

If I'm not mistaken, the wire library is made for arduino, and so would not work for C?

I would like to make this code in C to be able to progress in this language, so I would like to avoid going with arduino...

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.

Ok, i didn't know that! I will try to use the wire library then. I'll tell you the difference in a few days!

Thanks! :smiley:

Hello

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)

Does anyone have an idea to help me?

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.

Yeah, i must use it..

Thanks for your advice, i'll go post it there!

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.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.