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

PIC24FJ128GA006 with a extern flash memory

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



Joined: 16 Feb 2012
Posts: 4

View user's profile Send private message

PIC24FJ128GA006 with a extern flash memory
PostPosted: Wed Feb 22, 2012 3:00 am     Reply with quote

Hello,

I am newbie with a 24FJ128GA006 PIC and I would like to know how I have to initialized the SPI in order to use it to send and received blocks of data from a SST25vf family's device.

I have used this line in order to declared the SPI params.
#USE SPI (MASTER, SPI1,BAUD=16000000,DO = PIN_F3,DI = PIN_F2,CLK = PIN_F6, MODE=0, BITS=8, STREAM=FLASH_STREAM)

Am I forgetting anything or not taking into account something?
I want to use the driver included in ccs and its functions, called sst25vf.c.

What I am exactly trying...

Code:


#include <24FJ128GA006.h>
#include <sst25vf.c>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //Crystal osc 16MHz,High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES DEBUG                    //Debug mode for use with ICD
#FUSES NOWRT                      //Program Memory Write Protected
#FUSES NOIESO//  #FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES NOJTAG   //JTAG disabled

#use delay(clock=32000000)

#define FLASH_STREAM SPI_1
#USE SPI (MASTER, SPI1,BAUD=16000000,DO = PIN_F3,DI = PIN_F2,CLK = PIN_F6, MODE=0, BITS=8, STREAM=FLASH_STREAM)


void main()
{
int aux;
int title;

ext_flash_init();//intialization of the comunication required
aux=0xF4;// a value which is going to be saved
ext_flash_write(0x000006, &aux,2);//writing in the flash
delay_ms(100);
ext_flash_read(0x000006,title,2);//reading from the flash the same direction
}



Could someone help me?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 3:45 am     Reply with quote

A SPI clock of 16 MHz isn't available with 16 MHz CPU clock. I don't know, if #use spi selects the highest available clock frequency instead.

According to the comments in the sst25 driver, write protection must be unlocked before writing to the device. Please check.
arritsas



Joined: 16 Feb 2012
Posts: 4

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 4:39 am     Reply with quote

FvM wrote:
A SPI clock of 16 MHz isn't available with 16 MHz CPU clock. I don't know, if #use spi selects the highest available clock frequency instead.

According to the comments in the sst25 driver, write protection must be unlocked before writing to the device. Please check.


Ok, I have replaced the baud parameter. And changed it in order to take the default one.

But, I am not sure if I understand what you are telling about the write protection, do I must included the ext_flash_protect() function when I start the application? And if it like this unlock all the memory?
Ttelmah



Joined: 11 Mar 2010
Posts: 19326

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 9:16 am     Reply with quote

I wouldn't explicitly select the IO pins. The syntax for #use SPI, is to _either_ specify the pins, _or_ use SPI1/SPI2, which automatically selects the corresponding hardware pins.
Unless you are using the stream parameter (which the library doesn't), I'd also not have a stream name. Particularly, since I'm not sure of having the name given as the stream name already #defined to something else.
The big one though is the write protection as Fvm points out. Look at the header of the driver:
"//// (Note that this flash protects all locations on power up) ////"

ext_flash_protect(FLASH_PROTECT_NONE);

needed after init, before doing anything else.

Best Wishes
Ttelmah



Joined: 11 Mar 2010
Posts: 19326

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 9:26 am     Reply with quote

Just as a comment, I'd also select explicitly a 'legal' clock rate. I'd not be _sure_ the compiler would know that 1/1 and 1/1 for primary and secondary prescalers is 'invalid' at 16MHz (table 15-1 data sheet), so select 8MHz, which is the fastest available rate.

Best Wishes
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