Discussion in "8051 Discussion Forum" started by    abbas1707    Dec 31, 2007.
Mon Dec 31 2007, 04:17 pm
#1
hello everyone!

i wrote I2c library but i cant find a way to test it whether it works or not.
is there any way to test it on software like proteus?? there is an i2c debugger on proteus but i cant understand how to use it.
plz help
Mon Dec 31 2007, 04:33 pm
#2
just connect the pins you are using to the I2C debugger.. and run your program..
SDA to SDA and SCL to SCL. there is nothing special...
then you can see what is going on on the SDA line and SCL line..
Tue Jan 01 2008, 04:51 pm
#3
hi Ajay,

i tried my own library but it is giving nothing.then i tried yours but same result,, and i dont understand where im making mistake.
here is code and snap shot of proteus.im testing ds1621 which i available in proteus .
#include "I2C.H"
bit i2c_busy, no_ack, bus_fault;
ubyte bdata a;
int i;
sbit LSB=a ^ 0;
sbit MSB=a ^ 7;
void send_stop()
{
	sda = 0;
	scl = 1;
	HOLD;
	sda = 1;
	i2c_busy = 0;
}
void master(ubyte slave_addr)
{
	i2c_busy = 1;
	no_ack = 0;
	bus_fault = 0;
	if(!scl||!sda)
		bus_fault = 1;
	else
	{
		sda = 0;
		HOLD;
		scl = 0;
		HOLD;
		send_byte(slave_addr);
	}
}
void send_byte(ubyte i2c_data)
{
	ubyte i;
	a=i2c_data;
	for(i=0;i<8;i++)
	{
		scl=0;
		HOLD;
		sda=MSB;
		a<<=1;
		_nop_();
		scl=1;
		HOLD;
		scl=0;
	}
	sda = 1;
	scl = 1;
	HOLD;
	if(!sda)
	{
		scl = 0;
		HOLD;
	}
	else
	{
		no_ack = 1;
		scl = 0;
		HOLD;
	}
}
ubyte recv_byte(ubyte cnt)
{
	ubyte i,rcv_data;
	for(i=0;i<8;i++)
	{
		sda=1;
		scl=1;
		HOLD;
		LSB=sda;
		if(i<7)
			a<<=1;
		HOLD;
		scl=0;
		HOLD;
	}
	if(cnt==1)
		sda = 1;
	else
		sda = 0;
	scl =1;
	HOLD;
	scl = 0;
	sda = 1;
	HOLD;
	rcv_data = a;
	return rcv_data;
}
void main()
{
	unsigned char h;
	master(0x90);               
	send_byte(0xaa);
	master(0x91);           
	h=recv_byte(1);
	P3=h; // just to see what is most significant byte of temp
	send_stop(); 
} 




Tue Jan 01 2008, 05:35 pm
#4
there is a wrong transition on your I2C lines.. thats why you are getting those '?'
see the first frame goes perfect.. after that you are doing some change on SDA or SCL line which causing the whole problem...
or if you are trying to read.. then you must have the peripheral connected on I2C lines.. and i see that U2 is not connected yet.. so connect it and try again..
 abbas1707 like this.
Tue Jan 01 2008, 07:13 pm
#5
what is I2C?
Wed Jan 02 2008, 12:56 am
#6
Thanx Ajay!! it started working :-)
Ajay shud we place driver for ds1621 in our download section it is not tested on hardware.....


[ Edited Wed Jan 02 2008, 12:58 am ]
Wed Jan 02 2008, 01:12 am
#7
@snehasish

I²C (inter integrated circuit)bus is a bi-directional two-wire serial bus that provides a communication link between integrated circuits (ICs). and protocol dat is used for communication is known as I²C protocol .
for more info google it
Wed Jan 02 2008, 01:47 am
#8
Well.. i say.. if its working on Proteus then it should be working on hardware.. though i should not say this.. but Proteus gave me exact results whenever i tested..
Sure we can have the DS1621 library in our download section..

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm
Charlestehed
Wed Apr 24 2024, 05:20 pm
Robertgurse
Wed Apr 24 2024, 02:43 pm
Richardedils
Wed Apr 24 2024, 04:07 am
Malcolmaccek
Wed Apr 24 2024, 01:21 am
ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am