CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Serial Com Error

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ertansuluagac



Joined: 13 Jul 2017
Posts: 135
Location: IZMIR

View user's profile Send private message Send e-mail

Serial Com Error
PostPosted: Wed May 08, 2019 2:29 am     Reply with quote

Is there an error in my code? I don't see mistake. But the problem is;
Now when I press "R1O" as serial communication, my value will be 6000. When I press "R2O" my value will be 0. Serial communication is not interrupted every time. He goes in 1 time. Why is that?

Code:
{
#use rs232 (ICD, baud = 115200, STREAM = ICD_STREAM)
#pin_select U1TX = PIN_B3
#pin_select U1RX = PIN_B2
#use rs232 (UART1, baud = 115200, STREAM = DEBUG_STREAM, TRANSMIT_BUFFER=256, TXISR)

char buffer[6];

unsigned int8 ptr=0;
signed int32 MAX_PULSE_COUNT=0;
#int_rda
void serihaberlesme_kesmesi(void)
{
   disable_interrupts(INT_RDA);
     buffer[ptr++] = getc();
     if(ptr==4)
     {
         if(buffer[0]=='R' && buffer[1]=='1' && buffer[2]=='O' && buffer[3]==13)
         {
            MAX_PULSE_COUNT=6000;
         }
         
         else if(buffer[0]=='R' && buffer[1]=='2'&& buffer[2]=='O' && buffer[3]==13)
         {
            MAX_PULSE_COUNT=0;
           
         }
         
         
         ptr=0;
     }
     
}

 void main()
 {
     setup_timer2(TMR_INTERNAL | TMR_DIV_BY_256, 27343);
    enable_interrupts(GLOBAL);
    while(TRUE)
    {
       enable_interrupts(INT_RDA);
       if(interrupt_active(INT_TIMER2))
       {
         clear_interrupt(INT_TIMER2);
         fprintf(DEBUG_STREAM,"\f\rMAX_PULSE_COUNT:%ld ",MAX_PULSE_COUNT);
      }
   
    }
   
 }
 





}

_________________
Es
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Wed May 08, 2019 1:06 pm     Reply with quote

You don't show us your processor or fuses. Strong possibility something
like a watchdog could be causing problems.

Then leave the INT_RDA enabled. Turn it on once at the start of the code
and leave it on.

Then print a local copy of MAX_PULSE_COUNT, in the main. So:

Code:


     int16 LocalPulseCount;

     //then in your loop:
     do {
         LocalPulseCount=MAX_PULSE_COUNT;
     while (LocalPulseCount!=MAX_PULSE_COUNT);

     //and print this local copy.


This avoids issues with printing a 16bit variable that may change
during the print.

As a general comment, in 'C' it is a 'standard' to reserve ALL CAPITALS
for macros and enums. It makes it easier to know that these are not
variables that can be changed in the code. Helps readability and to
avoid some 'nasties'. Try sticking to this.

Add 'ERRORS' to your #use rs232. This should _always_ be used
with the hardware UART, unless you add your own code to handle
errors. Without this if anything at all is sent after your R1O or R2O
(like an 'enter', the UART _will_ become hung. With your disable,
this is probably what is happening. Consider adding code to the ISR
so if the character arriving is '\n' or '\r' ptr is reset to 0.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group