Serial EEPROM Writing using mega32

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Task: Interface 24c256 with mega32 with bitbang technique
H/W : mega32 with internal 8Mhz osc, AT24c256 wonnected to mega32, 16x2 LCD for displya in 4bit mode.
S/W:
1. LCD Init (Working)
2. EEPROM Init (Working)
3. EEPROM Read (Working, able to read data saved using some programmer)
4. EEPROM Write (Not working for values ending with 1)

Problem description:
Have a look at WriteByte(). If i make 70 instead of 71, things will work fine. Data will get write if 0th bit of any Shout(value) is 0.

Lets have a look at code (Dean, I wrote it, not copied)

File 1:

initEEPROM();
WriteByte(0,2,71);
k=ReadByte(0,2);
lcd_putc(k);

File 2:

void WriteByte(uint8_t HighWord,uint8_t LowWord, uint8_t d1)
{		
	Start();	
	Shout(160); //Device address byte with write
	Shout(HighWord); //Address High Byte	
	Shout(LowWord); //Address LOW Byte	
	Shout(d1); //Data
	Stop();
}

void Shout(uint8_t d)
{
	//int i,b; //working
	int i;
	int f;
	uint8_t b,t,cnt;	
	//f=255;
	//f = f & d;
	cnt=128;	
	for (i=7;i>=0;i--)
	{	
		//t=f & (1<<i);		 //working
		t=d & cnt;
		if(t==0)
		{
			cbi(SDAPORT,SDA);
		}
		else
		{
			sbi(SDAPORT,SDA);			
		}		
		SHORTDEL		
		sbi(SCLPORT,SCL);
		LONGDEL		
		cbi(SCLPORT,SCL);		
		SHORTDEL		
		cnt=cnt/2;					
	}		
		SHORTDEL
		sbi(SCLPORT,SCL);//working
		//LONGDEL		//working		
		SHORTDEL
		cbi(SDADDR,SDA);	
		b=0;
		b=bit_is_clear(SDAPIN,SDA);			
		sbi(SDADDR,SDA);
		
		SHORTDEL				
		cbi(SCLPORT,SCL);//working
		//LONGDEL//working
		SHORTDEL
	        // i monitored b, its not ack'ing as we expect
		
}

[/code]