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

93C66C EPROM and SPI

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



Joined: 24 Jul 2012
Posts: 116

View user's profile Send private message

93C66C EPROM and SPI
PostPosted: Mon May 06, 2019 2:28 pm     Reply with quote

working with a 93C66C EPROM
datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21795E.pdf

Simple chip, but I still seem to be SPI challenged.
Not looking for great speed hence the delays in the code. It will be used to store config information and serial numbers etc.

Getting 0x0000 for a response. O-scope probing yields confidence in the SCLK and SDI lines but nothing coming out of the chip.

my driver is:
Code:

/* ******************** DEFINES ******************* */

#DEFINE   START_CMD      0X01
#DEFINE EWEN_CMD      0X00
#DEFINE EWDS_CMD      0X00
#DEFINE EWEN_ADDRESS   0XC0
#DEFINE EWDS_ADDRESS    0X00
#DEFINE WRITE_CMD      0X01
#DEFINE READ_CMD      0X01
#DEFINE EECS         PIN_B1
#DEFINE EEPROM_DELAY   5      // 5mS EEPROM delay more than enough time for the sequencing delays.


/* ********************  FUNCTIONS  ******************** */

void EEPROM_INIT() {
// Initialize the EEPROM

   output_low(EECS);

}  // end EEPROM_INIT()

void EEPROM_EWDS_WRITE() {
// The EWDS sequence is SB EWDS OPCODE ADDRESS
// SB is 1
// EWDS OPCODE is 00
// ADDRESS is 00000000  (0x00)

   output_high(EECS);

   spi_xfer(EE_SPI, (START_CMD | EWDS_CMD), 8);    // send Start bit and EWDS
   delay_ms(EEPROM_DELAY);
   spi_xfer(EE_SPI, EWDS_ADDRESS, 8);              // send EWEN address
   delay_ms(EEPROM_DELAY);

   output_low(EECS);

} // end EEPROM_EWDS_WRITE()

void EEPROM_EWEN_WRITE() {
// The EECS line is still high when this function is exited.
// The EWEN sequence is SB EWEN OPCODE ADDRESS
// SB is 1
// EWEN OPCODE is 00
// ADDRESS is 11000000  (0xC0)


   output_high(EECS);
    delay_ms(EEPROM_DELAY);
   spi_xfer(EE_SPI, (START_CMD | EWEN_CMD), 8);       // send Start bit and EWEN
   delay_ms(EEPROM_DELAY);
   spi_xfer(EE_SPI, EWEN_ADDRESS, 8);                // send EWEN address
   delay_ms(EEPROM_DELAY);


} // end EEPROM_EWEN_WRITE()

void EEPROM_write_16b(int16 data, int8 wr_address) {
   // writes the 16 bit data to the 8 bit address
   // This function only writes one 16bit word of data.
   
   

    EEPROM_EWEN_WRITE();                     // Wake up the EEPROM
    delay_ms(EEPROM_DELAY);
    spi_xfer(EE_SPI, (START_CMD | WRITE_CMD), 8);          // send Start bit and WRITE_CMD
   delay_ms(EEPROM_DELAY);
   spi_xfer(EE_SPI, wr_address, 8);         // send write address
   delay_ms(EEPROM_DELAY);
   spi_xfer(EE_SPI, data, 16);              // send data
    delay_ms(EEPROM_DELAY);
    EEPROM_EWDS_WRITE();                      // park the EEPROM
    delay_ms(EEPROM_DELAY);

   output_low(EECS);   

} // end EEPROM_write_16b()


int16 EEPROM_read_16b(int8 rd_address) {
   // reads the 16bit data located at the 8 bit address
    // this function only reads on 16bit word of data
    // per the 93C66C datasheet, a dummy '0' preceeds the 16bit data
   
    int16 rd_data=0;

   output_high(EECS);

    delay_ms(EEPROM_DELAY);
    spi_xfer(EE_SPI, (START_CMD | READ_CMD), 8);           // send READ_CMD
   delay_ms(EEPROM_DELAY);
    spi_xfer(EE_SPI, rd_address, 8);         // send read address
   delay_ms(EEPROM_DELAY);
    rd_data = spi_xfer(EE_SPI, rd_data, 16);    // read data 17 = 1 dummy zero + 16b data
    delay_ms(EEPROM_DELAY);

    output_low(EECS);

    return rd_data;

} // end EEPROM_read_16b()


and my simple test program is:

Code:



#device PIC18f87k22

#fuses INTRC_IO, NOWDT, PUT, NOBROWNOUT, NOMCLR

#use delay(crystal=15M, clock=60M)
#use rs232(UART1, baud=57600, STREAM=SERIAL, errors)
#USE SPI(MASTER, MODE=0, SPI2, STREAM=EE_SPI, Baud= 2000000, FORCE_HW)
#include <18F87K22.h>
#include "93LC66.H"

int16 write_data = 0;
int16 read_data = 0;

int8 write_address = 0x00;
int8 read_address = 0x00;

void main() {

   EEPROM_INIT();

    write_address = 0;
    write_data = 0x04d2;

   while(1) {

      EEPROM_write_16b(write_data, write_address);      // write a 16bit word

      read_data = EEPROM_read_16b(read_address);          // read a 16bit word

        fprintf(SERIAL,"read_data = %Lx\n\r",read_data);    // should be 04D2

        delay_ms(1000);



   }  // end continuous loop

}  // end main


not found what I am missing here. My ORG pin is tied to 5V so enabled for 16bit data.

CCS 5.064
PIC18F87K22 running at 60MHz
MPLAB 8.91
Windows 10
PCM programmer



Joined: 06 Sep 2003
Posts: 20717

View user's profile Send private message

PostPosted: Mon May 06, 2019 4:16 pm     Reply with quote

Look at the CCS driver file, 9356spi.c for an example. It uses the older
spi_write() method, but you could test it with your hardware to prove that
the hardware is correct. (And it does use hardware SPI).
Then you could modify it to use the spi_xfer() method, if you want to.
beaker404



Joined: 24 Jul 2012
Posts: 116

View user's profile Send private message

PostPosted: Tue May 07, 2019 8:42 am     Reply with quote

Is there additional setup required to use SPI2 on the 18F87K22 ? My SCLK is running but nothing on the DI and DO.
I have the PIC pins disconnected from the EEPROM.
beaker404



Joined: 24 Jul 2012
Posts: 116

View user's profile Send private message

PostPosted: Tue May 07, 2019 9:09 am     Reply with quote

changed SPI2 from FORCE_HW to FORCE_SW and it works now.
Thoughts?
Ttelmah



Joined: 11 Mar 2010
Posts: 14542

View user's profile Send private message

PostPosted: Tue May 07, 2019 10:59 am     Reply with quote

General thing, make sure you turn off the other peripherals on these
pins. The PSP, and the external memory interface.
However have to query your clock setting. The chip does not support
15MHz from the internal oscillator. 16MHz, 8MHz, bit not 15MHz....
beaker404



Joined: 24 Jul 2012
Posts: 116

View user's profile Send private message

PostPosted: Tue May 07, 2019 11:44 am     Reply with quote

not sure I understand your question on the oscillator, I am using a 15MHz crystal to get my 60MHz clock rate.
I have a 16MHz crystal to get 64MHz but have not installed it yet.
Ttelmah



Joined: 11 Mar 2010
Posts: 14542

View user's profile Send private message

PostPosted: Tue May 07, 2019 12:38 pm     Reply with quote

Your fuses have:

INTRC_IO

Internal RC oscillator, not crystal.
beaker404



Joined: 24 Jul 2012
Posts: 116

View user's profile Send private message

PostPosted: Tue May 07, 2019 12:54 pm     Reply with quote

Ah yes, an obvious oversight on my part.
I assume HSM is correct for a 15MHz external crystal running the PIC at 60MHz?
Ttelmah



Joined: 11 Mar 2010
Posts: 14542

View user's profile Send private message

PostPosted: Wed May 08, 2019 12:17 am     Reply with quote

Yes.

HSM, PLLEN
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