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

write_eeprom...error

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



Joined: 28 Apr 2008
Posts: 6

View user's profile Send private message

write_eeprom...error
PostPosted: Mon Apr 28, 2008 11:42 am     Reply with quote

Hi to all,
this is a subroutine for writing in eeprom:
Code:

boolean Write_int_eep(int *buffprt, int n_byte, int address)
{
   byte b;
   disable_interrupts(GLOBAL);
   for(;n_byte>0;n_byte--,buffprt++,address++)
   {
      b=*buffprt;
      if(read_eeprom(address)!=b)
         write_eeprom(address,b);
         if(read_eeprom(address)!=b) //errore in scrittura
         {
            enable_interrupts(GLOBAL);
            return false;
         }
   }
   enable_interrupts(GLOBAL);
   return true;
}

why it does not work?
the read_eeprom works perfectly but the write_eeprom does not write anything.
The chip is 18f252.
If I insert, for example, this code..... write_eeprom(0x10, 0x55)....at the beginning of the code (in main) the byte 0x55 is written correctly
Question Question Question
Best regards.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 28, 2008 11:45 am     Reply with quote

Post a test program that calls this function. Show all #include, #fuses,
and #use statements. Show all variable declarations. The program
must be compilable with no errors. Also show the printf statement
that displays the result.


Post your compiler version.
micro65



Joined: 28 Apr 2008
Posts: 6

View user's profile Send private message

PostPosted: Mon Apr 28, 2008 12:20 pm     Reply with quote

thanks for your answer
Code:

......
......
#include <DS1307.c>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
......
......
#include <18F252.h>
#device ICD=TRUE
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES PROTECT                  //Code protected from reads
#FUSES NOOSCSEN                 //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES DEBUG                    //Debug mode for use with ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOCPD                    //No EE protection
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table read
......
......
//DEFINIZIONI
#define  SINCRO   '%'   //carattere sincronismo
#define  SPACE    ' '
#define  CR       0x0D  //carriage return
#define  LF       0x0A  //line feed
#define  TRUE     1
#define  FALSE    0
#define  MAX_COLONNE    48 //massime colonne di led
#define  RX_BUFFER_SIZE 65 //30
#define  DECIMALE  0x40     //primo led dal basso acceso
#define  SEPARATORE 0       //colonna che separa due cifre
#define  VAL_TIMEOUT  5   //circa 5 secondi
#define  CLK_VIS  PIN_A0 //Clock per acquisizione dato
#define  STRB_VIS PIN_A1 //Strobe per caricamento dati
#define  EN_VIS   PIN_A2 //Enable pin
#define  RES_VIS  PIN_A3 //Reset pin
//////////////////////////
#define  DIR_485  PIN_A5//stabilisce in 485 se in Tx o Rx (in 422 sempre in RX)

//corrispondenza locazioni in eeprom
#define  BAUD_RX  0      //In eeprom interna locazione 0 mem. Baud rate
                         /* value 0 = 2400
                            value 1 = 4800
                            value 2 = 9600
                            value 3 = 19200 */
#define  DECIMALI  2   
#define  SI_ORA    4   
#define  UM        6     
#define  NOSOVRAC  8   
#define  SCRITTA   0x20 

//VARIABILI
static unsigned long cTimeOut;       //timeout per TMR0
static unsigned long cTimeOut1;     //timeout per TMR1
static unsigned char cRxBuffer[RX_BUFFER_SIZE]; //buffer seriale
static unsigned char cVisBuffer[MAX_COLONNE];   //buffer visualizzazione
static unsigned char cStr1[5]={"SET1"};//per programmazione
static unsigned char cStr2[5]={"SET2"};//per programmazione
static unsigned char cStr3[5]={"SET3"};//per programmazione
static unsigned char cStr4[5]={"SET4"};//per programmazione
static unsigned char cStr5[5]={"SET5"};//per programmazione
static unsigned int *cRxBufferprt;  //puntatore
static unsigned int *cBuffGenprt;  //puntatore Buffer gnerico
static unsigned char cCount; //conteggio generico
static unsigned char cDecimal; //numero decimali
static unsigned char cReceive; //Byte in ricezione
static unsigned char cGen;    //per uso generale
static unsigned char cRiferimenti;
static unsigned char c_UM[2];

#ROM 0x00F00000 = {0x01, 0x03, 0x01, "oz", 0x00} //inizializzazione eeprom (baud rate 4800, decimali = 0....)
#ROM 0x00F00020 = {"******************************"}

I think it is sufficient
Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 28, 2008 12:25 pm     Reply with quote

That's not what I wanted. I want to see a test program that calls
the Write_int_eep() function. I don't need to see all those #define
statements and static variables that are not related to the problem.
Only put code that is related to the problem. Also, your posted code
is not compilable.

Here's an example of a test program.
http://www.ccsinfo.com/forum/viewtopic.php?t=32722&start=3
micro65



Joined: 28 Apr 2008
Posts: 6

View user's profile Send private message

PostPosted: Mon Apr 28, 2008 12:36 pm     Reply with quote

this code calls Write_int_eep() function:
Code:

separate void GestProg()
{
   if((cRxBuffer[1]=='S')&&(cRxBuffer[2]=='E')&&(cRxBuffer[3]=='T')&&(*(cRxBufferprt-1)==CR))
   {
      switch(cRxBuffer[4])
      {
         case('1'):
         if(Write_int_eep(&cRxBuffer[5],60,SCRITTA))
            printf("OK scritta\r");
         else
            printf("KO scritta\r");
         cRxBuffer[0]=NULL;
         cRxBuffer[1]=NULL;
         *(--cRxBufferprt)=NULL;
         break;
         
         case('2'):
         if(Write_int_eep(&cRxBuffer[5],2,UM))
            printf("OK unita' misura\r");
         else
            printf("KO unita' misura\r");
         cRxBuffer[0]=NULL;
         cRxBuffer[1]=NULL;
         *(--cRxBufferprt)=NULL;
         break;
       
      }
   }
}


bye
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 28, 2008 12:38 pm     Reply with quote

I didn't get a test program or the compiler version, so I'm giving up.
micro65



Joined: 28 Apr 2008
Posts: 6

View user's profile Send private message

PostPosted: Mon Apr 28, 2008 1:02 pm     Reply with quote

the compiler version is 4.065
ckielstra



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

View user's profile Send private message

PostPosted: Mon Apr 28, 2008 3:17 pm     Reply with quote

I looked into your problem too and agree with PCM Programmer: Post a test program!

A small program that shows your problem. The program must be complete, i.e. including all required #fuses, include files, etc. so we can copy / paste the code into our compiler. Make the program small, not larger than what fits on a single screen and remove everything that is not required.

We know you will have to put some effort in creating such a test program but we ask this for some special reasons:
- From your description it looks like the problem is in how you call the function.
- When creating the test program it is very likely you will find the problem yourself.
- A complete test program saves us a lot of time. We do help the people here in our spare time and only pick the fun questions. The easier you make it for us the quicker and better help you will get.
micro65



Joined: 28 Apr 2008
Posts: 6

View user's profile Send private message

PostPosted: Tue Apr 29, 2008 12:08 pm     Reply with quote

ok, sorry but I did not understand.
However I found the problem.
The problem is only in Debug mode con icd-u (version firmware 1.39),
normally everything works perfectly.
Indeed in debug mode the following code works only in part
Code:

case('6'):   
        cRxBuffer[0]=NULL;
        cRxBuffer[1]=NULL;
        *(--cRxBufferprt)=NULL;
        cRxBuffer[0x2c]=NULL;
        cRxBuffer[0x2f]=NULL;
        cRxBuffer[0x34]=NULL;
        cRxBuffer[0x37]=NULL;
        cRxBuffer[0x3A]=NULL;
        day = atoi(&cRxBuffer[0x2A]);
        break;

cRxBuffer[0]=NULL;
cRxBuffer[1]=NULL;
*(--cRxBufferprt)=NULL;
are reset to zero

cRxBuffer[0x2c]=NULL;
cRxBuffer[0x2f]=NULL;
cRxBuffer[0x34]=NULL;
cRxBuffer[0x37]=NULL;
cRxBuffer[0x3A]=NULL;
remain unchanged.

Why?
Thanks
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