Pages: [1]   Go Down
Author Topic: I2C interface with LIS3LV02DQ  (Read 306 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 33
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been trying to get the I2C bus to work with my LIS3LV02DQ.  Using the wire library didn't work.  So I decided to take a lower level approach and use the example code from the Atmega168's datasheet.  Right now the code hangs when polling the interrupt flag.

I'm not really sure if I've even setup the Atmega correctly for I2C.  Here is what my code looks like:

void loop( void )
{
  
  TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN);  // Send Start
  while( !(TWCR & (1 << TWINT) ) );  // Wait to receive Slave ACK
  Serial.println( "Slave ACK" );   // Never receives the TWINT flag so this never prints
}

void setup( void )
{
  Serial.begin(9600);
  PRR |= 0x80;          // Turn on TWI
  TWCR |= (1 << TWEN);  // Enable SCL and SDA Pg. 83
}
Logged

Pages: [1]   Go Up
Jump to: