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

Problem 24FJ256GB110 and 25LC256

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



Joined: 13 Apr 2010
Posts: 23

View user's profile Send private message

Problem 24FJ256GB110 and 25LC256
PostPosted: Wed Oct 06, 2010 10:34 am     Reply with quote

Hello,
I have this problem using a 24FJ256GB110 and 25LC256



Code:


#ifndef EEPROM_SELECT

#define EEPROM_SELECT PIN_D12
#define EEPROM_CLK    PIN_G6
#define EEPROM_DI     PIN_G8
#define EEPROM_DO     PIN_G7

#endif

#define EEPROM_ADDRESS long int
#define EEPROM_SIZE    262144

void init_ext_eeprom() {
   output_high(EEPROM_SELECT);
   output_low(EEPROM_DI);
   output_low(EEPROM_CLK);
}

BOOLEAN ext_eeprom_ready() {
   BYTE cmd[1], i, data;

   cmd[0] = 0x05;                  //rdsr opcode

   output_low(EEPROM_SELECT);

   for(i=1; i<=8; ++i) {
      output_bit(EEPROM_DI, shift_left(cmd,1,0));
      output_high(EEPROM_CLK);   //data latches
      output_low(EEPROM_CLK);      //back to idle
   }

   for(i=1; i<=8; ++i) {
        output_high(EEPROM_CLK);   //data latches
        shift_left(&data,1,input(EEPROM_DO));
        output_low(EEPROM_CLK);  //back to idle
   }
   output_high(EEPROM_SELECT);
   return !bit_test(data, 0);
}

void write_ext_eeprom(EEPROM_ADDRESS address, BYTE data) {
   BYTE cmd[4];
   BYTE i;
   BYTE wren;
   wren=0x06;
   cmd[0]=data;
   cmd[1]=address;
   cmd[2]=(address>>8);
   cmd[3]=0x02;

   // Wait until the eeprom is done with a previous write
   while(!ext_eeprom_ready());

   output_low(EEPROM_SELECT);
   for(i=0; i<8; ++i)
   {
      output_bit(EEPROM_DI, shift_left(&wren,1,0));
      output_high(EEPROM_CLK);
      output_low(EEPROM_CLK);
   }
   output_high(EEPROM_SELECT);
   output_low(EEPROM_SELECT);
   for(i=0; i<32; ++i)
   {
      output_bit(EEPROM_DI, shift_left(cmd,4,0));
      output_high(EEPROM_CLK);
      output_low(EEPROM_CLK);
   }
   output_high(EEPROM_SELECT);
}

BYTE read_ext_eeprom(EEPROM_ADDRESS address) {
   BYTE cmd[3];
   BYTE i,data;
   cmd[0]=address;
   cmd[1]=(address>>8);
   cmd[2]=0x03;

   // Wait until the eeprom is done with a previous write
   while(!ext_eeprom_ready());

   output_low(EEPROM_SELECT);
   for(i=0; i<24; ++i)
   {
      output_bit(EEPROM_DI, shift_left(cmd,3,0));
      output_high(EEPROM_CLK);
      output_low(EEPROM_CLK);
   }
   for(i=0; i<8; ++i)
   {
      shift_left(&data,1,input(EEPROM_DO));
      output_high(EEPROM_CLK);
      output_low(EEPROM_CLK);
   }
   output_high(EEPROM_SELECT);
   return(data);
}




the program works, but sometimes there is an error in reading the EEPROM
how is it possible?

example:
about 10 times this routine 2-3 times only the right data!!

Code:
for(slot=0;slot<1000;slot++)
   {
    usb_cdc_putc(read_ext_eeprom(slot));
    delay_us(300);                     
   }


a few bytes are wrong!!!

I could not use the SPI ...
Embarassed


Thanks to all
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 06, 2010 12:20 pm     Reply with quote

I don't have the PCD compiler, so I can't help very much.
But, my suggestion is to prove that the SPI interface is the problem.
Change your test to the following:
Quote:

for(slot=0;slot<1000;slot++)
{
usb_cdc_putc((int8)slot);
delay_us(300);
}

This should display incrementing numbers from 0 to 255, several times.
If it fails, the problem is the CDC interface. If it works, the problem may
be in the SPI interface.
microlo75



Joined: 13 Apr 2010
Posts: 23

View user's profile Send private message

Solved
PostPosted: Fri Oct 08, 2010 11:25 pm     Reply with quote

With SPI work !!!!!

Thanks for reply

bye
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