Trying to use MSP430G2553 with SRF02 ultrasonic range finder. The code I'm using below is taken from an example on the internet (I'm assuming it works). However, how do I set up the SDA SCL lines?
I was playing around with #define SDA BIT0 and CSL_init(), which is from the grace example in CCS. Don't think those make sense, Please help.
Here is the related technical specifications of the ultrasound: http://www.robot-electronics.co.uk/htm/srf02techI2C.htm
Code:
void main(void) // taken from example on internet
{
int i;
short range[17];
while(1)
{
i2c_start(); //initiate start condition
i2c_write(0xE0); //device address
i2c_write(0x00); //register address
i2c_write(0x50); //set units to inches
i2c_stop();
delay_ms(105); //wait for returning ping
i2c_start(); //initiate a new start condition
i2c_write(0xE0); //device address
i2c_write(0x02); //address of high byte register
i2c_start();
i2c_write(0xE1); //device address but read
for (i=0;i<17;i++)
{
range[i] = i2c_read(1); //read first byte and shift left
range[i] = range[i] << 8;
if(i<16)
range[i] += i2c_read(1); //read second byte and add to 1st
else{
range[i] += i2c_read(0);}
}
i2c_stop();
for (i=0;i<17;i++)
printf("range in inches = %lu\n\r", range[i]);
delay_ms(1000);
}
}