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

Memory device problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
John Travolta
Guest







Memory device problem
PostPosted: Thu Jul 21, 2005 4:23 am     Reply with quote

Hello guys, Question
I am usin a serial SPI flash memory(M25P80)(ST Micro) to connect to a PIC18F452.

Here's my code which so far is not workin.

#if defined(__PCH__)
#include <18F452.h>
#device ICD=TRUE
#fuses HS,NOWDT,NOPROTECT,NOLVP,BROWNOUT,STVREN,PUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#use fixed_io(b_outputs=PIN_B1)
#use fixed_io(c_outputs=PIN_C3,PIN_C5)
#priority ext, rtcc, rda
#endif

#define PIC_SS PIN_A2 //PIC18F452's SPI
#define PIC_SDO PIN_C5 // PINS
#define PIC_SDI PIN_C4
#define PIC_SCK PIN_C3
//........................................................................................................void sys_init();
void flash_read_id(void);
//........................................................................................................
void flash_read_id(void){
output_low(PIC_SS);
printf("%X",spi_read(0x9f));
printf("%X",spi_read(0));
printf("%X",spi_read(0));
output_high(PIC_SS);
}
//..............................................................................................................
void init_flash() {
short int i;

output_low(PIC_SDO); //Initialization routine.
output_low(PIC_SCK);
output_low(PIC_SS);
output_float(PIC_SDI);
i=input(PIC_SDI); //Read Once.

setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4);

output_low(PIC_SS);
printf("%X",spi_read(0x55)); //Write and Read Once again!!
output_high(PIC_SS);
}
//.......................................................................................................
void main ()
{
int i;
printf("\n\rIt ain't workin' man !!..\n\r");
sys_init(); // Setting TRIS;
init_flash(); // Initializing FLASH;

while (TRUE){
output_high(PIC_SS);
delay_us(10); // HOLD IT HIGH FOR SOME TIME BEFORE output_low(PIC_SS); //SELECTING THE CHIP
spi_write(10101011); //Control word to read ID.
printf("%2X,%2X,%2X\n\r",spi_read(0),spi_read(0),spi_read(0));
output_high(PIC_SS);
delay_ms(1000);
flash_read_id(); // Repeat the read ID process.
}
}
//..................................................................................................
void sys_init(){
set_tris_c(0b10010000);
set_tris_a(0);
}


//.......................................................................................................



Please Help !! Rolling Eyes
I am using PCWH 3.228



tHanKs iN adVAncE Wink
carlosma



Joined: 24 Mar 2004
Posts: 53
Location: Portugal

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Thu Jul 21, 2005 12:19 pm     Reply with quote

what kind of trouble have?
The serial comunication work?
John Travolta
Guest







Memory Device Problem
PostPosted: Thu Jul 21, 2005 9:06 pm     Reply with quote

Hello,

The problem seens to be the memory device is not responding to any of the control words that i write into it. The SDI pin of the PIC is always low. I can see some pulses on the SDO pin of the PIC. I'm also using 5v to 3v level converters using voltage dividing circuits.


What shopuld i do next ??
John Travolta
Guest







Memory Device Problem
PostPosted: Thu Jul 21, 2005 9:11 pm     Reply with quote

Hello,

The problem is that the memory chip is not responding to any of the commands that i write into it. I can see some pulses on the SDO pin of the PIC, but the SDI pin of the PIC is always low. I'm also using voltage dividers to convert 5v to 3v. What is the problem????
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 21, 2005 9:40 pm     Reply with quote

There appears to be a driver for it here. He calls it the "MP25P80".
The driver starts about half-way down the page:
http://www.kd7lmo.net/picobeacon_source.html
John Travolta
Guest







Memory Device Problem
PostPosted: Sun Jul 24, 2005 10:18 pm     Reply with quote

Hello PCM programmer,

Thank you so much for the Link. I got the driver and made some modifications before adding to my code. But I'm sorry to say that it does not work.

It is like that the problem is not with the software(I think 'coz i tried so many drivers.). Is there any hardware specificatons for the SPI communication?? Previously i had done SPI master-slave communcation between two PIC's without much trouble. But somehow i cannot run this particular device(M25P80). The thing is the SDO pin of the Memory device is always low. What do you think might be the problem ?

My connection is

PIC-SDO-----------> M25P80 SDI
PIC-SDI------------> M25P80 SDO
PIC-SCK-----------> M25P80 SCK
PIC-PIN_A3--------> M25P80 SS
The HOLD, Write Protect Pins of the M25P80 is pulled high. I am using an LF version of the PIC.

Please Help.

tHanKs iN adVAncE Wink
John Travolta
Guest







Memory Device Problem
PostPosted: Sun Jul 24, 2005 10:19 pm     Reply with quote

Hello PCM programmer,

Thank you so much for the Link. I got the driver and made some modifications before adding to my code. But I'm sorry to say that it does not work.

It is like that the problem is not with the software(I think 'coz i tried so many drivers.). Is there any hardware specificatons for the SPI communication?? Previously i had done SPI master-slave communcation between two PIC's without much trouble. But somehow i cannot run this particular device(M25P80). The thing is the SDO pin of the Memory device is always low. What do you think might be the problem ?

My connection is

PIC-SDO-----------> M25P80 SDI
PIC-SDI------------> M25P80 SDO
PIC-SCK-----------> M25P80 SCK
PIC-PIN_A3--------> M25P80 SS
The HOLD, Write Protect Pins of the M25P80 is pulled high. I am using an LF version of the PIC.

Please Help.

tHanKs iN adVAncE Wink
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 24, 2005 11:58 pm     Reply with quote

Quote:
#include <18F452.h>
#device ICD=TRUE
#fuses HS,NOWDT,NOPROTECT,NOLVP,BROWNOUT,STVREN,PUT

I'm also using voltage dividers to convert 5v to 3v.
I am using an LF version of the PIC.

Since you have a LF PIC, then you can it at +3.3v.
According to the 18F452 data sheet, it can run at 20 MHz at +3.3v.
When you have both the PIC and the MMC at 3.3v, then you
can get rid of the voltage dividers. You can eliminate any
problems that may be caused by them. At least, you could
do this while testing the code for the MMC, and then maybe
put the PIC back to +5v later. I don't know if your ICD
works with the PIC running at 3.3v -- you'll have to check that.

Also, if you run the PIC at 3.3v, you need to change the BROWNOUT
fuse to BORV20. Example:
#fuses HS,NOWDT,NOPROTECT,NOLVP,BORV20,STVREN,PUT



Quote:
PIC-PIN_A3--------> M25P80 SS

#define PIC_SS PIN_A2 //PIC18F452's SPI

Here you have two versions of your program. The SS pin
is on A3 in one of them, and it's on A2 in the other.
Does your program match the connections on your board ?
Which pin is the correct one, A2 or A3 ?
John Travolta
Guest







Memory Device Problem
PostPosted: Thu Jul 28, 2005 8:38 pm     Reply with quote

Hello PCM Programmer,

Thank you so much for your input. Now i am not using the voltage dividers but directly connecting the LF version to the M25P80 memmory chip. But i am using the ICD-U40 and it shows the verification results dialog box whenever trying to program at 3volts, with a few exceptions where it can program correctly.


Is it not possible to use ICD-U40 to program at 3V ??
Thanks again.


tHanKs iN adVAncE Wink
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 28, 2005 9:06 pm     Reply with quote

Quote:
Is it not possible to use ICD-U40 to program at 3V ??

Here is a thread from the CCS Debuggers/Programmers forum
which explains using the ICDU-40 at 3.3v:

http://www.ccsinfo.com/forum/viewtopic.php?t=20395

You'll notice there is a comment about bulk erase.
What this means is, DO NOT set the PROTECT fuse when running
at 3.3v. You can't erase it at 3.3v. You can only erase it when
the PIC is running at 5v.
John Travolta
Guest







Memory Device Problem
PostPosted: Fri Jul 29, 2005 9:29 pm     Reply with quote

Laughing
Thanks again PCM_programmer, for your help. I can now run the ICD at 3.3 volt with the memory device also. But still occasionally i get problems programming.

Regarding the memory chip(M25P80) the data that i read from the device (after successful write operation) gets corrupted. I am doing an erase operation before writing to the M25P80. But still when i read the data back, sometimes or say most of the times, the data returned is corrupted, even if you reading as little as 10 or 15 bytes also.

Is there anything that i can do to alleviate this problem ?? I cannot find anything in it's datasheet. Thank You.


tHanKs iN adVAncE Wink
John Travolta
Guest







Memory Device Problem
PostPosted: Wed Aug 10, 2005 1:11 am     Reply with quote

Hello again,

I have a problem that my flash device cannt work with the PIC running at 5v usin levl converters. I use 5.6kOhm and 3.7kOhm resistors 2 do the level shifting. I dont wan to use the LF version of the PIC. I have to run the PIC at higher freq.


Can anybody tell me why this does not work ???




tHanKs iN adVAncE Wink
Ttelmah
Guest







PostPosted: Wed Aug 10, 2005 3:54 am     Reply with quote

A pair of resistors, is not really an adequate level shifter. Depending on the frequencies involved, there may be significant attenuation of the edges on signals, (espcially with the relatively large values being used)and you still have to handle the shift the other way. The SDI input, is a Schmitt input, and requires an input voltage 0f 0.7Vdd before it will be seen as a logic '1'. Look at a proper level shifter, to have any hope of things being reliable.
For the 'down' shifter, a single resistor, and a clamp diode to the 3v rail, is a 'better' way to go. For the up shifter, active components are really needed (though you might just be able to make to work, by using a diode to make the output behave as if it was a open-collector drive, and adding a pull-up resistor to 5v. If the '3v' rail is 3.3v, then the pin will go up to about 3.9v, which might work - it is though a 'bodge'...).

Best Wishes
John Travolta
Guest







Memory Device Problem
PostPosted: Wed Aug 10, 2005 5:21 am     Reply with quote

Thanks Ttelmah for that, I'll try the diode-resistor pair for down converters and use pull-up transistors for up converters and hope things become more reliable. Thanks.
John Travolta
Guest







Memory Device Problem
PostPosted: Thu Aug 11, 2005 4:25 am     Reply with quote

Hello Ttelmah, i think i got your concept of 'down' converters wrong! I tried using one with 3.3v zener diode, but that failed to work. Can you be more specific about the 'down' converters please ??? For 'up' converters, i am using the BC547 pullups. Will that do ??


tHanKs iN adVAncE Wink
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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