Hello everyone,
I have a problem with I2c communication in DSPIC33F. I am using DSPIC 33F as my master and pololu MinIMU 9 v2 as my slave.
http://www.pololu.com/catalog/product/1268
this is the information regarding my slave. It consists of three devices and my slave exactly is L3GD20 3-axis gyroscope
The problem is when I try to observe the readings of slave, I could see only the slave address repeatedly( I m viewing it on CRO).Except that I could not see anything else on CRO.
I m posting my program here.
I have been working on it since a month but could not fix the problem. I could not understand what is the problem with the code,why it is always returning the slave address but could not able to read the registers of slave. I am attaching the datasheet of dspic 33f i2c communication and that of my slave device IMU. Please help me,it's extremely urgent.
Thankyou.
I have a problem with I2c communication in DSPIC33F. I am using DSPIC 33F as my master and pololu MinIMU 9 v2 as my slave.
http://www.pololu.com/catalog/product/1268
this is the information regarding my slave. It consists of three devices and my slave exactly is L3GD20 3-axis gyroscope
The problem is when I try to observe the readings of slave, I could see only the slave address repeatedly( I m viewing it on CRO).Except that I could not see anything else on CRO.
I m posting my program here.
Rich (BB code):
#include "p33Fxxxx.h"
#include <p33FJ64MC802.h>
#include <i2c.h>
#include <String.h>
// calculate baud rate of I2C
#define Fosc (8000000)
#define Fcy (Fosc/2) // no PLL
#define Fsck 100000
#define I2C_BRG 0x188 //((Fcy/2/Fsck)-1)
#define I2C_ON 0x8000
void readFloat(float *ptr);
unsigned char SlaveAddress_read;
unsigned char SlaveAddress_write;
int main (void)
{
float value = 0;
float temp;
I2C1CONbits.A10M = 0;
char status;
unsigned char i2cbyte;
//Enable channel
OpenI2C1( I2C_ON, I2C_BRG );
TRSTAT=1;
SlaveAddress_read = 11010111;
SlaveAddress_write = 11010110;
while (1)
{
readFloat(&value);
}
return 0;
}
void readFloat(float *ptr)
{
unsigned char rx_data[6];
I2C1CONbits.SEN = 1;
while(I2C1CONbits.SEN);
MasterWriteI2C1(SlaveAddress_write);
while (I2C1STATbits.ACKSTAT);//Return Ack Status
MasterWriteI2C1(0b10101000);
while (I2C1STATbits.ACKSTAT);//Return Ack Status
I2C1CONbits.RSEN = 1;
MasterWriteI2C1(SlaveAddress_read);
while (I2C1STATbits.ACKSTAT);//Return Ack Status
rx_data[0] = MasterReadI2C1();
I2C1CONbits.ACKDT=0; // Set for ACk
I2C1CONbits.ACKEN=1; // Send Ack
while(I2C1CONbits.ACKEN); // wait for ACK to complete
rx_data[1] = MasterReadI2C1();
I2C1CONbits.ACKDT=0; // Set for ACk
I2C1CONbits.ACKEN=1; // Send Ack
while(I2C1CONbits.ACKEN); // wait for ACK to complete
rx_data[2] = MasterReadI2C1();
I2C1CONbits.ACKDT=0; // Set for ACk
I2C1CONbits.ACKEN=1; // Send Ack
while(I2C1CONbits.ACKEN); // wait for ACK to complete
rx_data[3] = MasterReadI2C1();
I2C1CONbits.ACKDT=0; // Set for ACk
I2C1CONbits.ACKEN=1; // Send Ack
while(I2C1CONbits.ACKEN); // wait for ACK to complete
rx_data[4] = MasterReadI2C1();
I2C1CONbits.ACKDT=0; // Set for ACk
I2C1CONbits.ACKEN=1; // Send Ack
while(I2C1CONbits.ACKEN); // wait for ACK to complete
rx_data[5] = MasterReadI2C1();
I2C1CONbits.ACKDT=1; // Set for NotACk
I2C1CONbits.ACKEN=1; // Send Nack
while(I2C1CONbits.ACKEN); // wait for ACK to complete
I2C1CONbits.ACKDT=0;
StopI2C1(); //Send the Stop condition
IdleI2C1(); //Wait to complete
memcpy(ptr, &rx_data, 6);
}
I have been working on it since a month but could not fix the problem. I could not understand what is the problem with the code,why it is always returning the slave address but could not able to read the registers of slave. I am attaching the datasheet of dspic 33f i2c communication and that of my slave device IMU. Please help me,it's extremely urgent.
Thankyou.
Attachments
-
763.7 KB Views: 132
-
1.5 MB Views: 31
Last edited by a moderator: