View previous topic :: View next topic |
Author |
Message |
Prefekt
Joined: 21 Oct 2010 Posts: 85
|
25LC640 on PIC18F2525 |
Posted: Thu Jul 02, 2015 5:40 am |
|
|
I want store 2345 bytes in EEPROM 25LC640.
Before I have used the 93C66 without problem. But the 93C66 was too small.
The only data that I receive from the EEPROM is 0.
Here is my code:
Code: |
#include <18F2525.h>
#device ADC=10
#define FOSC 40000000
#fuses NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, H4
#use delay(clock=FOSC)
#define EEPROM_SELECT PIN_B4
#define EEPROM_CLK PIN_B5
#define EEPROM_DI PIN_C5
#define EEPROM_DO PIN_C4
#use rs232(stream=CONTROL, baud=115200,parity=N,xmit=PIN_C3,rcv=PIN_B0,bits=8, ERRORS)
#include <25640.c>
void main(void)
{
delay_ms(1000);
fprintf(CONTROL, "Start\r");
delay_ms(1000);
int8 s;
init_ext_eeprom();
for(int16 i=0; i<2345; i++)
{
write_ext_eeprom(i,88);
}
for(int16 j=0; j<2345; j++)
{
s=read_ext_eeprom(j);
fprintf(CONTROL, "%d",s);
}
} |
Compiler Version: 5.032
what's wrong?
Last edited by Prefekt on Thu Jul 02, 2015 7:25 am; edited 1 time in total |
|
|
Prefekt
Joined: 21 Oct 2010 Posts: 85
|
|
Posted: Thu Jul 02, 2015 7:24 am |
|
|
Now I have found this driver here in forum.
Code: | #ifndef EEPROM_SELECT
#define EEPROM_SELECT PIN_C2
#define EEPROM_CLK PIN_C3
#define EEPROM_DI PIN_C5
#define EEPROM_DO PIN_C4
#endif
#define EEPROM_ADDRESS long int
#define EEPROM_SIZE 8192
void init_ext_eeprom()
{
output_high(EEPROM_SELECT);
setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 );
}
//--------------------------------
int1 ext_eeprom_ready(void)
{
int8 data;
output_low(EEPROM_SELECT);
spi_write(0x05);
data = spi_read(0);
output_high(EEPROM_SELECT);
return(!bit_test(data, 0));
}
//--------------------------------
void write_ext_eeprom(EEPROM_ADDRESS address, BYTE data)
{
while(!ext_eeprom_ready());
output_low(EEPROM_SELECT);
spi_write(0x06);
output_high(EEPROM_SELECT);
output_low(EEPROM_SELECT);
spi_write(0x02);
spi_write(address >> 8);
spi_write(address);
spi_write(data);
output_high(EEPROM_SELECT);
}
//--------------------------------
BYTE read_ext_eeprom(EEPROM_ADDRESS address)
{
int8 data;
while(!ext_eeprom_ready());
output_low(EEPROM_SELECT);
spi_write(0x03);
spi_write(address >> 8);
spi_write(address);
data = spi_read(0);
output_high(EEPROM_SELECT);
return(data);
} |
I have changed the PIN's on my board., but I get no results, only '0' |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Thu Jul 02, 2015 7:54 am |
|
|
You have the WP line high on the chip?.
The driver you have found does correctly set the write enable, but this will only work, if the hardware write protection is off. |
|
|
Prefekt
Joined: 21 Oct 2010 Posts: 85
|
|
Posted: Thu Jul 02, 2015 8:40 am |
|
|
@Ttelmah
Thank you for your hint.
PIN 7 was soldered on my board but the junction was not correct. With your hint, I found the error :-)
Thanks
Volker |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Thu Jul 02, 2015 11:21 am |
|
|
I looked through the posted driver, and it looked 'right', so then thought 'what else'. |
|
|
|