|
|
View previous topic :: View next topic |
Author |
Message |
boris
Joined: 29 Nov 2007 Posts: 15 Location: Hungary
|
Trouble with 25LC256 |
Posted: Thu Jun 26, 2008 8:48 am |
|
|
Hi!
I've created a circuit that uses a 25LC256 SPI EEPROM. My problem is that it seems I can write data to the EEPROM, but when I try to read it, the EEPROM SO pin stays in HIGH IMPEDANCE mode. I tried to change the "SPI_CLK_DIV_16" to "SPI_CLK_DIV_4", samle the signal at the end, etc, but nothing worked so far.
The code I use:
Code: |
#include "main.h"
#define EEPROM_SELECT PIN_A2
char adat;
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_16|SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
while(1)
{
puts( " *************************** " );
puts( " * Boris Technologies * " );
puts( " *************************** " );
delay_ms(1000);
output_high(EEPROM_SELECT);
output_low(EEPROM_SELECT);
spi_write(0x06); //Set the write enable latch (enable write operations)
output_high(EEPROM_SELECT);
output_low(EEPROM_SELECT);
spi_write(0x02); //write command
spi_write(0x00); //address low
spi_write(0x00); //address high
spi_write(0x66); //data to write
output_high(EEPROM_SELECT);
delay_ms(10);
output_low(EEPROM_SELECT);
spi_write(0x03); //read command
spi_write(0x00); //address low
spi_write(0x00); //address high
adat = spi_read();
output_high(EEPROM_SELECT);
printf("data: %u\n\r",adat);
output_low(EEPROM_SELECT);
spi_write(0x05); //Read STATUS register
adat = spi_read();
output_high(EEPROM_SELECT);
printf("status reg: %u\n\r",adat);
}
}
|
the main.h contains:
Code: |
#include <16F88.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc
#FUSES PUT //Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOIESO //Internal External Switch Over mode disabled
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8,FORCE_SW)
|
And I've created a simlation with Proteus, the results:
The circuit:
Thanks for the help! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 26, 2008 11:02 am |
|
|
Your program to interface to the eeprom is just a bunch of inline code.
You should write it as a driver, with routines that are called to init the
eeprom, and to read from it, and to write to it. If you write it as a
driver and put it in a separate file, then the code is re-usable for all
future projects. You can just "#include" it in your next project.
See the 25LC640 hardware SPI driver in this post for an example:
http://www.ccsinfo.com/forum/viewtopic.php?t=28199&start=1
Also, look closely at your usage of the spi_read() function. In CCS,
you need to give that function a parameter (usually 0x00) so that the
compiler will generate code to create the SPI clock signal during the
read operation. Without the parameter, there is no clock, and there is
no read. See the link above for an example. |
|
|
boris
Joined: 29 Nov 2007 Posts: 15 Location: Hungary
|
|
Posted: Thu Jun 26, 2008 12:26 pm |
|
|
Hi PCM programmer!
I made a driver to read and write the eeprom, but it didn't work, so I narrowed down the code to a few lines to test what's wrong.
I use CCS v4.074 and the help says exactly:
Quote: | If this device is the master then either do a SPI_WRITE(data) followed by a SPI_READ() or do a SPI_READ(data). These both do the same thing and will generate a clock. If there is no data to send just do a SPI_READ(0) to get the clock. |
So based on the help my code should work, but I try what you suggested.
Thanks! |
|
|
|
|
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
|