|
|
View previous topic :: View next topic |
Author |
Message |
Eros Guest
|
PIC16F877 SPI to 25LC640 EEPROM |
Posted: Thu Mar 28, 2002 9:12 pm |
|
|
Hi,
My name is Eros
I face the problem on the 25lc640 EEprom
I use The program list on the OLD CCS C COMPILER USER EXCHANGE title:PIC16F877 SPI to 25LC640 EEPROM(able to use the find to search)to do my Eeprom library file and I just modify a bit coz I m using portA5 as the chip select of 25LC640 EEPROM and he is using portC1.
Here is my main program and include file
//Main:
#include<16f877.h>
#fuses xt,noprotect,nowdt,put,brownout,nolvp
#use delay(clock=4000000)
#INCLUDE<25lc640.C>
#include <lcd.c>
main()
{
BYTE VALUE, ADDRESS_HIGH, ADDRESS_LOW;
SETUP_PORT_A(NO_ANALOGS);
SET_TRIS_A(0);
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16 );
output_high(EEPROM_cs);
LCD_INIT();
ADDRESS_HIGH=0X00;
ADDRESS_LOW=0x00;
VALUE=0xab;
WRITE_EXT_EEPROM(ADDRESS_HIGH,ADDRESS_LOW,VALUE);
PRINTF(LCD_PUTC,"addr : \%X\%X \%X",ADDRESS_HIGH,ADDRESS_LOW,value);
PRINTF(LCD_PUTC,"\naddr : \%X\%X \%X",ADDRESS_HIGH,ADDRESS_LOW,READ_EXT_EEPROM(ADDRESS_HIGH,ADDRESS_LOW));
}
//my include file(modify from OLD CCS C COMPILER
//USER EXCHANGE ):
#define EEPROM_CS_PIN PIN_A5 // chip select pin of eeprom
#define EEPROM_SCK PIN_C3
#define EEPROM_SI PIN_C5
#define EEPROM_SO PIN_C4
// general defines
#define EEPROM_READ_INSTRUCTION 0x03 // instruction to read data from memory
#define EEPROM_WRITE_INSTRUCTION 0x02 // instruction to write data to memory
#define EEPROM_WREN_INSTRUCTION 0x06 // instruction for "write enable sequence"
#define EEPROM_WRDI_INSTRUCTION 0x04 // instruction for "write disable sequence"
#define EEPROM_RDSR_INSTRUCTION 0x05 // instruction to read eeprom status register
#define EEPROM_WRSR_INSTRUCTION 0x01 // instruction to write eeprom status register
#IFNDEF EEPROM_CS
#define EEPROM_CS EEPROM_CS_PIN
#ENDIF
// prototypes
void Write_ext_eeprom(byte address_high, byte address_low, byte data);
byte Read_ext_eeprom(byte address_high, byte address_low);
void Write_ext_eeprom_status(byte data);
byte Read_ext_eeprom_status();
void Write_ext_eeprom(byte address_high, byte address_low, byte data) {
output_low(EEPROM_CS); // enable eeprom node
spi_write(EEPROM_WREN_INSTRUCTION); // send Write Enable Sequence
output_high(EEPROM_CS); // setting CS high will set write enable latch
output_low(EEPROM_CS);
spi_write(EEPROM_WRITE_INSTRUCTION); // send write instruction
spi_write(address_high); // send write address
spi_write(address_low);
spi_write(data); // write data
output_high(EEPROM_CS); // disable eeprom node
delay_ms(6); // internal write cycle time
}
void Write_ext_eeprom_status(byte data) {
output_low(EEPROM_CS); // enable eeprom node
spi_write(EEPROM_WREN_INSTRUCTION); // send Write Enable Sequence
output_high(EEPROM_CS); // setting CS high will set write enable latch
output_low(EEPROM_CS);
spi_write(EEPROM_WRSR_INSTRUCTION); // send write instruction
spi_write(data); // write status
output_high(EEPROM_CS); // disable eeprom node
}
byte Read_ext_eeprom(byte address_high, byte address_low) {
byte data;
output_low(EEPROM_CS); // enable eeprom node
spi_write(EEPROM_READ_INSTRUCTION); // send read instruction
spi_write(address_high); // send read address
spi_write(address_low);
spi_write(0); // write dummy byte to force data
data = spi_read(); // read data
output_high(EEPROM_CS); // disable eeprom node
return(data);
}
byte Read_ext_eeprom_status() {
byte data;
output_low(EEPROM_CS); // enable eeprom node
spi_write(EEPROM_RDSR_INSTRUCTION); // send read instruction
spi_write(0); // write dummy byte to force data
data = spi_read(); // read status
output_high(EEPROM_CS); // disable eeprom node
return(data);
}
//Output On The LCD display:
ADDR : 0000 AB
ADDR : 0000 FF (always get ff whatever the address are?)
There is nothing wrong on the LCD.c and the connection
and for the program I just change the
#define EEPROM_CS_PIN PIN_c1 to #define EEPROM_CS_PIN PIN_A5
Can you help me ..
Thank Q
Best regard
Eros
Sl1978@hotmail.com
___________________________
This message was ported from CCS's old forum
Original Post ID: 3502 |
|
|
Bruce R. Knox Guest
|
Re: PIC16F877 SPI to 25LC640 EEPROM |
Posted: Fri Mar 29, 2002 4:00 am |
|
|
Eros:
I believe you need to set the CKE bit in SSPSTAT when you use that part - I am using it and have it set. I did not analyze the rest of your code, but I know that if you put the following after your spi init you'll have a better chance:
#ASM
MOVLW 0X40 // SET CKE TO ONE
MOVWF 0X94 // BIT 6 IN SSPSTAT
#ENDASM
I remember having a similar problem before I read the data sheets and determined that CKE should be set.
Good luck.
Bruce
:=Hi,
:=My name is Eros
:=I face the problem on the 25lc640 EEprom
:=I use The program list on the OLD CCS C COMPILER USER EXCHANGE title<img src="http://www.ccsinfo.com/pix/forum/tongue.gif" border="0">IC16F877 SPI to 25LC640 EEPROM(able to use the find to search)to do my Eeprom library file and I just modify a bit coz I m using portA5 as the chip select of 25LC640 EEPROM and he is using portC1.
:=
:=Here is my main program and include file
:=
:=//Main:
:=
:=#include<16f877.h>
:=#fuses xt,noprotect,nowdt,put,brownout,nolvp
:=#use delay(clock=4000000)
:=#INCLUDE<25lc640.C>
:=#include <lcd.c>
:=
:=main()
:={
:=
:= BYTE VALUE, ADDRESS_HIGH, ADDRESS_LOW;
:= SETUP_PORT_A(NO_ANALOGS);
:= SET_TRIS_A(0);
:= setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16 );
:= output_high(EEPROM_cs);
:= LCD_INIT();
:=
:= ADDRESS_HIGH=0X00;
:= ADDRESS_LOW=0x00;
:= VALUE=0xab;
:=
:= WRITE_EXT_EEPROM(ADDRESS_HIGH,ADDRESS_LOW,VALUE);
:= PRINTF(LCD_PUTC,"addr : \%X\%X \%X",ADDRESS_HIGH,ADDRESS_LOW,value);
:= PRINTF(LCD_PUTC,"\naddr : \%X\%X \%X",ADDRESS_HIGH,ADDRESS_LOW,READ_EXT_EEPROM(ADDRESS_HIGH,ADDRESS_LOW));
:=}
:=
:=//my include file(modify from OLD CCS C COMPILER
:=//USER EXCHANGE ):
:=
:=#define EEPROM_CS_PIN PIN_A5 // chip select pin of eeprom
:=#define EEPROM_SCK PIN_C3
:=#define EEPROM_SI PIN_C5
:=#define EEPROM_SO PIN_C4
:=
:=
:=// general defines
:=#define EEPROM_READ_INSTRUCTION 0x03 // instruction to read data from memory
:=#define EEPROM_WRITE_INSTRUCTION 0x02 // instruction to write data to memory
:=#define EEPROM_WREN_INSTRUCTION 0x06 // instruction for "write enable sequence"
:=#define EEPROM_WRDI_INSTRUCTION 0x04 // instruction for "write disable sequence"
:=#define EEPROM_RDSR_INSTRUCTION 0x05 // instruction to read eeprom status register
:=#define EEPROM_WRSR_INSTRUCTION 0x01 // instruction to write eeprom status register
:=
:=#IFNDEF EEPROM_CS
:=#define EEPROM_CS EEPROM_CS_PIN
:=#ENDIF
:=
:=
:=// prototypes
:=void Write_ext_eeprom(byte address_high, byte address_low, byte data);
:=byte Read_ext_eeprom(byte address_high, byte address_low);
:=void Write_ext_eeprom_status(byte data);
:=byte Read_ext_eeprom_status();
:=
:=
:=void Write_ext_eeprom(byte address_high, byte address_low, byte data) {
:=
:=output_low(EEPROM_CS); // enable eeprom node
:=
:=spi_write(EEPROM_WREN_INSTRUCTION); // send Write Enable Sequence
:=output_high(EEPROM_CS); // setting CS high will set write enable latch
:=output_low(EEPROM_CS);
:=
:=spi_write(EEPROM_WRITE_INSTRUCTION); // send write instruction
:=spi_write(address_high); // send write address
:=spi_write(address_low);
:=
:=spi_write(data); // write data
:=
:=output_high(EEPROM_CS); // disable eeprom node
:=delay_ms(6); // internal write cycle time
:=}
:=
:=
:=void Write_ext_eeprom_status(byte data) {
:=
:=output_low(EEPROM_CS); // enable eeprom node
:=
:=spi_write(EEPROM_WREN_INSTRUCTION); // send Write Enable Sequence
:=output_high(EEPROM_CS); // setting CS high will set write enable latch
:=output_low(EEPROM_CS);
:=
:=spi_write(EEPROM_WRSR_INSTRUCTION); // send write instruction
:=
:=spi_write(data); // write status
:=
:=output_high(EEPROM_CS); // disable eeprom node
:=}
:=
:=
:=byte Read_ext_eeprom(byte address_high, byte address_low) {
:=
:=byte data;
:=
:=output_low(EEPROM_CS); // enable eeprom node
:=
:=spi_write(EEPROM_READ_INSTRUCTION); // send read instruction
:=spi_write(address_high); // send read address
:=spi_write(address_low);
:=
:=spi_write(0); // write dummy byte to force data
:=
:=data = spi_read(); // read data
:=
:=output_high(EEPROM_CS); // disable eeprom node
:=
:=return(data);
:=}
:=
:=
:=byte Read_ext_eeprom_status() {
:=
:=byte data;
:=
:=output_low(EEPROM_CS); // enable eeprom node
:=
:=spi_write(EEPROM_RDSR_INSTRUCTION); // send read instruction
:=
:=spi_write(0); // write dummy byte to force data
:=
:=data = spi_read(); // read status
:=
:=output_high(EEPROM_CS); // disable eeprom node
:=
:=return(data);
:=}
:=
:=//Output On The LCD display:
:=ADDR : 0000 AB
:=ADDR : 0000 FF (always get ff whatever the address are?)
:=
:=There is nothing wrong on the LCD.c and the connection
:=and for the program I just change the
:=#define EEPROM_CS_PIN PIN_c1 to #define EEPROM_CS_PIN PIN_A5
:=
:=Can you help me ..
:=Thank Q
:=
:=Best regard
:=Eros
:=Sl1978@hotmail.com
___________________________
This message was ported from CCS's old forum
Original Post ID: 3506 |
|
|
Charlie U Guest
|
Re: PIC16F877 SPI to 25LC640 EEPROM |
Posted: Fri Mar 29, 2002 3:02 pm |
|
|
This is to both Eros and Bruce: Check a previous post that I submitted regarding the SPI (link attached below). I think you are both encountering the same problem that I had with the SPI.
Essentially, CCS broke the SPI setup when they changed from version 2.XX to 3.XX. If you use only the SPI_H_to_L and SPI_L_to_H you can not set up the SPI to operate in either mode 0,0 or 1,1.
If you add the new parameters:
#define SPI_SAMPLE_AT_END 0x8000
#define SPI_XMIT_L_TO_H 0x4000
you can get the other modes (I think).
Look at my previous post and try to use the Hex values that are listed for either mode 0,0 or 1,1 and this might help.
Let us know how you do with this.
Charlie U.
___________________________
This message was ported from CCS's old forum
Original Post ID: 3521 |
|
|
Bruce R. Knox Guest
|
Re: PIC16F877 SPI to 25LC640 EEPROM |
Posted: Fri Mar 29, 2002 4:10 pm |
|
|
Charlie:
When I first tried to use the lc326/640 with the compiler, I was moving over from an assembler version of a driver. I was using Standard SPI Mode 0,0 (CKP = 0, CKE = 1) there, and it worked great. I noticed, when I had the same 0xff problem that Eros was having, that the compiler had not set it up that way (CKE was 0), leaving me in Mode 0,1 causing the 320/640 r/w operations to fail. Rather than analyzing the compiler's actions, I just stuck in the asm statements that set CKE to one, and then it started working.
Personally, I find the CCS compiler to be really good at helping build a structured, easy to read program. There are some problems and limitations, but I try to remember that this is a PIC, not a 68040 or PowerPC! I have found that by keeping complex structures and arrays to a minimum, it seems to be a good, time saving tool. And I have to admit, I was pretty impressed that it handled a really complex return statement, using floats, that used a three term regression to linearize a thermocouple. I really didn't expect that to work!
Anyway, I'm sure there are plenty of ways to skin the SPI cat - I am interested to hear how Eros resolved his problem!
Happy programming,
Bruce
:=This is to both Eros and Bruce: Check a previous post that I submitted regarding the SPI (link attached below). I think you are both encountering the same problem that I had with the SPI.
:=
:=Essentially, CCS broke the SPI setup when they changed from version 2.XX to 3.XX. If you use only the SPI_H_to_L and SPI_L_to_H you can not set up the SPI to operate in either mode 0,0 or 1,1.
:=
:=If you add the new parameters:
:=
:=#define SPI_SAMPLE_AT_END 0x8000
:=#define SPI_XMIT_L_TO_H 0x4000
:=
:=you can get the other modes (I think).
:=
:=Look at my previous post and try to use the Hex values that are listed for either mode 0,0 or 1,1 and this might help.
:=
:=Let us know how you do with this.
:=
:=Charlie U.
___________________________
This message was ported from CCS's old forum
Original Post ID: 3523 |
|
|
Yasser ELZOGHBY Guest
|
Help me |
Posted: Sat Mar 30, 2002 9:42 am |
|
|
Dear Sir
do you have p16f873.h file?
I lost it
Please help me to find it
Thanks in Advance
Yasser
___________________________
This message was ported from CCS's old forum
Original Post ID: 3534 |
|
|
Eros Guest
|
Re: PIC16F877 SPI to 25LC640 EEPROM |
Posted: Tue Apr 02, 2002 1:50 am |
|
|
Thank for helping me..
i alredy solve the problem..
the problem was when u using the spi_read or spi_write function from the ccs u can't (may be can but i dun't know )redefine the sdo and the sdi pin coz it is using the hardware spi and the pin alredy fixed rc5--sdo rc4--SDI; so there was wrong connection on my circuit :>
and for Yasser ELZOGHBY ,I have send file that you want to your Email :>
best regard
Eros
___________________________
This message was ported from CCS's old forum
Original Post ID: 3565 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|