PIC MikroC I2C Communication Problem.

Status
Not open for further replies.

sabin14

Junior Member level 3
Joined
Mar 5, 2013
Messages
30
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,288
Location
Kerala,India
funzone.mobi
Activity points
1,431
I am trying to get values form the gyroscopic sensor(MU6060) using I2C and display it directly on lcd using pic 16f877a at 4Mhz.
But not displaying any value on LCD. Please help me to correct the code. The sensor address is 0x69.

Code:
  sbit LCD_RS at RB7_bit;
  sbit LCD_EN at RB5_bit;
  sbit LCD_D4 at RB1_bit;
  sbit LCD_D5 at RB2_bit;
  sbit LCD_D6 at RB3_bit;
  sbit LCD_D7 at RB4_bit;

  sbit LCD_RS_Direction at TRISB7_bit;
  sbit LCD_EN_Direction at TRISB5_bit;              //lcd configuration
  sbit LCD_D4_Direction at TRISB1_bit;
  sbit LCD_D5_Direction at TRISB2_bit;
  sbit LCD_D6_Direction at TRISB3_bit;
  sbit LCD_D7_Direction at TRISB4_bit;
  char temp ;                                 //temporary variable
void main(){

  PORTB = 0;
  TRISB = 0; 
  Lcd_Init();
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_out(1,1,"I2C Value");
  I2C1_Init(100000);            //set clock frequeny
  while(1){
    I2C1_Start();             //start I2C
    I2C1_Repeated_Start();
    I2C1_Wr(0x69);
    temp = I2C1_Rd(0);         //read value and store it in temp
    Lcd_Chr(2,1,temp);       //display value read form I2c
    I2C1_Stop();
    Delay_ms(300);
  }
}
 

Try this


Code C - [expand]
1
2
3
4
5
6
I2C1_Start();              // issue I2C start signal
I2C1_Wr(0x69);             // send byte via I2C  (device address + W)
I2C1_Wr(1);                // send byte (data address)
I2C1_Repeated_Start();     // issue I2C signal repeated start
temp = I2C1_Rd(0);        // Read the data (acknowledge)
I2C1_Stop();




Datasheet mentions about RA (Register Address of Sensor to read or write). Can you tell me what is the address of the register to be read?

Without RA it will not work.


 

Attachments

  • gyro.jpg
    97.5 KB · Views: 133
Last edited:
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…