I have a Baby O: B-328 (https://www.pololu.com/catalog/product/1220) and LSM303DLHC (https://www.pololu.com/catalog/product/2124) connected to a breadboard.
B-328
11.5 volts to VIN from 8 AA batteries
LSM303DLHC
4.98 volts from B-328 VCC
<Edit 12/30/2012 15:42 eastern>
(I made a mistake in explaining the first time)
LSM303DLHC SLC jumpered to B-328 PC4
LSM303DLHC SDA jumpered to B-328 PC5
Pins are actually:
LSM303DLHC SDA jumpered to B-328 PC4
LSM303DLHC SCL jumpered to B-328 PC5
While attempting to read from the CTRL_REG1_A (20h) Register of the LSM303DLHC’s Linear Acceleration Digital Interface (33h). It gets to the point after the i2c_start_wait(), lights the red LED and stops. I have tried other registers in the Linear Acceleration Digital Interface as well as trying the Magnetic Field Digital Interface (3Dh) and a couple of it’s registers and have the same results.
Pull-up resistors are on the board for the I2C, correct? So I don’t need external resistors. The LSM303DLHC’s on-board resistors measure 4.67k each.
To test PC4 and PC5
I have set PC4 and PC5 HIGH to light a LED each.
I also set PC4 and PC5 LOW. PC0 and PC1 HIGH. With a jumper PC0 to PC4 and PC1 to PC5 to check for proper input readings and they appear to be in good order.
Even if I comment out the red_led()s and delays prior to “i2c_write(0x20)” (Figuring the delays might impact the I2C process) and setting the following red_led(1) and a delay_ms(2000), the led does not light. I think it’s a “i2c_write(0x20)”, but what?
Any suggestion where to look next would be great.
#include <pololu/orangutan.h>
#include <i2cmaster/i2cmaster.c>
#include <i2cmaster.h>
#define F_CPU 20000000UL
#define LSM303DLC_ACCELERATOR 0x33 // device address
int main(void)
{
unsigned char ret;
red_led(1);
delay_ms(100);
i2c_init(); // initialize I2C library
red_led(0);
delay_ms(100);
// read previously written value back from address
// set device address and write mode
i2c_start_wait(LSM303DLC_ACCELERATOR+I2C_WRITE);
red_led(1);
delay_ms(100);
i2c_write(0x20); // write address
red_led(0);
delay_ms(100);
// set device address and read mode
i2c_rep_start(LSM303DLC_ACCELERATOR+I2C_READ);
red_led(1);
delay_ms(100);
ret = i2c_readNak(); // read one byte
red_led(0);
delay_ms(100);
i2c_stop();
while(1){
red_led(1);
delay_ms(400);
red_led(0);
delay_ms(400);
}
}