View previous topic :: View next topic |
Author |
Message |
tranz
Joined: 10 Feb 2007 Posts: 78
|
Amtel 25256 EEPROM problem |
Posted: Sun Aug 10, 2008 4:21 pm |
|
|
Hey guys,
I replaced my existing EEPROM with another EEPROM (amtel 25256) and changed the connections based on a working board, now it does not seem to work. The microcontroller is still 16F877A
The connections are as follows
PIN1-CS to PIN C1
PIN2- SO to PIN C5 - pulled up by 10k
PIN3- WP to Vcc
PIN4-GND
PIN5- SI to PIN C4
PIN6- SCK to PIN C3
PIN7-HOLD to Vcc
PIN8-Vcc
Vcc is 3.3v
The code used to test this eeprom is as follows:
Code: |
#include <16F877A.h>
//#include <25640.h>
#fuses HS,NOLVP,NOWDT,PUT
#use delay(clock=20000000)
#include <stdio.h>
#include "lcd2.c"
#define TRUE 1
#include "EEPROM.c"
void main()
{
BYTE d,c;
int b;
lcd_init();
init_ext_eeprom();//initializing EEPROM
while(1)
{
b = ext_eeprom_ready();
while(b==1)
{
write_ext_eeprom(0,0x01); //0 = start address, c= data
d = read_ext_eeprom(0);// Read the byte d from the address a
lcd_putc(d);
delay_ms(1000);
}
}}
|
the EEPROM header file is as follows
Code: |
#define EEPROM_SELECT PIN_C1 //changed
#define EEPROM_CLK PIN_C3 //changed
#define EEPROM_DI PIN_C4 //changed
#define EEPROM_DO PIN_C5 //changed
#ifndef EEPROM_ADDRESS
#define EEPROM_ADDRESS long
#endif
#byte SSPSTAT=0x94
#byte SSPCON=0x14
//Rest of it is the same as that in the header file.
|
Any suggestions?
Regards
Terry |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Aug 10, 2008 4:51 pm |
|
|
1. Why is the 25640.c driver file commented out ?
2. What is the Vdd voltage on the PIC ? If it's 3.3v, are you using
the "LF" version of the PIC ?
3. Why are SSPSTAT and SSPCON declared ? The CCS 25640.c
driver is a software SPI driver. It doesn't use hardware SPI. |
|
![](templates/subSilver/images/spacer.gif) |
tranz
Joined: 10 Feb 2007 Posts: 78
|
|
Posted: Sun Aug 10, 2008 4:57 pm |
|
|
Since I am using a different EEPROM I commented out the 25640.c file, the file I am using for the EEPROM is EEPROM.c
Which is the same as "AT25256.c" since I am using that EEPROM. |
|
![](templates/subSilver/images/spacer.gif) |
tranz
Joined: 10 Feb 2007 Posts: 78
|
|
Posted: Sun Aug 10, 2008 4:59 pm |
|
|
CORRECTION on Vcc its 5 V.
Sorry about that. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Aug 10, 2008 5:13 pm |
|
|
OK, now I understand.
Quote: | while(1)
{
b = ext_eeprom_ready();
while(b==1)
{ |
The write_ext_eeprom() routine in AT25256.c calls ext_eeprom_ready(),
so you shouldn't have to call it in your code.
Because you are writing 0x01 to the eeprom, assuming that you read it
back OK, you won't see "01" displayed on the LCD. It will be some
control character. If you want to see the actual hex value, then you
need to format it with printf and re-direct the output of printf to the LCD.
Example:
Code: | printf(lcd_putc, "\fValue= %2X", d); |
|
|
![](templates/subSilver/images/spacer.gif) |
tranz
Joined: 10 Feb 2007 Posts: 78
|
|
Posted: Sun Aug 10, 2008 5:21 pm |
|
|
I did the modifications on the code as suggested, but the compiler is not running past "write_ext_eeprom(0,0x01);"
As I debugged it further, it seems not to fulfill the condition "ext_eeprom_ready(); "
Suggestions? |
|
![](templates/subSilver/images/spacer.gif) |
tranz
Joined: 10 Feb 2007 Posts: 78
|
|
Posted: Mon Aug 11, 2008 8:33 am |
|
|
New results,
When the individual pins of the EEPROM are looked into via scope, the SCK is working, but SI and SO are high, no data is being sent or recieved on those lines.
Any Suggestions? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon Aug 11, 2008 10:11 am |
|
|
If you look at write_ext_eprom, you will see that it won't start the actual write, till the chip is 'ready'. If you look at the code for this, it drops the EEPROM_SELECT line, and then outputs the data bit for a status command, on EEPROM_DI, and clocks EEPROM_CLK. If these lines are not operating, something is wired wrong, or setup wrong in the configuration...
Disconnect everything from the PIC. You should see EEPROM_DI changing.
Other things. Though you talk about EEPROM.h, you don't show where this is included. Why have you renamed the standard driver?.
Code: |
#include <16F877A.h>
#fuses HS,NOLVP,NOWDT,PUT
#use delay(clock=20000000)
#include <stdio.h>
#include "lcd2.c"
#define TRUE 1
#define EEPROM_SELECT PIN_C1 //changed
#define EEPROM_CLK PIN_C3 //changed
#define EEPROM_DI PIN_C4 //changed
#define EEPROM_DO PIN_C5 //changed
#include "AT25256.c"
//The driver _automatically_ accepts pin definitions made before it.
void main() {
BYTE d,c;
int b;
lcd_init();
init_ext_eeprom();//initializing EEPROM
while(1) {
write_ext_eeprom(0,0x01); //0 = start address, c= data
d = read_ext_eeprom(0);// Read the byte d from the address a
lcd_putc(d);
delay_ms(1000);
}
}
|
The standard driver is written, so you just define the pins you want, and load it. It automatically uses your definitions.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
tranz
Joined: 10 Feb 2007 Posts: 78
|
|
Posted: Mon Aug 11, 2008 12:39 pm |
|
|
Thanks Ttelmah,
Yeah I used the original driver, and swapped the data lines and it worked.
Thanks again for the help.
Cheers |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
tranz
Joined: 10 Feb 2007 Posts: 78
|
|
Posted: Tue Aug 12, 2008 7:59 am |
|
|
Yeah, I know this time I got a bit confused with the MISO and MOSI thing wires.
Thanks again, sorry for the inconvenience caused.
Cheers |
|
![](templates/subSilver/images/spacer.gif) |
tranz
Joined: 10 Feb 2007 Posts: 78
|
|
Posted: Fri Aug 15, 2008 10:20 am |
|
|
Well I am facing a new problem with my amtel EEPROM, as the data gets stored I am incrementing the address, by 1.
The funny part is although the datasheet says I have 32,768 words/bytes to play with, the address counter stops at 255.
Code: |
void main()
{
byte c,x;
int b=0;
lcd_init();
init_ext_eeprom();//initializing EEPROM
c=fgetc(HOSTPC);
write_ext_eeprom(b, c);
printf(lcd_putc,"value=%2X ",c);
b=b+1;
do {
x=fgetc(HOSTPC);
write_ext_eeprom(b, x);
printf(lcd_putc,"\fvalue=%2X ",x);
b=b+1;
while(b==5120)
{
output_high(PIN_C2);
delay_ms(5000);
output_low(PIN_C2);
}
}while (1);
}
|
So based on this code, b should be incremented till 5120, and then it should blink an LED.
But the entire system just stops at b=255.
What am I doing wrong? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 15, 2008 10:34 am |
|
|
Download the CCS manual.
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Look at the table called "Basic and Special Types" on page 37.
(page 49 in the Acrobat reader).
Look at the size of the data types. Look at the small table just
below the big one, which shows how "C Standard Types" compare
to CCS data types. |
|
![](templates/subSilver/images/spacer.gif) |
tranz
Joined: 10 Feb 2007 Posts: 78
|
|
Posted: Fri Aug 15, 2008 11:05 am |
|
|
Yeah works with int16.
Thanks. |
|
![](templates/subSilver/images/spacer.gif) |
|