Serial IRQ Problem

19 Dec 2010

Hello

 If  I send serial data  into my serial port,  I can process the  command and everthing is fine.  However, this seems to block  all other interrupts.  Thus,  if I subsequenly  want to process  a  command  input from one of the control knobs,  the system will  not respond.  The inputs  from the knons  only work until the point that I send some commands  via the serial port.

 

Is the problem here that scanf  is  basically  tying up my serial  port?  To  check  this,  I made sure I was sending complete strings  and  was able to confirm  this  with printf.

I am pretty  confused about this - any  ideas  to point  me in the right  direction?

/********************* remote serial  IRQ *************************/
void remotecontrol(void) {
   
    int q=0;
   
    myled=!myled;      /* just to let us know we are looping through here */
    //printf("1");
  
  if (remote.scanf("%s", remcon)){
  remaction=atoi(remcon);}
 
    /* here we flush  everything to make sure that any garbage entries do not remain */
    /* because what we got in from the serial link was not a valid string */
    else {
        for (q=0;q<8;q++) {
            remcon[q]=(' '); /* clean it up for the next cycle */
            remaction=0;
        }
    }
   
    flag=remaction;
    remcontoken=1; 
    //printf("2");
  
   }

19 Dec 2010

I found this after  doing  some searching

http://mbed.org/forum/mbed/topic/335/?page=1#comment-1703

 

so I am  going to re-check how I use scanf  to see  if  I  can sort this out.  I  think what's  happening is I  am receiving the char's  correctly,  and scanf  is decoding correctly  ans I am executing,  but  then I  still  have  some  chars in the Rx  buffer  (I am  sending  a string like this "9211\n\r") and I am goimg back into the Rx ISR and  just  sitting there  until the next  packet.  While I am sitting in the Rx ISR,  the way  scanf  is written,  none of the other  IRQ's are being serviced.  That my theory  anyway. 

 

If  I  am way  off,  love to hearanother  idea.

19 Dec 2010

after some work,  I  got it to work with this:-

 

void remotecontrol(void) {
   
    int q=0;
    int z=0;
   
    myled=!myled;      /* just to let us know we are looping through here */
    
  do{
  remcon[z]=getc(remote);
  z++;}
  while (z<6);
  printf("%s\n\r",remcon);
  remaction=atoi(remcon);//}
 
    /* here we flush  everything to make sure that any garbage entries do not remain */
    /* because what we got in from the serial link was not a valid string */
  
        for (q=0;q<8;q++) {
            remcon[q]=(' '); /* clean it up for the next cycle */
            }
   
    flag=remaction;remaction=0;
    remcontoken=1; 
      
   }

 

Basically,  scanf  is  removed and I get the  input string  using getc.  I  will  parse the code  in the main loop rather than in the serial  ISR.

19 Dec 2010

You may find this is better:-

Serial remote(p9, p10); // Assumes connected to P9 and P10

// ... then later
    z = 0;
    do {
        if (remote.readable()) {
            remcon[z++] = remote.getc();
        }
    }
    while (z < 6);

Also see MODSERIAL which is designed to take a lot of the pain out of this for you.

21 Dec 2010

Thanks  for that Andy.  I will try  it  out  later today.  Cheers  Andrew