Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

25cxx SPI EEPROM interface with atmega8535 or atmega16

Status
Not open for further replies.

vijayragavalu

Member level 1
Joined
Aug 29, 2005
Messages
36
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,558
25cxx

can any one help me out . i need source code to interface 25c04 to atmega8535 or 16 uc i tried to read out the status of 25c04 but i failed to get it

thankyou
 

atmega8535 value pull-up resistors

Atmel has an app note on this: AVR320.

http://www.atmel.com/dyn/resources/prod_documents/doc1108.pdf

There is also some example code in ASM for this app note on the Atmel site.

The most common problem with interfacing to EEPROMs is not including the pull-up resistors. Refer to your datasheet, but usually at least the data line from the EEPROM to the AVR needs a pullup.
 

opcode for atmega8535

ya every thing i did it and i am doing my work in C language could you please help me out.
hardware is no issue (like pullup resistors)
 

atmega16 interface with eeprom source code

Did you check out the avrfreaks website?

www.avrfreaks.net

There are a number of projects on that site that use EEPROMs.

Where did you get your C code? Are you using the AVR's built-in SPI interface? If so, are you attached to the correct pins? Did you remember to configure the IO DDR registers properly?

When attempt to read the ID from the EEPROM, what do you get? If you get all 0xFFs, then it sounds like the part is not connected properly, or is missing an input signal. Double check power, ground and all signals to the EEPROM with a multimeter. Wiring shorts or opens are common.

If you are still having problems, then I think you need to use an o-scope to look at the clock and data lines.
 

ic 25c04

hi banjo
i didnt connect 25c04 to SPI line of atmega i connected it in other i/o lines(PD4,PD5,PC0,PC1 to MISO,CS,MOSI,SCK respectively )

i would like to do it in normal SPI protocal (as per 25C04 Datasheet)

in Avrstudio4.12 i dont know how to set and reset a perticular PORT Bit line without distrubing other pins(i.e if i need to set PORTC.0, the following command will not work 1<<PORTC and PORTC=0x01) ...and i have done bitwise access in keil for at89s51(Sbit P0^1,sbit P0^2).if this is possible in atmega8535 can you please tell me the command.


and i sent exact command to read out the STATUS reg of Microchip 25c04 ic i cross checked in o scope also. and i got 0x20,But my ans shoud be 0x02 i dont know why
 

eeprom atmega16

can any one tell me the answer.....
 

spi eeprom by atmega16

Hi,

I posted a reply over the weekend, but I see that it did not make it to the Forum.
With regard to bit setting and clearing, there are a number of ways to do this depending on the compiler you are using.

With the GCC compiler, the current recommended way is something like:

// Port Set
PORTD |= _BV(SPRK_4);

// Port Clear
PORTD &= ~(_BV(SPRK_4));


These are read, modify, write operations; so only one bit is affected. Of course, if the right hand side has several bits referenced then all these will be affected. The "_BV()" is a compile time function that does the bit shifting for you. All you provide is the bit position in the addresses you are modifying.

With regard to the STATUS reg, try removing the EEPROM and running the code again. What value do you receive?

If you receive, 0xFF, then I would suspect that the problem is with your handling of the shifted in data from the EEPROM. Try writing and reading an eeprom address. What do you receive? This may give you further clues as to what is the problem.

If you still receive, 0x02, then I would suspect that the problem is with the port assignment or the address you are reading to reference the port. I say this because the receive data is independent of whether the eeprom is there or not!

Also, looking at a datasheet on the web, you have to issue a WREN instruction to enter write mode. The WEL powers up as a '0'. Therefore, unless you run WREN, I would not expect the WEL bit set.
 

example code eeprom atmega16

thanks for your reply banjo

in my coding i do these commands
PORTD |= _BV(SPRK_4);
PORTD &= ~(_BV(SPRK_4));
other than that you have any commands to alter Individual bit line please..

if i remove EEPROM i got status reg 0xFF
status reg
https://obrazki.elektroda.pl/38_1179153911.jpg
and my (SCK) clock frequency is 45khz
befor issuing WREN i got 0x20;after issuing i got status reg of 0x00; i dont know what problem..
after complete debug and checkup i will tell you the status ok please help me out
[/img]
 

op code atmega16

Whose EEPROM are you using? Depending on the vendor, the upper bits of the STATUS register mean different things. For example, CATALYST calls bit #5 the SPI_MODE bit.

Take a look at these datasheets:

http://doc.chipfind.ru/catalyst/25c02.htm

**broken link removed**

The MicroChip datasheets states that you MUST take the CS to its inactive state after sending the WREN command. If you do not do this, the WREN command will be ignored.

Since you see a change without the EEPROM and the STATUS changes after an attempted WREN, I would look closely at the sending of the WREN command. Are you sending the bits in the correct order? Do you clock, data, and chip selects match the datasheets?
 
eeprom interfacing using atmega16

thank you Banjo
i got status reg exactly then i would have to read and write in memory location
and will tell you the result
thanks a lot
 

interfacing eeprom with atmega 16

hi banjo

again i have problem this is my code can you please gothrough the code

i added the result near the c code line. plz tell me wats problem

#include<avr/io.h>

void delayms(int);
void writeEn(void);
void writeSts(unsigned char);
unsigned char SPIread(unsigned char);
void SPIwrite(unsigned char);
unsigned char readSts(void);
unsigned char dataR[10],dataS[10];

int main()
{
unsigned int i=0;
unsigned char data=0;
DDRD=0x10; // MISO - PD5 , CS -PD4
DDRC=0x03; // MOSI - PC1 , SCK -PC0
PORTD=0xFF;
PORTC=0xFF;
delayms(200);
UCSRB=0x98;
UCSRC=0x86;
UBRRL=25; // BAUD rate 9600 for 4MHZ crystal

writeEn();
UDR=readSts(); // result 0x02
delayms(2);

writeEn();
writeSts(0x00);
UDR=readSts(); // result is 0x00;
delayms(2);

writeEn();
UDR=readSts(); // result 0x02
delayms(2);




SPIread(0x52); // SPI READ from 0x52 memory before write
for(i=0;i<10;i++)
{
UDR=dataR; //result is ten 0 values
delayms(3);
}


SPIwrite(0x52); // SPI WRITE from 0x52 memory
for(i=0;i<10;i++)
{
UDR=dataS; // result is 0 to 9
delayms(3);
}

for(i=0;i<10;i++) // Clear dataR[] arrays
{
dataR=0;
}


SPIread(0x52); // SPI Read from 0x52 after write
for(i=0;i<10;i++)
{
UDR=dataR;
delayms(3); // result is ten 0(but result should be 0 to 9)
// i dont know why tell me why
}


while(1)
{
/* data=readSts();
delayms(100);*/
;
}
return 0;
}


void delayms(int n)
{
int i,j;
for(i=0;i<n;i++)
for(j=0;j<100;j++);
}

void writeEn(void)
{
unsigned char x=0x06,i,j;
PORTD= 0xEF;
PORTC=0x00;
for(i=0;i<=7;i++)
{
j=x>>7 & 0x01;
if(j==1) PORTC |=0x02;
else PORTC &=0xFD;
x=x<<1;
PORTC &= 0xFE;
delayms(1);
PORTC |= 0x01;
delayms(1);
}
PORTD= 0xFF;
}


void writeSts(unsigned char sta)
{
unsigned char x=0x01,i,j;
PORTD= 0xEF;
for(i=0;i<=7;i++)
{
j=x>>7 & 0x01;
if(j==1) PORTC |=0x02;
else PORTC &=0xFD;
x=x<<1;
PORTC &= 0xFE;
delayms(1);
PORTC |= 0x01;
delayms(1);
}
j=0;
for(i=0;i<=7;i++)
{
j=sta>>7 & 0x01;
if(j==1) PORTC |=0x02;
else PORTC &=0xFD;
sta=sta<<1;
PORTC &= 0xFE;
delayms(1);
PORTC |= 0x01;
delayms(1);
}
PORTD= 0xFF;
}


unsigned char readSts(void)
{
unsigned char x=0x05,i,j;
unsigned char data=0;
PORTD= 0xEF;
for(i=0;i<=7;i++)
{
j=x>>7 & 0x01;
if(j==1) PORTC |=0x02;
else PORTC &=0xFD;
x=x<<1;
PORTC &= 0xFE;
delayms(1);
PORTC |= 0x01;
delayms(1);
}
j=0;
for(i=0;i<=7;i++)
{
PORTC |= 0x01;
delayms(1);
PORTC &= 0xFE;
delayms(1);
j=~PIND;
j=j & 0x20;
if(j ==0x20)
{
data <<=1;
data|=0x01;
}
else data<<=1;
j=0;
}
PORTD= 0xFF;
data=~data;
return data;
}



unsigned char SPIread(unsigned char add)
{
unsigned char count=10,x=0x03,i,j;

PORTD= 0xEF;
PORTC= 0x00;
for(i=0;i<=7;i++)
{
j=x>>7 & 0x01;
if(j==1) PORTC |=0x02;
else PORTC &=0xFD;
x=x<<1;
PORTC &= 0xFE;
delayms(1);
PORTC |= 0x01;
delayms(1);
}
for(i=0;i<=7;i++)
{
j=add>>7 & 0x01;
if(j==1) PORTC |=0x02;
else PORTC &=0xFD;
add=add<<1;
PORTC &= 0xFE;
delayms(1);
PORTC |= 0x01;
delayms(1);
}
// data=0x00;
j=0;
count=0;
while(count<10)
{
for(i=0;i<=7;i++)
{
PORTC |= 0x01;
delayms(1);
PORTC &= 0xFE;
delayms(1);
j=~PIND;
j=j & 0x20;
if(j==0x20)
{
dataR[count] <<=1;
dataR[count] |=1;
}
else dataR[count] <<=1;
j=0;
}
PORTD= 0xFF;
count++;
}
return 0;
}



void SPIwrite(unsigned char add)
{
unsigned char x=0x03,i,j,data=0,count=0;
PORTD= 0xEF;
PORTC= 0x00;
for(i=0;i<=7;i++)
{
j=x>>7 & 0x01;
if(j==1) PORTC |=0x02;
else PORTC &=0xFD;
x=x<<1;
PORTC &= 0xFE;
delayms(1);
PORTC |= 0x01;
delayms(1);
}
for(i=0;i<=7;i++)
{
j=add>>15 & 0x01;
if(j==1) PORTC |=0x02;
else PORTC &=0xFD;
add=add<<1;
PORTC &= 0xFE;
delayms(1);
PORTC |= 0x01;
delayms(1);
}
count=0;
while(count<10)
{
dataS[count]=count;
data=dataS[count];
for(i=0;i<=7;i++)
{
j=data>>7 & 0x01;
if(j==1) PORTC |=0x02;
else PORTC &=0xFD;
data=data<<1;
PORTC &= 0xFE;
delayms(1);
PORTC |= 0x01;
delayms(1);
}
PORTD= 0xFF;
count++;
}

}


this hardware setup
https://obrazki.elektroda.pl/45_1179399877.jpg
 

atmega interfacing spi eeprom

From a quick read through your code, a couple of issues pop out. First, your SPI Read function issues a byte read opcode of 0x03. After sending this and the address, you attempt to read back ten characters. Since you gave it a byte opcode, it will only give you back a single character, not ten. Also, you are mixing decimal and hex numbers quite a bit. I try to stay permanently in hex mode. For example, you are attempting to read ten characters, not 16 that hex 0x10 would produce.

In your SPI Write routine, you again seem to be using the same opcode as the SPI Read. This cannot be. The opcode is what tells the EEPROM what operation you are going to perform. The opcode on the datasheet that I looked at for writes is 0x02, not the 0x03 shown in your code. These opcodes should not be "magic numbers" of 0x02 or 0x03 buried in your code. These should be #define constants at the top of the code or in a header file. This makes checking and correcting things like opcode errors easy and quick.

My best advice is to spend some time in simulation. Use either the Atmel AVR Studio or the VMLAB tools and plot out the clock, cs and data waveforms. Compare these to the datasheet and fix all the issues before trying to run it on hardware. VMLAB can be found at

**broken link removed**

They even have some peripherial parts. I do not know if they have an SPI EEPROM, but if they do you could even get readback data from the simulator.
 
25c04 spi

thank you banjo
after i rectified two errors(you mentioned) it is working
thanks a lot
keep in touch
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top