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

eeprom write problem

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



Joined: 12 Jun 2006
Posts: 19

View user's profile Send private message

eeprom write problem
PostPosted: Mon Jul 03, 2006 1:54 pm     Reply with quote

Hi everybody

1.-I wrote a small routine to write an array to a 24256 memory.
The first time the routine is called it works perfectly.
but the second time, the routine hangs up waiting for the write ack.

This is the code

Code:

writeExtMem(unsigned int16 address, char *data, unsigned int16 length) {
     #DEFINE PAGE_SIZE=64
   int8 i;
   int1 STATUS;
 
  if (length == 0)
    return;

  i2c_start();
  status=i2c_write(EEPROM_WRITE);
   while(status==1)
   ;
  status=i2c_write(address>>8);
   while (status==1)
   ;
  status=i2c_write(address);
   while (status==1)
   ;

  for (i=0; i < LENGTH; i++) // EEProm can only write 64 bytes at a time
   status=i2c_Write(*Data++);
   while (status==1)
   ;
    i2c_stop();
   i2c_start();
   status=i2c_write(EEPROM_WRITE);
      while(status==1)
         {
         i2c_start();
         status=i2c_write(EEPROM_WRITE);   
      }
}


what is the diference between the slow and fast mod of the i2c?

Regards
Ysaac
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Mon Jul 03, 2006 2:32 pm     Reply with quote

Code:
  status=i2c_write(EEPROM_WRITE);
   while(status==1) ;


if i2c_write() returns 1, then you will sit here forever. You need to rethink this. I think that you intended to do something like:

Code:
 
  while (1)
  {
    status=i2c_write(EEPROM_WRITE);
    if (status !=1)
      break;
  }


Your code is full of this. I would only check when you are addressing the eeprom. It doesn't make much sense any where else. If you get a failure any other place, then you need to repeat the entire process.
ysaacb



Joined: 12 Jun 2006
Posts: 19

View user's profile Send private message

PostPosted: Tue Jul 04, 2006 5:15 am     Reply with quote

Dear Mark
I made the correction you suggest, but I still have the same problem: when the main program, call the this function the second time it hungs up trying to accses the EEprom i.e.:

status=i2c_write(EEPROM_WRITE);

this is the corrected one:

Code:

writeExtMem(unsigned int16 address, char *data, unsigned int16 length) {
     #DEFINE PAGE_SIZE=64
   int8 i;
   int1 STATUS;
 
  if (length == 0)
    return;

  i2c_start();
   while (1)
  {
    status=i2c_write(EEPROM_WRITE);
    if (status !=1)
      break;
  }
  status=i2c_write(address>>8);
  status=i2c_write(address);
  for (i=0; i < LENGTH; i++) // EEProm can only write 64 bytes at a time
   status=i2c_Write(*Data++);
    i2c_stop();
   i2c_start();
   status=i2c_write(EEPROM_WRITE);
      while(status==1)
         {
         i2c_start();
         status=i2c_write(EEPROM_WRITE);   
      }
}


and this is the main program that read a text file an send it to the eeprom



Code:

#include <18f452.h>
#device icd=true
#use delay(clock=20000000)
#fuses HS,NOWDT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stream=,bits=8)
#use i2c(master,sda=pin_C4,scl=pin_C3,force_HW)
#include <stdio.h>
#include <lcdd.c>
#include <string.h>
#include <I2C_24256_YB.h>


#define BUFFER_SIZE 80
#define PAGE_SIZE 64
#define LAST_CHAR '?'
char BUFFER[BUFFER_SIZE],BUFFER_OUT[BUFFER_SIZE];
char BUFFER_PAGE[PAGE_SIZE];
char char_out;
int1 ONLY_ONE;

int8 next_in,count_ch,LAST_NEXT_IN;
int16 EE_pointer;


#int_rda
void rx_serial_data()
   {
   byte count_end,t;
   byte comp_last_4;
   char ch;

   ch=getc();
   buffer[next_in] =ch; // get the data(single character) from serial port
   count_ch=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;

   }

void CLEAR_BUFFER_GSM()
   {
   memset(buffer,0,(next_in+1));
   next_in=0;
   }


void main ()
{
   boolean READY;
   
memset(buffer, 0, BUFFER_SIZE);
   ONLY_ONE=1;
   READY=TRUE;
   output_float(PIN_C4);
      output_float(PIN_C3);
      enable_interrupts(global);
   enable_interrupts(int_rda); // Enable 'receive data available' interrupt
      puts("ENVIE ARCHIVO");
   EE_pointer=0;
        while (BUFFER[count_ch]!=LAST_CHAR)
      {
      if (next_in!=PAGE_SIZE)
         ;
      else
         {
         strncpy(BUFFER_PAGE,BUFFER,next_in);
         CLEAR_BUFFER_GSM();
           WriteExtMem(EE_pointer,BUFFER_PAGE,PAGE_SIZE);
         delay_ms(6);
            EE_pointer+=PAGE_SIZE;   
         }
      }
      WriteExtMem(EE_pointer,BUFFER,next_in);
      delay_ms(6);
      EE_pointer=0;
      CLEAR_BUFFER_GSM();
      
      DO
         {
         ReadExtMem(EE_pointer,&CHAR_OUT,ONLY_ONE);
         delay_ms(10);
         ++EE_pointer;
         putc(char_out);
         }
      WHILE(char_out!=LAST_CHAR);

      while(1)
         ;
}


Regards Ysaac
wgalaugher



Joined: 10 Jan 2011
Posts: 18

View user's profile Send private message

PostPosted: Sat Aug 20, 2011 4:21 pm     Reply with quote

Did this code ever get resolved; it looked like it was left in limbo.
I think this could, with a few mods, serve as the basis for what I am trying to do.
I'm trying to read a text file containing 132 four digit numbers (int16).
The code has to be buffered to handle the slow write of the eeprom.

Below is a sample of test data that would be read by the pic ie 18F2620 with a 24LC128

Code:

10
20
30
40
50
60
70
80
90
100
110
200
210
220
230
240
250
260
270
280
290
300
310
320
330
340
350
360
370
380
390
400
410
420
430
440
460
470
480
490
500
510
520
530
540
550
560
570
580
590
600
610
620
630
640
650
660
670
680
690
700
710
720
730
740
750
760
770
780
790
800
810
820
830
840
850
860
870
880
890
900
910
920
930
940
950
960
970
980
990
1000
1010
1020
1030
1040
1050
1060
1070
1080
1090
1100
1110
1120
1130
1140
1150
1160
1170
1180
1190
1200
1210
1220
1230
1240
1250
1260
1270
1280
1290
1300
1310
1320
1330
1340
1350
1360
1370
1380
1390
1400
1410




There is so much written that it is hard to pick the correct solution
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Aug 20, 2011 5:31 pm     Reply with quote

Quote:
The code has to be buffered to handle the slow write of the eeprom.


That's where FRAM comes in...
_________________
Google and Forum Search are some of your best tools!!!!
ckielstra



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

View user's profile Send private message

PostPosted: Sun Aug 21, 2011 4:56 am     Reply with quote

I don't understand the problem at hand. The only thing your application is doing is reading, but this is a problem because the write speed is slow? Doesn't make sense to me.

For a new hardware design I would recommend using the afore mentioned FRAM. All the advantages of EEPROM but as quick as the PIC can handle it.
wgalaugher



Joined: 10 Jan 2011
Posts: 18

View user's profile Send private message

PostPosted: Sun Aug 21, 2011 9:06 am     Reply with quote

The use of Fram is terrific.


My first questions are:

Using Fram or eeprom

1. Can I use the code as is to read the text file and load the eeprom?

2. What if I don't have a page of data?
mutthunaveen



Joined: 08 Apr 2009
Posts: 100
Location: Chennai, India

View user's profile Send private message

pull ups
PostPosted: Sun Aug 21, 2011 9:44 pm     Reply with quote

Hey did you use pullup resistors for the data and clock pin of SPI?? (10K to +5V)
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