Dear sir,                 We are using MC9S08GB60 control...

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

Dear sir,                 We are using MC9S08GB60 control...

1,907 Views
santhu
Contributor I
            Dear sir,
 
              We are using MC9S08GB60 controller (8 bit).In this we having a problem in clearing the TDRE flag.In the datasheet of this controller they mentioned the  two steps for clearing the TDRE flag.I did that inside my ISR (which is shown below in the code),after that also there is no changes in the status of TDRE flag (TDRE remains high after writing to SCI1D register).Actually whatever i write in the SCI1D (data register),the SCI1D register will not take that data that i saw in that register while debugging. And one more thing in SCI1C2 we are not enabling the TCIE then also TC flag will set. But in the receiver section we cleared the RDRF flag with 2 step statements.Suggest me if any mistakes in my code or mistakes in procedure of handling ISR .Below i written code sample.             
              
 
 
                #include <hidef.h> /* for EnableInterrupts macro */
                #include  "derivative.h" /* include peripheral declarations */
                #include <MC9S08GB60.h>
                #include <stdio.h>
                #include <math.h>
                #include <string.h>
 
                void interrupt 18 Vsci1tx_isr(void);
               
               // this array of data bytes should written to SCI1D one by one each time ISR call //
               
                unsigned char transmit_byte[11]={0x18,0xAA,0x18,0x10,0xFF,0x58,0xFF,0x90,0xFF,0x16};
               
                unsigned char *transmit_received_data; // Pointer to array of character
 
 
                void main(void)
                 {
                  SOPT=0x02;
                   EnableInterrupts; /* enable interrupts */
                  /* include your code here */
                  transmit_received_data=transmit_byte;
                   
                  SCI1BDL=0x0D;     //baud rate selected for 19200.             
                  SCI1BDH=0x00;
                  SCI1C1=0x00;       // normal 8 bit mode selected,parity check is dissabled //
                  SCI1C2=0x88;       // TIE , TE enabled and normal transmitter and receiver operation selected //
                  SCI1C3=0x00;       // framing error,parity error,noise error and OR interrupts are dissabled //
 
                  while(1)
                    {
                     
                   }
               }
 
           void interrupt 18 Vsci1tx_isr(void)                // ISR
            {
             unsigned char clear_trans_empty_flag=0 ;
             clear_trans_empty_flag=SCI1S1;              // reading the status register when TDRE=1;
             SCI1D=*transmit_received_data;               // Writting the data to SCI data register;
             transmit_received_data++;                       // increment the pointer address
           }
 
            
 With regards
SANTHOSH
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
                
             
            
 
 
       
Labels (1)
0 Kudos
3 Replies

370 Views
erooll
Contributor II

Hi.
Maybe your trouble is produced by optimization of code in Codewarrior, and clear_trans_empty_flag=SCI1S1; could be omitted.
Try to change your ISR function by this:

void interrupt 18 Vsci1tx_isr(void)
{
   if(SCI1S1_TDRE)
   { 
      SCI1D=*transmit_received_data;
      transmit_received_data++;
   }
}


and also take care of assignation of pointers:
transmit_received_data=&transmit_byte;

0 Kudos

370 Views
santhu
Contributor I
 
  Thanks for your answer. I tried the same thing what you told,but that concept is not working.The flag is not cleared.The data what i wrote in the SCID register is not writting inside that register.This may be the reason of not clearing of TDRE flag.And one more thing that in the SCI12 register i dissabled TCIE bit (transmit complete interrupt enable bit), then also TC flag will set.I tried many ways to clear this both flag inside ISR,but it not working.When I used receiver ISR i didn't faced any problem,whatever data i received that is shown in SCI1D register.suggest me if you come to knw where i did mistakes.
 
With regards
 
Santhosh
 
0 Kudos

370 Views
bigmac
Specialist III
Hello Santhosh,

I think that you may need to commence the SCI send process by writing the first character to SCI1D from outside the ISR.  Then use the ISR to automatically send the remaining string characters until a final null character is encountered (which probably would not be sent).

The following code snippet to demonstrate this process is untested.  I purposely did not increment the pointer within the send_string() function, to avoid the additional complexity of disabling and re-enabling interrupts (otherwise an interrupt might occur before the pointer has been incremented).

byte *send_data;

void send_string( byte *str)
{
   SCI1C2_TE = 1;      // Enable SCI send
   send_data = str;    // Initialise global pointer
   SCI1D = *send_data; // Send first character
}

void interrupt 18 Vsci1tx_isr( void)
{
   (void)SCI1S1;      // Read status register
   send_data++;       // Increment pointer
   if (*send_data)    // Non-null string character
      SCI1D = *send_data;
   else
      SCI1C2_TE = 0;  // Terminate send process
}

Regards,
Mac

0 Kudos