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

About 25LC080b SPI eeprom on 18F4620

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



Joined: 15 Jan 2009
Posts: 8

View user's profile Send private message MSN Messenger

About 25LC080b SPI eeprom on 18F4620
PostPosted: Wed May 20, 2009 10:43 pm     Reply with quote

My SPI EEPROM can't work ...
Help me, please .... Orz !!

I use CCS function of spi_write, spi_read.
I want to write an ASCII word to EEPROM and read ASCII word from EEPROM.

But it can't work...
Code:

#include "C:\Documents and Settings\Chen Yang Li\My Documents\CCS\SPI_EEPROM_4620\spi_eeprom_4620.h"
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdlibm.h>
#include <string.h>
 
#define EEPROM_SELECT  PIN_A5     //CS
#define EEPROM_CLK     PIN_C3   //CLOCK
#define EEPROM_DI      PIN_C4   //Input
#define EEPROM_DO      PIN_C5   //Output
 
#define EEPROM_SIZE   1024
     
char SPI_Data;
 
 
#int_RDA
void  RDA_isr(void)
{
 rs_buff = getc();
 printf("%c",rs_buff);
}

#int_SSP
void  SSP_isr(void)
{
  output_low(EEPROM_SELECT);    
  spi_write(0x03);   
  spi_write(0x00);   
  spi_write(0x10);
   
  SPI_Data = spi_read(0x00 >> 8);
}
//------------------------------------------------------------------
void initial_eeprom()            
{
 output_high(EEPROM_SELECT);      
 output_low(EEPROM_DI);
 output_low(EEPROM_CLK);
}
//------------------------------------------------------------------

//------------------------------------------------------------------
void write_ext_Enb_eeprom()
{   
  output_low(EEPROM_SELECT);      //Select Device   
  spi_write(0x06);               //Enable OP code
  output_high(EEPROM_SELECT);      //Deselect Device

  output_low(EEPROM_SELECT);      //Select Device   
  spi_write(0x02);               //write OP code
  spi_write(0x00);              //High address
  spi_write(0x10);              //Low address
  spi_write('G');               //write ASCII 'G'
  output_high(EEPROM_SELECT);
}


void main()
{
 setup_adc_ports(NO_ANALOGS|VSS_VDD);
 setup_adc(ADC_OFF|ADC_TAD_MUL_0);
 setup_psp(PSP_DISABLED);
 setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
 setup_wdt(WDT_OFF);
 setup_timer_0(RTCC_INTERNAL);
 setup_timer_1(T1_DISABLED);
 //setup_timer_2(T2_DISABLED,0,1);
 //setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
 setup_comparator(NC_NC_NC_NC);
 //setup_vref(FALSE);

 enable_interrupts(INT_RDA);
 enable_interrupts(INT_SSP);
 enable_interrupts(GLOBAL);
 setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);
   
 printf("SPI Testing....");
 delay_ms(3000);
     
 initial_eeprom();
   
 for(;;)
   {      
     write_ext_Enb_eeprom();   
     printf("%i",SPI_Data); 
   }
   
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 20, 2009 11:53 pm     Reply with quote

Here is a hardware SPI driver that should work with the 25LC080B:
http://www.ccsinfo.com/forum/viewtopic.php?t=28199&start=1


Quote:
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);

You want to run the oscillator at 8 MHz. There is no reason to have
the "OSC_31250" parameter in there. Delete it.


Quote:

enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);

#int_SSP
void SSP_isr(void)
{
output_low(EEPROM_SELECT);
spi_write(0x03);
spi_write(0x00);
spi_write(0x10);

SPI_Data = spi_read(0x00 >> 8);
}

I don't see the reason for the SSP interrupts. Use the code shown in
the link that I posted above. Delete all the INT_SSP stuff.
semmoor



Joined: 09 May 2012
Posts: 46
Location: KSA

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

PostPosted: Fri Jul 27, 2012 4:04 am     Reply with quote

i tested this code didn't work
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Jul 27, 2012 4:35 am     Reply with quote

semmoor wrote:
i tested this code didn't work
This makes no sense to me...
Why are you testing a 3 years old code of which the original poster says it doesn't work??? Confused
semmoor



Joined: 09 May 2012
Posts: 46
Location: KSA

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

PostPosted: Fri Jul 27, 2012 5:48 am     Reply with quote

ckielstra wrote:
semmoor wrote:
i tested this code didn't work
This makes no sense to me...
Why are you testing a 3 years old code of which the original poster says it doesn't work??? Confused


No !! i didn't mean the code above, i meant the code on this link :
http://www.ccsinfo.com/forum/viewtopic.php?t=28199&start=1

written by pcmprogrammer that's why i was amazed, how come a code written by pcmprogrammer can't work? it never happened before.
but i'm really sure it might be something on my circuit.

thanks ckielstra.
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