CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

spi and 25lc512 problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
assaad



Joined: 09 Dec 2009
Posts: 37

View user's profile Send private message

spi and 25lc512 problem
PostPosted: Thu Aug 26, 2010 8:53 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 26, 2010 10:03 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 26, 2010 11:18 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 27, 2010 5:42 am     Reply with quote

Thank you, it is solved, there was problem in timing.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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