jagjit.sehra
New Member
Hi Folks,
I am new to this foroumn, I am intrested in interfacing the SRF05 ultra-range sensors to the PIC18F452 using MPLAB lab enviroment and the C18 complier. The complier already has commands built in to communicate on the I2C bus. The program that I have written however returns no value fromteh internal register of the sensor after ranging. The code is shown below. I am new to this therefore there may be some obvious mistakes that I cant see.
#include <p18f452.h>
#include <sw_i2c.h>
void start(void);
void read(void);
void ack_poll(void);
unsigned char var;
unsigned char value;
unsigned char i;
unsigned char rarr[2];
unsigned char far *rdptr = rarr;
void main(void)
{
start();
ack_poll();
read();
Nop();
}
void start(void)
{
SWStartI2C();
var=SWPutcI2C(0xE0);
SWAckI2C();
var=SWPutcI2C(0x00);
SWAckI2C();
var=SWPutcI2C(0x51);
SWAckI2C();
SWStopI2C();
Nop();
}
void read(void)
{
//unsigned char new;
SWStartI2C();
var=SWPutcI2C(0xE0);
SWAckI2C();
var=SWPutcI2C(0x00);
SWAckI2C();
SWRestartI2C();
var=SWPutcI2C(0xE1);
value=SWGetsI2C(rdptr,2);
//new=SWReadI2C();
var=SWAckI2C();
Nop();
SWStopI2C();
Nop();
}
void ack_poll(void)
{
SWStartI2C();
var=SWPutcI2C(0xE0);
while(SWAckI2C()){
SWRestartI2C();
var=SWPutcI2C(0xE0);
}
SWStopI2C();
}
I have been going mad trying to get it to return some values with no success. Any help will therefore be appreciated. Thanks.
Jag.
I am new to this foroumn, I am intrested in interfacing the SRF05 ultra-range sensors to the PIC18F452 using MPLAB lab enviroment and the C18 complier. The complier already has commands built in to communicate on the I2C bus. The program that I have written however returns no value fromteh internal register of the sensor after ranging. The code is shown below. I am new to this therefore there may be some obvious mistakes that I cant see.
#include <p18f452.h>
#include <sw_i2c.h>
void start(void);
void read(void);
void ack_poll(void);
unsigned char var;
unsigned char value;
unsigned char i;
unsigned char rarr[2];
unsigned char far *rdptr = rarr;
void main(void)
{
start();
ack_poll();
read();
Nop();
}
void start(void)
{
SWStartI2C();
var=SWPutcI2C(0xE0);
SWAckI2C();
var=SWPutcI2C(0x00);
SWAckI2C();
var=SWPutcI2C(0x51);
SWAckI2C();
SWStopI2C();
Nop();
}
void read(void)
{
//unsigned char new;
SWStartI2C();
var=SWPutcI2C(0xE0);
SWAckI2C();
var=SWPutcI2C(0x00);
SWAckI2C();
SWRestartI2C();
var=SWPutcI2C(0xE1);
value=SWGetsI2C(rdptr,2);
//new=SWReadI2C();
var=SWAckI2C();
Nop();
SWStopI2C();
Nop();
}
void ack_poll(void)
{
SWStartI2C();
var=SWPutcI2C(0xE0);
while(SWAckI2C()){
SWRestartI2C();
var=SWPutcI2C(0xE0);
}
SWStopI2C();
}
I have been going mad trying to get it to return some values with no success. Any help will therefore be appreciated. Thanks.
Jag.