Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: Serial monitor Rx interrupt

  1. #1
    Junior Member
    Join Date
    Feb 2019
    Posts
    4

    Serial monitor Rx interrupt

    Hello Everyone.
    I am using Teensy3.2
    I want to communicate with one IC using I2c protocol i will get value from IC and will do some alterations on it in the place of "hello world" that is mentioned in my code below. And when i enter any special character,pointer will go out from main code just like i am doing in the code below but i want to do this with interrupt.
    Is it possible.
    Please give me any appropriate solution.

    Code:
    void interrupt ();
    
    void setup() {
      // put your setup code here, to run once:
    Serial.begin(115200);
    }
    
    void loop() {
      
     char val;
      // put your main code here, to run repeatedly:
     if( Serial.available()>0)
     {
      val = Serial.read();
      if (val == '+' )
    {
      interrupt ();
        
        }
     }
    
     Serial.println("Hello world");
     delay(500);
    }
    
    void interrupt ()
    {
     while(1)
     {
      ;
     }
    
    }

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    7,839
    Not clear on your question? There is no IC specific or i2c code shown in the code shown.

    Are you looking to monitor incoming USB Serial characters?

    If you were looking to watch arrival of UART Serial1 [or other Serial#] I have done that.

    There is an inbuilt Arduino check for available Serial characters - but it is not interrupt driven. It is checked on each exit of loop() or any time delay() or yield() is called. Look up serialEvent() to see if it would be a solution.

  3. #3
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,435
    @Defragster: Isn't that the Job of EventResponder?
    Otherwise I'd say just chain the Serial-Interrupt, but that's not very Arduino-like.
    Last edited by Frank B; 02-20-2019 at 10:00 AM.

  4. #4
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,299
    In ever case, this isn't a "Suggestion or bug report", so I will move that thread into the appropriate category.

  5. #5
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    7,839
    I see it as "Technical Support & Questions" - well moved! - but I never pay attention to that.

    eventResponder is checked - AFAIK - in the same places as serialEvent() - unless it is set to interrupts, if that is working but I don't have a LINK to point to for that.

    On the GPS thread I set up an interrupt to detect the UART Serial Start Bit on the Rx pin - to track the time nearest to the actual data point calc providing the data - the loop() was periodically busy for long calcs and the message took ~5 ms to transfer (depending on msg len and baud). If this is a UART question I can share that. If it is USB then messing with anything there would seem fraught with peril. On the UART Rx - I had the _isr - disable the _isr and record the cycle counter for timing. Then when the GPS message was complete I turned the _isr back on for the next message, because data transitions made the _isr a bit busy

    Details not provided to be sure in this case why interrupt notice is time critical - or if the code not shown will be keeping the CPU busy for long periods between loop() exit or other call to yield()/delay() - so serialEvent() - or eventResponder may be sufficient.

  6. #6
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,299
    Yes, I moved it towards technical support and questions.

    Just a little question in this context: Although I do see EventResponder related code in the core files, is there already an API and documentation about that?

  7. #7
    Junior Member
    Join Date
    Feb 2019
    Posts
    4
    First thanks all of you actually i am using USB serial for looking my result on serial monitor. And i want to interface AD5933 IC with teensy3.2. After getting frequency from serial monitor my teensy3.2 will send result on serial monitor continuously. But i want when i enter any special character pointer will go out from main code just like in the code above . is it possible with serialEvent() function???

  8. #8
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    7,839
    Quote Originally Posted by Theremingenieur View Post
    Yes, I moved it towards technical support and questions.

    Just a little question in this context: Although I do see EventResponder related code in the core files, is there already an API and documentation about that?
    I have not and did not find and good examples for using - EventResponder. I did play with KurtE's Serial work somewhere (T4?) in a quick sample - it was wired up then just like using serialEvent. Looking at the source shows an expectation for interrupt triggering it seems rather than polling.

    Quote Originally Posted by Abbasi View Post
    First thanks all of you actually i am using USB serial for looking my result on serial monitor. And i want to interface AD5933 IC with teensy3.2. After getting frequency from serial monitor my teensy3.2 will send result on serial monitor continuously. But i want when i enter any special character pointer will go out from main code just like in the code above . is it possible with serialEvent() function???
    If the loop() is processing quickly - not held up with busy loops or work the response to incoming characters on USB Serial will be quite fast, typically given some few (tens or hundreds of) thousand or more passes through loop() each second when not bogged down. And as noted even if delay() is called - that will actually trigger a call to the serialEvent code. And if there are busy loops putting in a call to yield() would result in a check as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •