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

PIC24 SPI

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







PIC24 SPI
PostPosted: Mon Jul 27, 2009 3:29 pm     Reply with quote

I'm trying to setup a software SPI connection to M25PE20 external flash.
spi pin selects:
Code:
#pin_select SDI1 = PIN_D9
#pin_select SDO1 = PIN_D8
#pin_select SCK1OUT = PIN_D10
#pin_select SS1OUT = PIN_B9
#use spi(SPI1, MASTER, SAMPLE_FALL, bits=8, STREAM=SPIA)


In my main:
Code:
int i;
char arr[10];
char arr2[10];
init_device();

setup_spi(SPI_MASTER | SPI_CLK_DIV_64);

arr[0]=0x06;  //enable write
arr[1]=0x0A;  //write command
arr[2]=0x00;  //address part1
arr[3]=0x00;  //address part2
arr[4]=0x01;  //address part3
arr[5]='H';
arr[6]='E';
arr[7]='L';
arr[8]='L';
arr[9]='O';

output_low(PIN_B9);  //chip select
for(i=0;i<10;i++) spi_write(arr[i]);  //write to flash
output_high(PIN_B9); 

delay_ms(10);

arr[0]=0x03;  //read command
arr[1]=0x00;  //address part1
arr[2]=0x00;  //address part2
arr[3]=0x01;  //address part3

output_low(PIN_B9);  //chip select
for(i=0;i<4;i++) spi_write(arr[i]);  //send read command
for(i=0;i<5;i++)  arr2[i]=spi_read(0);  //read back first 5 characters

fputs(arr2,USER);  //print string


I can't tell if anything is working in this code portion. When I print the string from flash it prints all nulls.
CRH
Guest







PostPosted: Mon Jul 27, 2009 3:33 pm     Reply with quote

I forgot to mention:
I'm using a PIC24FJ256GB106 with the PCD compiler from CCS
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 27, 2009 4:58 pm     Reply with quote

Quote:

#use spi(SPI1, MASTER, SAMPLE_FALL, bits=8, STREAM=SPIA)

In my main:
setup_spi(SPI_MASTER | SPI_CLK_DIV_64);

You should not mix different methods of setting up the SPI module.
I suggest that you get rid of the #use spi() statement and just use
the setup_spi() only. Also, in your setup_spi() statement, you should
specify the SPI Mode. According to the M25PE20 data sheet, it uses
modes 0 or 3. See page 10. (Mode 0 = 0,0 and Mode 3 = 1,1).
http://www.numonyx.com/Documents/Datasheets/M25PE20_10.pdf

Here is a thread about configuring the setup_spi() function:
http://www.ccsinfo.com/forum/viewtopic.php?t=31594
CRH
Guest







PostPosted: Mon Jul 27, 2009 5:46 pm     Reply with quote

SPI_XMIT_L_TO_H is not valid on the PIC24, what would you recommend using instead?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 27, 2009 6:15 pm     Reply with quote

You're right. The PCD manual only lists SPI_L_TO_H and SPI_H_TO_L
as options. That reflects that CKE bit in the SSP control register.
They don't appear to allow any control over the CKP bit, which controls
the idle state of the SCLK signal.

I don't have the PCD compiler, so I can't do any of my normal analysis
on the problem. I probably can't help too much more.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Jul 28, 2009 1:26 am     Reply with quote

There's a previous thread on PIC24 hardware SPI http://www.ccsinfo.com/forum/viewtopic.php?t=38491

My suggestion is to use spi_read() for read and write action, as shown in the examples. It's working perfectly in my applications, e.g. with serial SPI flash memory.
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