I2C line following sensor - can't read
Navigates to RoboticsConnection.com Home RoboticsConnection.com HomePage
RoboticsConnection User Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



I2C line following sensor - can't read Expand / Collapse
Author
Message
Posted Friday, June 11, 2010 4:43 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: Tuesday, June 22, 2010 9:10 AM
Posts: 1, Visits: 15
Hello I have been trying for 2 days to read the sensor but without success.
I'm using a pic18f248 with 1.8k pull up on sda & scl and the c18 compiler

here is my code maybe you guys can find anything wrong ?
I don't know if my I2C_read routine is correct.
Maybe my initialization isn't correct ? I've read many topics on internet and there was sometimes " #pragma config BOR = ON " but I didn't see anything about that on the 18f248 datasheet.

#include
#pragma config OSC=HS
#pragma config WDT=OFF
#pragma config LVP=OFF



void I2C_idle(void)
{
int boucle;

while(boucle == 0)
{
if((SSPCON2bits.ACKEN == 0) && (SSPCON2bits.SEN == 0) && (SSPCON2bits.RSEN == 0) && (SSPCON2bits.PEN == 0) && (SSPCON2bits.RCEN == 0) && (SSPSTATbits.R_W == 0))
boucle=1;
}
}

void I2C_start(void)
{
I2C_idle();
SSPCON2bits.SEN = 1;
}

void I2C_write(char donnee)
{
I2C_idle();
SSPBUF = donnee;
}


void Ack_slave_master(void)
{
I2C_idle();
while(SSPCON2bits.ACKSTAT==1);

}

void Repeated_start(void)
{
I2C_idle();
SSPCON2bits.RSEN = 1;
}

void I2C_read(void)
{
I2C_idle();
SSPCON2bits.RCEN=1;
while(SSPCON2bits.RCEN==1);
}


void Ack_master_slave(void)
{
I2C_idle();
SSPCON2bits.ACKDT = 0;
SSPCON2bits.ACKEN = 1;
}

void I2C_NOACK(void)
{
I2C_idle();
SSPCON2bits.ACKDT = 1;
SSPCON2bits.ACKEN = 1;
}

void I2C_stop(void)
{
I2C_idle();
SSPCON2bits.PEN = 1;
}

void pause(void)
{
unsigned int time = 0;

while(time < 10000)
time++;
}

void main(void)
{
unsigned char test;
SSPSTATbits.SMP = 1;
SSPSTATbits.CKE = 0;
SSPADD = 0x31; //master mode
SSPCON1 = 0x28; //SCL ~100k
TRISB = 0x00;
TRISC = 0x18;
I2C_start();
I2C_write(0x50);
I2C_read();
I2C_stop();
PORTB=SSPBUF; //display the result
while(1);

}

with this code the only thing displayed is the value inside write
Post #1910
Posted Friday, July 09, 2010 10:39 AM


Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Administrators
Last Login: Monday, October 31, 2011 9:18 PM
Posts: 640, Visits: 819
Here is the PIC code we use in the Serializer, where address is 0x50:

#use I2C(master, sda=PIN_c4, scl=PIN_c3,slow)

...


i2c_start();   // restart condition
i2c_write(ADDRESS + 1);
value = i2c_read(0);
i2c_stop();

Best Regards,

Jason Summerour
President,
Summerour Robotics Corporation
www.roboticsconnection.com

Post #1928
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: jsummerour, ringo

Permissions Expand / Collapse

All times are GMT -8:00, Time now is 6:08am

Powered By InstantForum.NET v4.1.4 © 2012
Execution: 0.078. 9 queries. Compression Disabled.