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 support@ccsinfo.com

SPI Can't work of PIC18452

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



Joined: 15 Jan 2009
Posts: 8

View user's profile Send private message MSN Messenger

SPI Can't work of PIC18452
PostPosted: Thu Jan 15, 2009 1:16 am     Reply with quote

Experiment board : Microchip App001
--------------------------------------------------------------------
I use SPI to write PIC and EEPROM (25LC160A)
Could you tell me how I should do ?
I have tried the following ways ...
--------------------------------------------------------------------

Code:
#define SPI_MODE_1  (SPI_L_TO_H)

setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_MODE_1|SPI_CLK_DIV_16);


void main()
{
//write to spi
output_low(CS);
SPI_write(0x06);
SPI_write(0x02);                  
spi_write(0x00);         
spi_write(0x10);                               
spi_write('A');
delay_us(100);       
output_high(CS);

//read from spi
output_low(pin_a5);                  
SPI_write(0x03);                             
spi_write(0x00);             
spi_write(0x10);                   
SPI_Msg = SPI_read();                                    
output_high(pin_a5);

if(spi_data_is_in())
{
   SPI_Msg = SPI_read();     
   printf("%c",SPI_Msg);
}
}

My procedure can't work, please help me !!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 15, 2009 2:59 am     Reply with quote

You problem is that you need a driver for the 25LC160A.

You have SPI mode 1 selected, but the data sheet says it uses
modes 0 or 3. Look at the timing diagram on page 5 on the left side:
Quote:
FIGURE 1-2: SERIAL INPUT TIMING

It gives those two modes (in binary notation). 25LC160A data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/21807D.pdf

Here's an example of a hardware SPI driver for the 25LC640.
I think it will work for the 25LC160A. Try it.
http://www.ccsinfo.com/forum/viewtopic.php?t=28199&start=1
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