How to read and write EEPROM on 68HC08 with Cosmic compiler?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to read and write EEPROM on 68HC08 with Cosmic compiler?

2,978 Views
Kender
Contributor I

 

 

Folks,

 

I’m not new to microcontroller programming. But I’m very new to 68HC08 and the Cosmic compiler. I normally use PICs and CCS compiler.

 

What’s the correct way to read and write the EEPROM on 68HC08? As far as I understand, the Cosmic compiler allows pointers to EEPROM and Flash. I have tried reading with this:

Code:

 

     Code:

char* pEeprom = (char*)MAKE16(receive_buffer[0], receive_buffer[1]);   /* EEPROM location */ transmit_buffer[1] = *pEeprom;


 

 

I’m getting 0xFF from every EEPROM location. It’s a little suspicious, but it’s conceivable that the whole EEPROM is initialized with 0xFF

 

But after I write with this

Code:

 

 

 

Code:
char* pEeprom = (char*)MAKE16(receive_buffer[0], receive_buffer[1]);   /* EEPROM location */ *pEeeprom = receive_buffer[2];               /* actually write too EEPROM */


 
 

and then read it, I still get 0xFF. That’s clearly a problem. Could you look at my code and identify the errors?

 

To continue describing the same problem, the other parts of the code use the variables declared with @EEprom, as the only method of accessing EEPROM.  That approach works.  However, I need to write an R&D utility that would read/write the EEPROM based on the address, whether or not there is a variable declared at that address.  So, in my code I’m trying to do the following:

-         Receive 2 bytes through a serial port

-         Cast them into a pointer that would point to the EEPROM.  I.e. the pointer is between 0x0600 and 0x0DFF.  I’ve got this range from the memory map in the 68HC08’s datasheet.

-         Dereference the pointer to read or write

 

Do you think this approach can work?

 

Thanks,

Nick

 

P.S.  Is there a forum dedicated to Cosmic compiler?

Labels (1)
0 Kudos
Reply
5 Replies

1,041 Views
Kender
Contributor I
Here's an update.  I have received some encouraging answers from the Cosmic tech support.  See below
 
_________________________________________
 
Hi Nick,

This syntax (unsigned char @EEprom *peech; ) puts the pointer variable
itself
in RAM, but specifies that the data it points to is located in EEPROM.

Arithmetic operations with this kind of pointer are legal.  The code
you
gave below should work fine.

Regards,

John [support]

_____________________________________ 



John,

Thanks.  What you say sounds encouraging.  I was
missing @EEprom in the line that declares a pointer:

unsigned char @EEprom *peech;

However, you still have declared a variable with
@EEprom.  That's something I would like to avoid.

Are the arithmetic operations with the EEPROM pointer
legal?  Do you think, the following modified version
of your code could work:


Code:
/* Declarations */@eeprom unsigned char eech1 @0x0600; /* 0x0600 is theaddress of the 1st byte of the 1st EEPROM bank in68HC08 */unsigned char @eeprom *peech;unsigned int iOffset;unsigned char ch;/* Code inside some routine */eech1 = 75;peech = &eech1;peech += iOffset; /* arithmetic on a pointer. Assumethat (peech + iOffset) is still within EEPROM bank,but it's unknown what resides at that offset,  */ch = *peech;

 

Regards,
Nick
0 Kudos
Reply

1,041 Views
J2MEJediMaster
Specialist I
Consult App Note 2295 for the proper techniques for writing to Flash memory for the HC08 families. While the primary topic is programming Flash, it also explains programming EEPROM. The software for the programming code is located in AN2295SW.zip on this site. HTH.

---Tom
0 Kudos
Reply

1,041 Views
Kender
Contributor I

Thanks for the pointer to the app note.   I've downloaded the code  that comes with the app note, and it's mostly Assembly.  I couldn’t find C code for writing Flash or EEPROM (there's some high-level C code, though).  Do you know where it is?  I also couldn’t identify the compiler that the AN2295 C code is written for; is it CodeWarrior or Cosmic?

Cheers,

Nick

0 Kudos
Reply

1,041 Views
J2MEJediMaster
Specialist I
As I understand it, the Flash and EEPROM routines are written in assembly. The code was written for CodeWarrior tools.

---Tom
0 Kudos
Reply

1,041 Views
Kender
Contributor I

I hate to be so negative (almost like a teenager).  But the Assembly code doesn’t help me at all.  I don’t know the Freescale assembly, I don’t have time to learn it, and I don’t have a desire to learn it.

Is there a way to write to the EEPROM that used only C (Cosmic compiler) and avoids writing any Assembly code?

Best,

Nick

0 Kudos
Reply