Computer Interfacing
Discussions about interfacing and electronics
 

Problem in I2C Communication

The problem is that slave is not sending the acknowledgement to proceed on to next step. Hence the bus is getting busy only by the slave address microcontroller is sending. And hence we are able to view only slave address in the bus. connections: co


 

       Computer Interfacing Forum Index -> I2C bus
Author Message
prabhakar.kapula
New User



Joined: 06 Oct 2012
Posts: 1
Location: Hyderabad

Oct 06, 2012 7:38 am

Basically our task is to establish I2C communication between DSpPIC 33F and L3GD20( 3 axix gyro). Master is DSPIC33F and the slave is the gyro.
Actually this gyro returns the angular velocities for the movement we give.It returns the values 16bits per axis and total of 6 bytes of information for a position.
our code is :

#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 = 0b11010111;
SlaveAddress_write = 0b11010110;

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);
}

The problem is that slave is not sending the acknowledgement to proceed on to next step. Hence the bus is getting busy only by the slave address microcontroller is sending. And hence we are able to view only slave address in the bus.
connections:
common power supply to the gyro as well as to dspic 3v3( from system USB,regularized to 3.3v)
SCL,SDA were pulled up through 4.7k.
Supply given to Vin rather than Vdd of gyro.
Naveendharan
Guest







Jan 23, 2013 5:57 am

Hi prabhakar,

Im also having the same problem. In my project controller is able to communicate with L3GD20 sometimes, most often its not. just don know whats the hell is going on. will u able to rectify the problem? if yes please help me in this.

is there anything need to be done with hardware?
sda and scl are pulled through 4.7k.

anyone please Help me in this:(
saim
New User



Joined: 22 Oct 2014
Posts: 2
Location: uk

Oct 22, 2014 4:46 am

Hi prabhakar,

Im also having the same problem. In my project controller is able to communicate with L3GD20 sometimes, most often its not. just don know whats the hell is going on. will u able to rectify the problem? if yes please help me in this.

is there anything need to be done with hardware?
sda and scl are pulled through 4.7k.

anyone please Help me in this:(

       Computer Interfacing Forum Index -> I2C bus
Page 1 of 1



Running on php BB © 2001, 2009 php BB Group
   Lammert Bies     Interfacing     Sitemap     Forum