Hi, I am trying get results with I2C from a MMA7455 accelerometer but i'm stuck. I use MikroC Pro and his library. I have connected the CS pin to VCC, SDA to RC4, SCL to RC3, VCC to VCC and GND to GND. First I want to read the values from the x axis. If the value it would be bigger then "0" i should have a led turned on, else the led should be turned off. I have read the datasheet and I have understood that the address of MMA7455 is 0x0D (please correct me if i'm wrong), and the register of X axis is 0x06( i have tried also 0x00). Because it didn't worked like this i have searched the web and I have found different addreses for the same accelerometer. Some people said that te address is 0x3A or 0x2D, i tried these addresses but it didn't work. Please help me. Here it is the code
Rich (BB code):
// Software I2C connections
sbit Soft_I2C_Scl at RC3_bit;
sbit Soft_I2C_Sda at RC4_bit;
sbit Soft_I2C_Scl_Direction at TRISC3_bit;
sbit Soft_I2C_Sda_Direction at TRISC4_bit;
// End Software I2C connections
char X;
void Read_X() {
Soft_I2C_Start(); // Issue start signal
Soft_I2C_Write(0x3A);
Soft_I2C_Write(0x00);
Soft_I2C_Start(); // Issue repeated start signal
Soft_I2C_Write(0x3B);
X = Soft_I2C_Read(0u);
Soft_I2C_Stop();
}
void Init_Main() {
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
Soft_I2C_Init(); // Initialize Soft I2C communication
}
void main() { // Main procedure
Delay_ms(500);
Init_Main(); // Perform initialization
while (1) {
Read_X();
if (X<0)
{ trisb.b5=0;
portb.b5=1;}
else
{ trisb.b5=1;
portb.b5=0;}
}
}