LOGIN
Jagannath Sahoo
2
Apprentice
Student
 · BhubaneswarIndia
Share
Report
Get Link
SHOW & TELL

How To Send Bytes on UART Communication using AVR with Interrupt Enabled

Friends I’m working on mqtt protocol, where i need to send bytes on the UART lines. I know, its easy to use Software control for sending bytes on UART. but I want to implement on usage of Interrupts.So can anyone help me on building codes of serial communication with Interrupts???
Abhi Verma Robert Lancer Ravi Pujar

2 likes 
Like
Award Contribution
Ravi Pujar
24
Community Expert
Embedded systems engineer, Founder @Valetron Systems, Blogger @www.raviyp.com
 · DharwadIndia
Share
Report
Get Link

If you are using Arduino, I dont have much idea, as i had tried to use Interrupts based data reception but found that Arduino core is internally using that and its complicated.

Like
1 like 
Award Contribution
Jagannath Sahoo
2
Apprentice
Student
 · BhubaneswarIndia
Share
Report
Get Link

No! i’m trying with Native C programming…Ravi Pujar

Like
0 like 
Award Contribution
Abhi Verma
42
Community Expert
ROBOToTHON 2017 Mentor, Electronics Engineer
 · DelhiIndia
Share
Report
Get Link

there is no user interrupts available for user. AVR uses UART driver interrupt to receive a byte from serial.
but in arduino you can do something else. there is a function called SerialEvent() which runs once per loop cycle.
or you can use my favorite micros() or millis() function to make RTOS. call Serial.available() after a certain time.
e.g.

bool stringComplete  = false;
String inputString = "";

void Setup()
{
   Serial.begin(115200);
}

void loop()
{
   if( micros()%10000 == 1)
   {
   	communicate();
   }
}


void communicate()
{
   inputString = "";
   while (Serial.available()) {
   // get the new byte:
   char inChar = (char)Serial.read();
   // add it to the inputString:
   inputString += inChar;
   // if the incoming character is a newline, set a flag so the main loop can
   // do something about it:
   if (inChar == '\n') 
   {
    		 stringComplete = true;
   	}
 }
}
Like
1 like 
Award Contribution
Jagannath Sahoo
2
Apprentice
Student
 · BhubaneswarIndia
Share
Report
Get Link

Thank you for your information Abhi Verma… But i’m thinking to build a Library for this of my own for MQTT where i need to send bytes

Like
1 like 
Award Contribution
Abhi Verma
42
Community Expert
ROBOToTHON 2017 Mentor, Electronics Engineer
 · DelhiIndia
Share
Report
Get Link

yes you can. and this kind of code will give you RTOS capability. you can check for multiple tasks and use ur time to needed tasks rather then generating delay by halting the cpu in a loop.

Like
3 likes 
Award Contribution
Leave a reply...
DISCOVER
CHAT
HIRE
ACTIVITY
FEED
New Post
Help
Start Project
Online Users
Share Link
Write something before you submit it!
Photo updated
Request Sent!
Updated
Copied to Clipboard