IRSCI and Flash memory programming issue. - MC68HC908AP64

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

IRSCI and Flash memory programming issue. - MC68HC908AP64

1,336 Views
AlfaMaster
Contributor II

Hi.

 

I have a few problems.

I finnaly got the IRSCI working (echoing). Thanks.

But it ignores my code when i try to send bytes only.. ?

 

I have also done some testing on writing direct to the flash memory.

I followed the information in datasheet, but i'm not sure i'm doing it correct.

I will not know before i get the IRSCI TX to work.

 

By the way, Does anybody know where to find a complete interrupt driven uart code for MC68HC908AP64/32/16 ?

 

Please check my code below and comment what i do wrong.

 

#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "MCUinit.h"

// A pointer to memory where i want to store information.
unsigned char *EEPROM = (unsigned char*)0xF000;


void Delay (int pause) {
  int a;
   for(a=0;a<pause;a++) {
      ;
   }
}

unsigned char GetByte() {
   // This part should read a byte from address 0xF000.
   return *EEPROM;
}

void SetByte(unsigned char val) {
 // The delays below is not adjusted yet. Maybe i should use a timer.
 // This function should store one byte in address 0xF000.
 // Tryed to follow the instructions in datasheet.
 // Will this code work ?
 
 FLCR |=FLCR_PGM;  // Disable program controll bit
 *EEPROM=0x01; // Write to the memory area. (Will not be stored.)
 Delay(20);    // Wait
 FLCR |= FLCR_HVEN;    // Highvoltage enabled
 Delay(100);
 *EEPROM=val;          // Write byte to flash memory
 Delay(200);
 FLCR &=~FLCR_PGM;     // Disable program controll bit
 Delay(20);
 FLCR &=~FLCR_HVEN;  // Highvoltage disabled
 

 

void main(void) {
  int b=0;
  int a=0;
  byte tmp;

  // Init function produced by Device Initialization in Code Warrior.
  MCU_init();

  EnableInterrupts;
 
  SetByte(66); // Set the number 66 at address 0xF000
  a=GetByte(); // Read the byte on address 0xF000
 
  for(b=0;b<10;b++) {
  // Send the byte 10 times to IR UART.
  // I am not sure about next part.
  while(((IRSCS1 & IRSCS1_SCTE)==IRSCS1_SCTE) && ((IRSCS1 & IRSCS1_TC)==IRSCS1_TC));
  // Send the byte to IR uart. Should send ABCDEFGHIJ to the comport.
  IRSCDR=a+b;

  }

  for(;:smileywink: {
   
    for(b=0;b<100;b++) {
      ;
    }
    // The code below works fine
    // it echoes back the characters to the terminal connected to uart.
    while((IRSCS1 & IRSCS1_SCRF)==0);
   
    tmp=IRSCDR;
    IRSCDR=tmp; 
  }
}

 

/AlfaMaster

Message Edited by NLFSJ on 2009-08-18 10:00 AM
Labels (1)
0 Kudos
Reply
2 Replies

572 Views
bigmac
Specialist III

Hello Alpha,

 

Firstly, you appear to be attempting to run the erase/programming code from a flash location. As the datasheet explains, the flash memory is inaccessible while the HVEN bit is set. If you write your own erase programming code, this must be transferred to RAM, and run from there. Additionally, without accurate timing of the sequence of operations you risk permanently damaging the flash memory. The timing must take into account the bus clock rate in use.

 

Within the datasheet, there is reference to monitor ROM, and the erase and programming sub-routines that it contains. Monitor ROM remains accessible during flash operations. I would recommend that you make use of the ERARNGE and PRGRNGE ROM resident sub-routines, rather than attempting to write your own. It is possible that you might need to use in-line assembler to simplify the setup the buffer prior to calling either routine.  Also refer to AN2874.

 

I assume that your are using the header file for the AP64 device, as defined within the CW installation? This defines each register bit in two ways - as a member of a bit field, and as a mask value. Your code appears to require the mask value option, but your have chosen the bit field macro in many instances. This will not produce the expected result.  AN2616 may be of interest.

 

For example, the corrected SCI send code might appear as follows-

 

for (b = 0; b < 10; b++) { // Send 10 bytes to IR UART.
while ((IRSCS1 & IRSCS1_SCTE_MASK) == 0);
// Send the byte to IR uart. Should send ABCDEFGHIJ to the comport.
IRSCDR = 'A' + b;

}

 

It is necessary to wait only until the SCTE flag is set before sending the next byte. Alternatively, either of the following statements would make use of the bit field macro.

 

while (!IRSCS1_SCTE);

while (IRSCS1_SCTE == 0);

 

Regards,

Mac

Message Edited by bigmac on 2009-08-19 12:22 PM
0 Kudos
Reply

572 Views
AlfaMaster
Contributor II

Hi Mac.

 

This is really wierd.

 

I have added the changes to my code and it will only write ten letters if i write:

 

void main(void) {
  int b=0;
  int a=0;
  byte tmp;

  MCU_init();

  EnableInterrupts;
 
  for(b=0;b<10;b++) {
    while ((IRSCS1 & IRSCS1_SCTE_MASK) == 0);
    IRSCDR='A';
    while (IRSCS1_SCTE == 0);
  }

  while(1) {
    Delay(100);
    while((IRSCS1 & IRSCS1_SCRF)==0);
    tmp=IRSCDR;
    IRSCDR=tmp; 
  }
}

If i make an addition like :

 

  for(b=0;b<10;b++) {
    tmp='A'+b;
    while ((IRSCS1 & IRSCS1_SCTE_MASK) == 0);
    IRSCDR=tmp;
    while (IRSCS1_SCTE == 0);
  }


Then it will skip this part.

And another strange thing is that every second the MPU restarts ??

The COP is disabled:

 

  /* CONFIG1: COPRS=0,LVISTOP=0,LVIRSTD=0,LVIPWRD=0,LVIREGD=0,SSREC=0,STOP=0,COPD=1 */
  CONFIG1 = 0x01;                                     
  /* CONFIG2: STOP_ICLKDIS=0,STOP_RCLKEN=0,STOP_XCLKEN=0,OSCCLK1=0,OSCCLK0=0,SCIBDsrc=0 */
  CONFIG2 = 0x00;                                     

This lines is taken from MCUInit.

 

If i add __RESET_WATCHDOG(); in all loops then it ignores the loop that should write ten A.

 

Is there anything else i'm missing here ?

 

Regards

 AlfaMaster.

 

0 Kudos
Reply