Weird problem with AT24C1024B

Go To Last Post
19 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, i am having strange problems interfacing EEPROM with ATmega32.

I have tested the code on Proteus simulation and it works. I have checked the connections and everything seems to be ok. The SPI is getting initialized, the physical EEPROM is responding to start condition with a 0x08 but when i send device address afterwards it simlpy does not respond with 0x18. Instead it is giving NO ACK i.e 0x20..

A2 and A1 pins are grounded so i used 0xA0 as device address. I even tried using 0xA4, 0xA8, 0xAC as device address but just does not respond to anything

My code is a bigger one but here is the most basic code i programmed on it just to check where is the problem.

#define F_CPU 16000000UL
#include 
#include 
#include 



int main(void)
{
	DDRD=0xFF;
	PORTD=0xFF;
	
	//INT
    TWBR=0x12;  // Bit rate
    TWSR=(0<<TWPS1)|(0<<TWPS0); //prescaler configured to make 100KHz SCL frequency
	
	
	
	//SEND START
	TWCR= (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);  
    while(!(TWCR & (1<<TWINT))); 
	while((TWSR & 0xF8)!= 0x08); 
	_delay_ms(50);
	
		
	//SEND DEVICE ADD
	TWDR=0xA4;
	TWCR=(1<<TWINT)|(1<<TWEN);
	while (!(TWCR & (1<<TWINT)));
	while((TWSR & 0xF8)!= 0x18);
	
	flash();
	_delay_ms(1000);
/*This is where the code hangs because it is not receiving 0x18 but if i set it to 0x20 then code runs i.e its returning NO ACK*/
	
	//SEND ADD MSB
	TWDR=0x00;
	TWCR=(1<<TWINT)|(1<<TWEN);
	while (!(TWCR & (1<<TWINT)));
	while((TWSR & 0xF8)!= 0x28);
	
	
	//SEND ADD LSB
	TWDR=0x00;
	TWCR=(1<<TWINT)|(1<<TWEN);
	while (!(TWCR & (1<<TWINT)));
	while((TWSR & 0xF8)!= 0x28);
	
	//SEND DATA
	TWDR=0xAA;
	TWCR=(1<<TWINT)|(1<<TWEN);
	while (!(TWCR & (1<<TWINT)));
	while((TWSR & 0xF8)!= 0x28);
	
	//SEND STOP
	TWCR= (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);    
    while(!(TWCR & (1<<TWSTO)));  // Wait till stop condition is transmitted
	_delay_ms(50);
	
	
	
	
}
void flash(void)
	{
		PORTD=0x00;
		_delay_ms(200);
		PORTD=0xFF;
		_delay_ms(200);
		PORTD=0x00;
		_delay_ms(200);
		PORTD=0xFF;
		_delay_ms(200);
		
	}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I gather you have pullup resistors on sda and scl?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

From the data sheet:

Quote:
Figure 7-1. Device Address

Your Slave address is 0xA0/0xA1 (W/R) for memory 0x00000..0x0FFFF and 0xA2/0xA3 for 0x10000..0x1FFFF

So it is fairly clear that 0xA4 is not going to work.

As always, it is wise to use proven libraries. e.g. Fleury.

Mind you, your code 'looks' ok to me. So if you use the correct (W) address of 0xA0, everything should work. If it does not work, solder your chip properly to the correct pcb traces with real 4k7 external pull-up resistors.

You don't show your Proteus schematic. I presume that Proteus would not work without pull-up resistors. OTOH, Proteus seems to have no idea about sensible resistor values.

David.

p.s. please can you delete your duplicate post before anyone replies to it. ( click on [X] )

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have deleted the duplicate post half an hour apart.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
From the data sheet:
Quote:
Figure 7-1. Device Address

Your Slave address is 0xA0/0xA1 (W/R) for memory 0x00000..0x0FFFF and 0xA2/0xA3 for 0x10000..0x1FFFF

So it is fairly clear that 0xA4 is not going to work.

As always, it is wise to use proven libraries. e.g. Fleury.

Mind you, your code 'looks' ok to me. So if you use the correct (W) address of 0xA0, everything should work. If it does not work, solder your chip properly to the correct pcb traces with real 4k7 external pull-up resistors.

You don't show your Proteus schematic. I presume that Proteus would not work without pull-up resistors. OTOH, Proteus seems to have no idea about sensible resistor values.

David.

p.s. please can you delete your duplicate post before anyone replies to it. ( click on [X] )

I already had tried A0, infact i tried all combination A0, A4, A8, AC. It turned out that the particular IC was the problem.

I changed it and now its working good at 0xA8 (since i set A2 to high)
Sorry to bother you guys but i just wanted to make sure my code was ok. Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does Proteus complain if you omit the pull-up resistors in the schematic?

It is VERY unusual to get a duff EEPROM.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
Does Proteus complain if you omit the pull-up resistors in the schematic?

It is VERY unusual to get a duff EEPROM.

David.

In proteus it works even if you dont use pull-up but in actual one must use pull ups otherwise it wont work.

Well i dont know but it turned out to be the faulty IC. I am using pulls on both Proteus and actual circuit.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lots of people seem to use Proteus.

Unfortunately none of the 'older' members have a Proteus licence. So we can only guess about things.

I presume that it 'learns' about your hardware from the schematic. So when you shake a pin in software, it can do the appropriate action for the simulated hardware devices.

If it does not require pull-up resistors on I2C, this is a bad Simulation.
It appears to simulate a HD44780 CLCD display from pictures sent here.
Likewise a KS0108 GLCD display.

If you send the wrong timing for these chips, will Proteus work ?

I have used other Simulators that really do test I2C or LCD chip timing. How does Proteus behave ?

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What do you mean by wrong timing? Well its simulator is quite realistic so if anything is wrong in code or circuit it will behave likewise. The reason it does not need pull up resistors is that may be it turn ons the internal pull ups of the uC. OR the IC in proteus is AT24CxxxxC so perhaps this new version (unlike AT24CxxxxB) has internal pull ups.

Yes it can easily simulate G,C LCDs. But afaik there are no timing diagrams (or may be i am unaware of) but simulation and behavior is quite realistic. I even simulated USART with virtual terminal of proteus and it worked great.
(it has built-in max232 with RS232 connector)

Most people use pirated version, i dont know how badly it will hurt me but i am also using such a version.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A HD44780 is very fussy about the timing of its initialisation code. It is also fussy about the regular lcd_data() or lcd_command() timing.

We get LCD threads here every day. Generally from people who decide they are going to do things differently to the data sheet.

The GLCDs seldom have timing issues. They mostly work faster than the average AVR.

A USART in real life must work at the same baud rate as the receiving terminal.

Does Proteus display text on the terminal if you set the wrong baud rate?

It has always struck me that Proteus must be an excellent product for students to simulate their projects. Of course in those Universities that provide licensed copies to their students.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
so perhaps this new version (unlike AT24CxxxxB) has internal pull ups.

What would happen if 4..8 versions with internal pull ups were paralleled?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't think that there are any I2C hardware chips that have real I2C pull-ups. Since you can have many devices on a bus, you would soon upset the drivers.

Some specialised chips have 'weak internal' pull-ups. These are of the order of 100k-500k. So are unlikely to cause problems. For example, you are unlikely to have more than one or two accelerometer chips on the bus.

OTOH, they can't possibly work on a standard 100kHz bus. Due to their 'weakness' you can possibly communicate at 1kHz or so. A bus that does not meet the spec seems a bit useless to me.

AFIK, regular EEPROM chips never have pull-ups.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Unfortunately none of the 'older' members have a Proteus licence.

Quote:

Most people use pirated version, i dont know how badly it will hurt me but i am also using such a version.

As you/we suspected, David.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't think that there are any I2C hardware chips that have real I2C pull-ups. Since you can have many devices on a bus, you would soon upset the drivers.
I did not think it was likely....

(perhaps a 1Khz I2C bus, though unusal -it makes a ca 100 analog readings per second- is of some use/fast enough...)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Excuse me!

Quote:
none of the 'older' members have a Proteus licence
you mean none of the WISE members have a Proteus license as they don't need no stinkin simulator. :-)

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No. I think that Proteus looks an excellent product.

Yes, It would be very useful for Universities and their students.

As a hobbyist, I am not prepared to pay $400 (or whatever) for a licence.

I suspect that Educational establishments can get special deals.

From LabCenter's point of view, it seems unfortunate that they suffer from their software being stolen.

I am sure that if they improved their security, they would earn more from cheap educational licences. Obviously this is a commercial decision for LabCenter. The hobbyist market exists, but perhaps is not large enough to justify cheaper+more. Or whether they would pay anything at all !

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
A HD44780 is very fussy about the timing of its initialisation code. It is also fussy about the regular lcd_data() or lcd_command() timing.

We get LCD threads here every day. Generally from people who decide they are going to do things differently to the data sheet.

The GLCDs seldom have timing issues. They mostly work faster than the average AVR.

A USART in real life must work at the same baud rate as the receiving terminal.

Does Proteus display text on the terminal if you set the wrong baud rate?

It has always struck me that Proteus must be an excellent product for students to simulate their projects. Of course in those Universities that provide licensed copies to their students.

David.

Well i made my own code for this particular LCD driver and it works good. One way is to check the busy flag of lcd, i however simply put an approximated delay after each command (since the time it takes to process is written in the datasheet) usually 10ms is more then enough. I wonder why so many people get problems initializing it

I can upload my code if it can does good to anybody. I personally am not very easy with using libraries so i always try to make my own commands since the very start. But sometimes (like interfacing SD card) i am forced to use libraries and sadly enough i am still stuck on interfacing SD card since the past 7 days. I am not just able to get its know how properly, or may be it actually is that difficult.

Oh that went off-topic, yes Proteus will not work if you set the baud rate incorrect, it will show garbage text. In fact you have to set all the parameters such as stop bits, parity, bit format etc. I am attaching two screen caps, one of LCD and one of My virtual terminal (it is looped back just for checking purpose because GSM/GPS module was not available in proteus)

I know how bad is this but affording a 400$ + software for a student is not possible. And then it is much easier to simulate things first before implementing it on hardware. Sadly enough even companies with good running business use pirated version of pretty much all the software. Solidworks, Altium, proteus you name it.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I personally am not very easy with using libraries so i always try to make my own commands since the very start.

This seems strange to me.

I would start with a library. I would get the project working. I might think "can I do better?". Only at this stage would I look at the library code and compare with the data sheet. Yes, I do like to know how something works.

Quote:
usually 10ms is more then enough. I wonder why so many people get problems initializing it

This is really odd. If a library uses the correct timing, why would anyone deliberately introduce unnecessary waste of time?

Quote:
I know how bad is this but affording a 400$ + software for a student is not possible.

We can all understand this. But if your school/university negotiates a deal, they would probably pay $10..$50.

Quote:
Sadly enough even companies with good running business use pirated version of pretty much all the software. Solidworks, Altium, proteus you name it.

Do companies in your country use stolen lorries and vans too?

Returning to the original subject. Proteus simulates UART baud etc. If you alter the wiring to pins A2,A1 on your EEPROM schematic, does Proteus check the new hardware Slave addresses?

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The EEPROM in proteus is AT24CxxxxC, it has only one pin A1. and yes it checks for the actual state of this pin.

No sir, perhaps vans and lorries have a comparatively large footprint to be stolen easily. Slowly rules against piracy are getting imposed but it will take quite some time to actually make an effect.

And no it is not that way, i do use libraries but i always first want to get to the depth myself, just so that i have a better understanding. But like in case of SD card, i am forced to use library... About the lcd delay, i know datasheet has the actual values of time it needs for each instruction. This 10ms delay was just for testing purposes on simulation