View previous topic :: View next topic |
Author |
Message |
sindyvirgo
Joined: 15 Jan 2009 Posts: 8
|
About 25LC080b SPI eeprom on 18F4620 |
Posted: Wed May 20, 2009 10:43 pm |
|
|
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
|
|
Posted: Wed May 20, 2009 11:53 pm |
|
|
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
|
|
Posted: Fri Jul 27, 2012 4:04 am |
|
|
i tested this code didn't work |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Jul 27, 2012 4:35 am |
|
|
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??? |
|
|
semmoor
Joined: 09 May 2012 Posts: 46 Location: KSA
|
|
Posted: Fri Jul 27, 2012 5:48 am |
|
|
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??? |
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. |
|
|
|