HCS1232C memory problems

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

HCS1232C memory problems

2,857 Views
Sinky
Contributor I
I have been writing programs in C for the HCS12C32 and need my program to remain on the microcontroller after i disconnect from the computer.
 
So far this is not the case as my SCI works (through the transmission and reception pins on the base of the HCS12) until i remove my serial cable then the transmission dies.
 
I have looked into memory remapping but not sure if this is what i want. Does anyone have any advice on this problem?
 
Thanks
Labels (1)
0 Kudos
10 Replies

730 Views
JimDon
Senior Contributor III
Hmm, if you removed the cable, then how do you know it dies?

Are you burning the program into flash?
Or are you using ram?
0 Kudos

730 Views
Sinky
Contributor I
I have been using an oscilloscope to monitor the transmissions. I haven't specified in my program so it will be writing to whatever the default is; I assume that it is burning into the flash because when the flash is wiped after i run another program it is no longer there.  Am i right in assuming that i want it to be burned into ram?
 
Thanks
0 Kudos

730 Views
JimDon
Senior Contributor III
" Am i right in assuming that i want it to be burned into ram?"

Did you mean ROM (FLASH). No, you do NOT what it to go into RAM.

Just because it is gone when you run another program, does not mean it was in FLASH.

What kind of board is it?
Are you using code warrior. If so post your PRM file.
0 Kudos

730 Views
Sinky
Contributor I
I am using a HCS12C32. Yes i did mean ROM(sorry) but i am not sure if there is any on this because there is no EEPROM on this microcontroller. 
 
I am using codewarrior. My program is:
 

void main (void) {
    SCIBDH = 0x00;
    SCIBDL = 0x34;   //baud of 9600
    SCICR1 = 0x20;   //8 bits,  no parity */
    SCICR2 = 0xFC;  //Enable transmitter and receiver
 
//    Transmission
while(1) {
    SCIDRL = 0x29;                   //send the bit sequence
    while ((SCISR1 & 0x80) == 0) ;   // Wait for transmission buffer to be empty(TDRE)
//    Reception
    while ((SCISR1 & 0x20) == 0) ;   /* Wait for received character */
    if ((SCISR1 & 0x0F) != 0)
    {
        PORTA=1;
        PORTB=0;
    }
}
 
Thanks
0 Kudos

730 Views
JimDon
Senior Contributor III
Well there is FLASH 32K to be exact.

In your project, find the PRM file and post that
Look in the files tab under PRM.
This file controls where things get  put.

BTW In your  program, it will stop sending because it is waiting to receive a character, and it never will since you unplugged the cable.
0 Kudos

730 Views
Sinky
Contributor I
I have fixed the registers to what they should be, I was just trying to implement a simple SCI at this point.
 
void main (void) {
    SCIBDH = 0x00;
    SCIBDL = 0x34;   //baud of 9600
    SCICR1 = 0x00;   //8 bits,  no parity */
    SCICR2 = 0x0C;  //Enable transmitter and receiver
 
//    Transmission
while(1) {
    SCIDRL = 0x29;                   //send the bit sequence
    while ((SCISR1 & 0x80) == 0) ;   // Wait for transmission buffer to be empty(TDRE)
//    Reception
    while ((SCISR1 & 0x20) == 0) ;   /* Wait for received sequence */
    if ((SCISR1 & 0x0F) != 0)
    {
        PORTA=1;
        PORTB=0;
    }
}
 
The HCS12_Serial_Monitor PRM linker file is:
 
/* This is a linker parameter file for the MC9S12C32 */
NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. */
SEGMENTS /* here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
    RAM = READ_WRITE 0x3800 TO 0x3FFF;
    /* unbanked FLASH ROM */
    ROM_4000 = READ_ONLY  0x4000 TO 0x7FFF;
    ROM_C000 = READ_ONLY  0xC000 TO 0xF77F;
    /* banked FLASH ROM */
/*  PAGE_3E = READ_ONLY  0x3E8000 TO 0x3EBFFF; not used: equivalent to ROM_4000 */
/*  PAGE_3F = READ_ONLY  0x3F8000 TO 0x3FBFFF; not used: equivalent to ROM_C000 */
  //OSVECTORS      = READ_ONLY  0xFF8A TO 0xFFFF;  /* OSEK interrupt vectors (use your vector.o) */
END
PLACEMENT /* here all predefined and user segments are placed into the SEGMENTS defined above. */
    _PRESTART,                   /* Used in HIWARE format: jump to _Startup at the code start */
    STARTUP,                     /* startup data structures */
    ROM_VAR,                     /* constant variables */
    STRINGS,                     /* string literals */
    VIRTUAL_TABLE_SEGMENT,       /* C++ virtual table segment */
  //.ostext,                     /* OSEK */
    NON_BANKED,                  /* runtime routines which must not be banked */
    DEFAULT_ROM,
    COPY                         /* copy down information: how to initialize variables */
                                 /* in case you want to use ROM_4000 here as well, make sure
                                    that all files (incl. library files) are compiled with the
                                    option: -OnB=b */
                                 INTO  ROM_C000/*, ROM_4000*/;
                                             
  //.stackstart,               /* eventually used for OSEK kernel awareness: Main-Stack Start */
    SSTACK,                    /* allocate stack first to avoid overwriting variables on overflow */
  //.stackend,                 /* eventually used for OSEK kernel awareness: Main-Stack End */
    DEFAULT_RAM                  INTO  RAM;
  //.vectors                     INTO OSVECTORS; /* OSEK */
END
ENTRIES /* keep the following unreferenced variables */
    /* OSEK: always allocate the vector table and all dependent objects */
  //_vectab OsBuildNumber _OsOrtiStackStart _OsOrtiStart
END
STACKSIZE 0x100
VECTOR 0 _Startup /* reset vector: this is the default entry point for a C/C++ application. */
//VECTOR 0 Entry  /* reset vector: this is the default entry point for an Assembly application. */
//INIT Entry      /* for assembly applications: that this is as well the initialization entry point */
 
 
I have unplugged the serial cable that is coming from the computer but there is still a transmission coming to the microcontroller via pin 7 in the bottom of the microcontroller.
0 Kudos

730 Views
allawtterb
Contributor IV
You need to read the SCIDRL after you receive a byte to clear the receive data register full flag.  Otherwise, once you receive one byte your microcontroller will loop forever sending 0x29 because this flag is never cleared. 
 
Once you have changed this, your code should send an 0x29 on startup then wait for a byte to be sent back.  Every time it receives a byte it will send a 0x29 back (which will show up as a ')' if you are monitoring for ASCII data).
0 Kudos

730 Views
Sinky
Contributor I
Do you mean that at the end of the reception section i should input the line SCIDRL; to simply read the register to reset it? Or would writing 0x00 into the SCIDRL register to clear it at the end of the transmission section of code work?
 
Why would this wait for a byte to be sent back before it continues? Would it not just continue transmitting as long as the receive data register full flag is not set therefore transmitting 0x29 repeatedly until the flag is set?
 
Sorry i am pretty new to this.
 
Thanks
0 Kudos

730 Views
allawtterb
Contributor IV


Sinky wrote:
Why would this wait for a byte to be sent back before it continues? Would it not just continue transmitting as long as the receive data register full flag is not set therefore transmitting 0x29 repeatedly until the flag is set?

Because of this line:
 
while ((SCISR1 & 0x20) == 0) ;   /* Wait for received character */
 
This line waits until the RDRF flag is set.  Take a look at the datasheet for your microcontroller(link below), Page 391 and the description of the RDRF flag.  It explains how it is set and how to clear this flag.
 
 
0 Kudos

730 Views
allawtterb
Contributor IV
The initialization of the registers you have is confusing.  You have set the RSRC bit of SCICR1 as though you are doing a loopback test but you don't have the LOOPS bit set.  Also, you have enabled all SCI interrupts by setting the upper nibble of SCICR2 to 0xF but you seem to be polling the status registers in your forever while loop.  What exactly did you want to test with this program?
0 Kudos