CW6.0 Coding Problems

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

CW6.0 Coding Problems

2,684 Views
admin
Specialist II
I am trying to implement a routine to assign the count of a rotary buffer count to an array element.  The array element, command_buffer[1] is defined as an unsigned char and the function, get_sci_buffer_status returns an unsigned char.  However, the assignment does not appear to work. 
 
As the code below shows, I am trying to output the array element immediately after assignment. 
Each time the CASE is called, the 'A' is sent out the SCI port, however, the "count" is never sent out.  If I swap position of the 2 SCI outputs, I don't get anything on the SCI port.
 
I have also tried to output the contents of command_buffer[1] directly with the same results as above. 
 
I do not understand why this assignment does not work.  Any suggestions will be greatly appreciated.  Code fragment is shown below.  Also, I do not have access to the monitor to debug this correctly.  That is why I am using the SCI to output variables.   
 
CODE FRAGMENT
 
 // returns 0 if no data in sci_buffer else retuns data count in buffer
  case CMD_GET_SCI_STATUS: {
   unsigned char count = get_sci_buffer_status();
   command_buffer[1] = get_sci_buffer_status();          // this is the line I need to work, the rest is debug
   if (SCS1 & SCS1_SCTE_MASK) {
    SCDR = 'A';
   }
 
   while (~(SCC1& SCS1_SCTE_MASK));
    if (SCS1 & SCS1_SCTE_MASK) {
    SCDR = count;
   }
   return (1); 
  }
Labels (1)
0 Kudos
4 Replies

265 Views
mccPaul
Contributor I
What have you got connected to the SCI?
 
If your count does not equate to a visible ASCII character you would not expect to see anything using a terminal application.
 
Maybe you need to convert the count into a string before you write it?
 
That seems more likely than a basic failure in your compiler!
 
Paul.
0 Kudos

265 Views
admin
Specialist II
I use "unsigned char sci_count" to track the number of bytes in a rotary buffer.  The function "get_sci_buffer_status" returns the value of sci_count to the calling routine. 
 
unsigned char sci_count = 0x00;      // buffer count
 
unsigned char get_sci_buffer_status() {
 return(sci_count);    // return # of data bytes in buffer
}
I am at a loss to understand why the return might be unprintable.  Any help understanding this problem is greatly appreciated.
 
Spencer
0 Kudos

265 Views
peg
Senior Contributor IV
Hi Spencer,
 
As Paul already mentioned...
You are sending the raw cound value out the serial port, should you not be converting this value to ASCII before you send it?
 
0 Kudos

265 Views
admin
Specialist II
Thanks for the suggestions.  That was indeed my problem.  I converted the data to a printable char and now I can see something on the SCI port. 
 
 
Thanks
0 Kudos