Serial monitor Rx interrupt

Status
Not open for further replies.

Abbasi

Member
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)
 {
  ;
 }

}
 
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.
 
@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:
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.
 
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?
 
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???
 
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.

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.
 
Status
Not open for further replies.
Back
Top