Hello,
I have successfully used th srf02 module in serial mode with my PIC18F452 board. I'm using the C18 compiler and its built-in libraries.
But Im simply unable to get it working in the I2C mode. Im relatively new to the topic of I2C but have ready quite a few articles on it.
Heres the setup I have created:
connected an 16x4 lcd to the PIC
connected the necessary pull up resistors on SDA/SCL
Clock is 10Mhz with PLL enabled ->> 40Mhz
and heres the code:
void main(void)
{
initialize();
while(1)
{
StartI2C();//start I2C
WriteI2C(0xE0);//send srf02 address
WriteI2C(0x00);//send command reg address
WriteI2C(0x50);//send mode command (inches)
StopI2C();//stop i2c
//delay of minimum 70mS required
Delay10KTCYx(70);
StartI2C();//starti2c
WriteI2C(0xE0);//send srf02 address
WriteI2C(0x02);//send data reg address
RestartI2C();
WriteI2C(0xE1);
datah = ReadI2C();
datal = ReadI2C();
StopI2C();
result= (( datah << 8 ) | datal);
itoa(result,string);
SetDDRamAddr(0x80);//put cursor back on start line
while( BusyXLCD() );
putsXLCD(string);//display the result
while( BusyXLCD() );
Delay10KTCYx(70);
}
}
//-------------------------------------------------------------
void initialize(void)
{
OpenXLCD( FOUR_BIT & LINES_5X7 ); //configure LCD
while( BusyXLCD() );
OpenI2C(MASTER, SLEW_ON);
return;
}
am I missing something? the led on the srf module flickers only at the start.
any pointers would be highly appreciated.
Thank you.
Mohit
