Pages: [1]   Go Down
Author Topic: twimaster.cpp for I2C (to get a MLX90614 to work)  (Read 1934 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

To start: I'm a newbie, still trying to find out how the Arduino Due works.

At this moment I'm trying to get a MLX90614-BAA communicating with my Due board. The problem already starts during the compiling of the project. First I was having problems to find the include files, but that has been solved (so far smiley-razz).

In Arduino 1.5.1r2 I still get the following errors:
C:\Users\kazimier\Documents\Arduino\libraries\I2Cmaster\I2C.cpp: In member function 'void I2C::begin()':
C:\Users\kazimier\Documents\Arduino\libraries\I2Cmaster\I2C.cpp:91: error: 'PORTD' was not declared in this scope
C:\Users\kazimier\Documents\Arduino\libraries\I2Cmaster\I2C.cpp:91: error: '_SFR_BYTE' was not declared in this scope
etc.

I can't figure out what goes wrong. I've articles about adjusting twimaster.cpp (or do I need to adjust the I2C.cpp)?  

Thanks in advance!
Jelle
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I get the same error (as you can see below) when communicating with accelerometer MMA8453Q using the library and the examples in: http://n0m1.com/2012/02/12/shake-rattle-roll-the-mma8453q-arduino/

...\arduino-1.5.1r2\libraries\I2C\I2C.cpp: In member function 'void I2C::begin()':
...\arduino-1.5.1r2\libraries\I2C\I2C.cpp:91: error: 'PORTD' was not declared in this scope
...\arduino-1.5.1r2\libraries\I2C\I2C.cpp:91: error: '_SFR_BYTE' was not declared in this scope
...\arduino-1.5.1r2\libraries\I2C\I2C.cpp:91: error: '_BV' was not declared in this scope
...\arduino-1.5.1r2\libraries\I2C\I2C.cpp:95: error: 'TWSR' was not declared in this scope
...\arduino-1.5.1r2\libraries\I2C\I2C.cpp:95: error: 'TWPS0' was not declared in this scope

Can somebody help with this?
Thanks in advance for your help!!
Logged

US
Offline Offline
Full Member
***
Karma: 4
Posts: 183
Electronics are the new Legos
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Easy enough.  The library appears to be written for the AVR Arduinos, accessing ports directly rather than making library calls.  That code will not work with the Due as it is a different architecture.  You'll need to figure out what that code is trying to do and recode it.

This is common in many libraries as people took shortcuts to get more horsepower out of the smaller units.  It makes getting the hardware working on Due a painful process.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, here a working tested sketch found in the forum.
Luca

http://arduino.cc/forum/index.php/topic,137607.msg1101421.html#msg1101421

* MLX90614_Direct_Access.ino (3.41 KB - downloaded 21 times.)
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your answers!
I looked into the discussion that veneridesign suggested and there they point out that there is an error in the wire library. I am trying to fix this problem to use the offical wire library but I am not able to check if the changes (in red color) I've made work in the Wire.cpp file. Can someone check if they work??

static volatile uint8_t twi_sendStop;
uint8_t TwoWire::endTransmission(uint8_t sendStop) {
   // transmit buffer (blocking)
   twi_sendStop = sendStop;
   TWI_StartWrite(twi, txAddress, 0, 0, txBuffer[0]);
   TWI_WaitByteSent(twi, XMIT_TIMEOUT);
   int sent = 1;
   while (sent < txBufferLength) {
      TWI_WriteByte(twi, txBuffer[sent++]);
      TWI_WaitByteSent(twi, XMIT_TIMEOUT);
   }
   if (twi_sendStop==true){
      TWI_Stop( twi);
   }
   else{
   }

   TWI_WaitTransferComplete(twi, XMIT_TIMEOUT);

   // empty buffer
   txBufferLength = 0;

   status = MASTER_IDLE;
   return sent;
}

Additionally, the sensor uses the following protocol (see attached image). Do you know how can I get this sequence with the standard functions of the library (begin, write, read, request answer...)?

Thanks for all the help!!!



* byte_read.PNG (6.78 KB, 670x87 - viewed 36 times.)
Logged

White River Junction, Vermont USA
Offline Offline
Full Member
***
Karma: 5
Posts: 106
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

See:
http://arduino.cc/forum/index.php/topic,137607.0.html
(I2C Repeated Start)

-Chris
Logged

Pages: [1]   Go Up
Jump to: