Problems setting up SCI in CW

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

Problems setting up SCI in CW

1,760 Views
Kyle
Contributor I
CW version - 5.9 build - 2830
MCU - m68mod9s12c32 using 9s12c dev board
 
I'm trying to send commands to my LCD using SCI and I'm having trouble using it correctly.  i've tried using the processor expert, but it keeps complaining and throwing errors so I tried to set it up myself.  Heres the function i'm using.
 
Code:
void send_LCD(unsigned char *array){  int count = 0;  int i;  int dummy = 0;  count = intlen(array);  for (i = 0; i < count+1; i++) {    while (SCISR1_TDRE == 1) {      SCISR2 = 0x08;      dummy = SCISR1;      SCIDRL = array[i];    }    SCICR2_TE = 0;  }

 
array is a function of commands (254, 87, 1, 'Z') in this case.  I want to loop through and send each one once TDRE says that is ready to go.  I can't seem to get the loops to work properly, and of course, nothing happens to my LCD.  Any suggestions?  Thanks
Labels (1)
Tags (1)
0 Kudos
Reply
2 Replies

597 Views
bigmac
Specialist III
Hello Kyle,

It seems that the intent of your code is to wait until the SCISR1_TDRE flag becomes set, and then continue to send the next character.  However, your code does not do this.  The following code should provide the proper wait process.
for (i = 0; i < count+1; i++) {
   while (SCISR1_TDRE == 0);  // Wait for flag set
   SCISR2 = 0x08;
   (void)SCISR1;              // Read register
   SCIDRL = array[i];         // Send character
}
SCICR2_TE = 0;                // Disable send

Regards,
Mac


597 Views
Lundin
Senior Contributor IV
The function "intlen" seems very preculiar to me. What does it do? I assume you use some sort of global variables to get it working. Why aren't you using a struct instead?

Also, try to make dummy volatile. It is very likely that the compiler optimizes away the write to that variable, since the variable is never used.