Jump to content
Sign in to follow this  
HVflash

Energia UART Interrupt

Recommended Posts

Hi,

 

I wonder if it is possible to cause a interrupt when receiving serial data.

This would have the big advantage to be able to wake up from sleep mode if new serial data is available.

By now, serial data is written in the rx buffer even in sleep mode, but afaik it's not possible to notice that in Energia.

I found lots of code for CCS for exactly this application, but i'm not able to port it for Energia.

 

Does anybody already has some example code or may help me to make the CCS code working in Energia?

 

Thanks! :)

 

Share this post


Link to post
Share on other sites

I don't believe so, generally speaking Arduino doesn't have a facility for doing this and I know Energia never implemented one. Also UART doesn't work right when using sleep, sleepSeconds or suspend, only delay will keep the main CPU clock spun up to keep the UART peripheral working.

 

As a stop gap, it might be possible to connect a jumper wire between the UART RXD line and an unused (and IRQ capable) GPIO then set it up to interrupt on the start bit and have it alert your app to wake--that might be a handy way to "wake on UART" actually from a deep sleep mode, but just know the first few characters coming through will be gibberish due to the lack of accurate clock in LPM3/LPM4 (sleep/sleepSeconds and suspend in Energia).

 

Your GPIO interrupt handler routine would probably disable its own interrupt right away, and your app would re-enable the interrupt just before going into deep sleep.

 

Sent from my Galaxy Note II with Tapatalk 4

Share this post


Link to post
Share on other sites

Thank you for your answer.

I connected P1_0 and P1_1, but it doesn't work as intended:

int interval = 10;
byte highbyte, lowbyte;

void setup() 
{      
  Serial.begin(9600);

  attachInterrupt(P1_0, receiveData, FALLING);
}

void loop() 
{
  if (parseData)
  parseSerial();
  
  //Main code here: Measuring data

  sleepSeconds(interval);
}

void receiveData()
{
  wakeup();
  detachInterrupt(P1_0);
  parseData = true;
}

void parseSerial()
{
  parseData = false;
  
  highbyte = Serial.read();
  delay(50);
  lowbyte = Serial.read();

  interval = highbyte * 256;
  interval = interval + lowbyte;
    
  attachInterrupt(P1_0, receiveData, FALLING);
}

I try to develop a sensor that can be configured via the Serial port. By default it should sleep for 10s between every measurement. The code works somehow, the interupt routine sets the "parseData" flag correctly and also the received data is correct. But unfortunately after triggering the interrupt the MCU stays sleeping for the remaining time, instead of processing the serial data instantly. With a interval of 10s that's not a problem, but if you habe to wait for 2h or longer to change the measuring interval, thats no possibility. Any idea how to fix this?

Share this post


Link to post
Share on other sites

Thank you for your answer.

I connected P1_0 and P1_1, but it doesn't work as intended:

int interval = 10;
byte highbyte, lowbyte;

void setup() 
{      
  Serial.begin(9600);

  attachInterrupt(P1_0, receiveData, FALLING);
}

void loop() 
{
  if (parseData)
  parseSerial();
  
  //Main code here: Measuring data

  sleepSeconds(interval);
}

void receiveData()
{
  wakeup();
  detachInterrupt(P1_0);
  parseData = true;
}

void parseSerial()
{
  parseData = false;
  
  highbyte = Serial.read();
  delay(50);
  lowbyte = Serial.read();

  interval = highbyte * 256;
  interval = interval + lowbyte;
    
  attachInterrupt(P1_0, receiveData, FALLING);
}

I try to develop a sensor that can be configured via the Serial port. By default it should sleep for 10s between every measurement. The code works somehow, the interupt routine sets the "parseData" flag correctly and also the received data is correct. But unfortunately after triggering the interrupt the MCU stays sleeping for the remaining time, instead of processing the serial data instantly. With a interval of 10s that's not a problem, but if you habe to wait for 2h or longer to change the measuring interval, thats no possibility. Any idea how to fix this?

Well two things...

 

1. Since you're in LPM3 during sleepSeconds, then while the ISR should wake up & fire you can't expect the serial port to have much more than gibberish going on since SMCLK isn't running to feed the USCI (HW UART) peripheral its timing pulses necessary to synchronize its logic (and detection of outside events).  How you handle that I'm not entirely sure but I'd bet the main loop could sleep a fixed amount of time, say 50ms, doing Serial.read()'s and discarding the results, followed by a phase where it waits for pending data for up to 50ms before giving up.  Then the device which is sending this UART data can do its thing by sending 1 byte (to wake up the chip), wait 50ms, then send the real data.

2. Where is "parseData" declared?  Is it declared "volatile" as we'd expect (since it's modified inside ISRs and outside of ISR context)?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...