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

PIC18F4580 and FM25C160

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



Joined: 02 Mar 2006
Posts: 9

View user's profile Send private message

PIC18F4580 and FM25C160
PostPosted: Wed May 17, 2006 11:28 am     Reply with quote

I'm trying to use the hardware SPI and the CCS spi_read() and spi_write() functions to interface with a FM25C160 FRAM.

here's what I've got:
Code:
setup_spi(SPI_MASTER | SPI_MODE_1_1 | SPI_CLK_DIV_4);


and these functions:
Code:
void write_FRAM(FRAM_ADDRESS address, BYTE data) {
   BYTE cmd[4];
   BYTE i;
   cmd[0] = WRITE;
   cmd[1] = (address>>8);
   cmd[2] = address;
   cmd[3] = data;

   output_low(memory_CS);
   spi_write(WREN);
   output_high(memory_CS);

   output_low(memory_CS);
   for(i=0; i<4; ++i) {
      spi_write(cmd[i]);
   }
   output_high(memory_CS);
}

BYTE read_FRAM(FRAM_ADDRESS address) {
   BYTE cmd[3];
   BYTE i,data;
   cmd[0] = READ;
   cmd[1] = (address>>8);
   cmd[2] = address;

   output_low(memory_CS);
   for(i=0; i<3; ++i) {
      spi_write(cmd[i]);
   }

   data = spi_read(0);
   output_high(memory_CS);
   return(data);
}


I can't detect anything happening. I try writing to an address - I can see the PIC clocking 5 bytes (WREN then WRITE op-codes, 2-byte address, byte of data), and the SDO from the PIC looks to be the correct data. I am bringing the CS high between the WREN and WRITE op-codes, as I understand is correct. When I try reading the same address I see the PIC clocking 4 bytes (the READ op-code, the 2-byte address, and the data), the first 3 on the SDO (from the PIC) are correct, but I see nothing on the SDI for the last byte.

As far as I can tell the connections are correct: /CS and /WP on the FRAM connected to the PIC, SO on the FRAM to SDI on the PIC, SI/FRAM to SDO/PIC, SCK/FRAM to SCK/PIC, /HOLD tied to +5, VDD and VSS on the FRAM connected.


Any ideas?
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Wed May 17, 2006 11:48 am     Reply with quote

What about the /WP line?
_________________
David
Joules



Joined: 02 Mar 2006
Posts: 9

View user's profile Send private message

PostPosted: Wed May 17, 2006 12:54 pm     Reply with quote

/WP line is tied to a pin on the PIC which I'm holding high (maybe I've just been looking at this too long, /WP is active low and prevents writes, is that saying if it's high it allows writes?).


If I'm reading the datasheet correctly it doesn't seem like it should matter anyhow, since /WP only prevents writing to the status register, not memory.

Thanks though!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 17, 2006 1:08 pm     Reply with quote

I would try using SPI Mode 0 because apparently Ramtron made
an older chip (FM25160) that doesn't support Mode 3. What if you somehow got the older chip ? It's safer to use Mode 0.

Also, this chip has internal block write protection bits in the Status
register. Have you enabled this by accident ?
Joules



Joined: 02 Mar 2006
Posts: 9

View user's profile Send private message

PostPosted: Thu May 18, 2006 8:26 am     Reply with quote

thaks for your help, I tried SPI_MODE_0_0, no luck there, I also tried adding this:

Code:

output_high(memory_WP);
output_low(memory_CS);
spi_write(WREN);
output_high(memory_CS);
delay_cycles(8);
output_low(memory_CS);
spi_write(WRSR);
spi_write(0);
output_high(memory_CS);


which I believe should set the block protection to none, and I still get nothing on the SO of the FRAM when I run the read function, though I really have no idea if the writes are working or not (it's possible that the write isn't working but the read is, but I'm getting 0 back because I never wrote anything to the memory, correct?).

I'm almost thinking bad chip - if it where a DIP I'd just try another one, with SOICs I want to be pretty sure before I swap.
Joules



Joined: 02 Mar 2006
Posts: 9

View user's profile Send private message

PostPosted: Thu May 18, 2006 8:37 am     Reply with quote

Got it working; just messing around with the setup_spi() function, I added SPI_SAMPLE_AT_END and it appears to be working.


thanks again for the help.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 18, 2006 1:33 pm     Reply with quote

What is the oscillator frequency on your PIC ?
I'd like to analyze the timing and find out why the sample-at-end
feature had to be enabled.
Joules



Joined: 02 Mar 2006
Posts: 9

View user's profile Send private message

PostPosted: Fri May 19, 2006 4:14 am     Reply with quote

oscillator is 16MHz.

I've also got an MCP4921 DAC using the SPI, that's not connected to the PICs SDI however.
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