View previous topic :: View next topic |
Author |
Message |
assaad
Joined: 09 Dec 2009 Posts: 37
|
spi and 25lc512 problem |
Posted: Thu Aug 26, 2010 8:53 am |
|
|
Hi again,
I am using 25lc512 eeprom with pic18f8722 and I just wrote a test program to write one byte to the eeprom and read it again but I have tried the whole day and no success. I wish anyone could guide me to a solution.
Problem: The spi bus usually hangs. Very few time it return with 0x00, can't write to eeprom, can't read to eeprom.
I know that spi bus deos not need pull up resistors but I have pulled up each sclk, sdi and sdo with 10k to vdd.
I will be thankful for any help with this issue.
Here is the code:
Code: |
/////////////////////
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_64); // init spi
////////////////////////////////////
output_h(0xd5); // enable eeprom
spi_write(0x06); // write enable eeprom
output_h(0xd0); // disable eeprom
output_h(0xd5); // enable eeprom
spi_write(0x02); // write command
spi_write(0x00); // high address
spi_write(0x00); // low address
spi_write(65); // write 65 to 0x0000
output_h(0xd0); //disable eeprom
/////////////////////////////////////////////////////////
output_h(0xd5); //enable eepom
spi_write(0x03); // read command
spi_write(0x00); // h_address
spi_write(0x00); // l_ adderss
data = spi_read(); // read to data
output_h(0xd0); // disable eeprom
|
Regards
Assaad |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu Aug 26, 2010 10:03 am |
|
|
First, tell us your actual connections. What pins have you got the SDO/SDI, CS, HOLD, WP, and CLK connected to?. What is your oscillator frequency?. etc. etc..
Are you sure about your SPI mode setting?. The overview sheet for the Holtek part:
<http://www.holtek.com/english/docum/memory/25lc512.htm>
Says it supports modes 0, and 3. You are currently setting the SPI to mode 1.
The 'standard' defines for these, are:
Code: |
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
|
Check the mode number the chip should have, and use these.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 26, 2010 11:18 am |
|
|
Quote: | output_h(0xd5); //enable eepom
spi_write(0x03); // read command
spi_write(0x00); // h_address
spi_write(0x00); // l_ adderss
data = spi_read(); // read to data
output_h(0xd0); // disable eeprom
|
The spi_read() function requires a parameter to generate a clock.
You need to make the clock (8 SCLK pulses) to get the data from
the slave. This is in the CCS manual. Usually, a parameter of 0x00
is used. Edit the statement shown in bold and add the 0x00 parameter.
If you still need help, then see this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=28199&start=1 |
|
|
assaad
Joined: 09 Dec 2009 Posts: 37
|
|
Posted: Fri Aug 27, 2010 5:42 am |
|
|
Thank you, it is solved, there was problem in timing. |
|
|
|