element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Reading UART Rx Buffer (MKR WiFi 1010 / MKR 1000)
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 16 replies
  • Subscribers 391 subscribers
  • Views 2817 views
  • Users 0 members are here
  • rx
  • uart
  • arduino
Related

Reading UART Rx Buffer (MKR WiFi 1010 / MKR 1000)

kas.lewis
kas.lewis over 5 years ago

Hello All,

 

I'm looking to create my own UART interrupt. For those who need to know why it's because I need to stop the timer as soon as a value comes in. While I know I will get a lot of reasons and explanations why this is not necessary I'm a lot more interested in how to go about doing this.

 

I have to commented out

 

void SERCOM5_Handler()

{

  Serial1.IrqHandler();

}

 

in the variant.cpp file which works to remove the Arduino code from doing what it wants. The issue I'm having now is finding the function Serial.read(). I'm trying to read the uart rx buffer but with Atmel's documentation what it is this is not as easy as it should be.

 

 

I have tried

 

void SERCOM5_Handler()

{

  char temp = SERCOM5->USART.DATA.reg;

  if (temp == 'h' || temp == 'H'){

    digitalWrite(LED_BUILTIN, HIGH);

  }

  if (temp == 'l' || temp == 'L'){

    digitalWrite(LED_BUILTIN, LOW);

  }

}

 

 

without much success. Therefore any help in reading the UART rx register would be very much appreciated.

 

Kas

  • Sign in to reply
  • Cancel

Top Replies

  • BigG
    BigG over 5 years ago +1
    I can see where you are coming from. Usually you could use the "serialEvent()" function but I see that this is not possible with Arduino SAMD Boards. Unortunately, I have no idea why but will be following…
  • michaelkellett
    michaelkellett over 5 years ago +1
    Is (temp == 'h'||temp == 'H') the same as ((temp == 'h')||(temp == 'H')) ? (brackets are free and make code easier to follow, (actually == has precedence over || in C )) How are you debugging this - can…
  • kas.lewis
    kas.lewis over 5 years ago in reply to michaelkellett +1
    Hello michaelkellett I didn't know you can put breakpoints in the Arduino IDE. Truth is there is lots about Arduino I don't know as I usually do bare metal with direct control of al registers and I also…
Parents
  • michaelkellett
    michaelkellett over 5 years ago

    Is

    (temp == 'h'||temp == 'H')

     

    the same as

     

    ((temp == 'h')||(temp == 'H'))

     

    image ?

    (brackets are free and make code easier to follow, (actually == has precedence over || in C ))

     

    How are you debugging this - can you put a breakpoint in the interrupt handler and see what is in temp at the critical moment ?

     

    Why not modify the original handler ?

     

    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • kas.lewis
    kas.lewis over 5 years ago in reply to michaelkellett

    Hello michaelkellett

     

    I didn't know you can put breakpoints in the Arduino IDE. Truth is there is lots about Arduino I don't know as I usually do bare metal with direct control of al registers and I also usually keep away from Atmel amongst others (not a fan of their documentation).

     

    All that being said your suggestion to modify the original handler is a good one if I could find it. From what I can see the SERCOM5_Handler() calls another function Serial1.IrqHandler() which I'm having a hard time locating... If I find it that would be great. Also the real issue is not so much altering the current handler as figuing out how to read the Rx data register. I might be  a bit closer in getting what I need, if so I'll post my finding here when I get there.

     

    Kas

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • michaelkellett
    michaelkellett over 5 years ago in reply to kas.lewis

    This may sound weird but might be worth a go:

     

    You should be able to run the full Arduino code in the Microchip/Atmel IDE, it uses a Cortex M0 core so there should be ob chip debugging available.

    I don't know if you can get at the pins required.

     

    Is there an Arduino function or library for direct register access ?

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • michaelkellett
    michaelkellett over 5 years ago in reply to kas.lewis

    This may sound weird but might be worth a go:

     

    You should be able to run the full Arduino code in the Microchip/Atmel IDE, it uses a Cortex M0 core so there should be ob chip debugging available.

    I don't know if you can get at the pins required.

     

    Is there an Arduino function or library for direct register access ?

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • kas.lewis
    kas.lewis over 5 years ago in reply to michaelkellett

    michaelkellett

     

    Thank you for the suggestion, not really a fan of downloading another IDE (especially since I don't generally use Atmel or Microchip) but I'll see if this will help resolve my issue. Until I do that though I'll share what I've tied so far. There is a lot of commented code but this shows everything I've tried without success. Interestingly enough after sending 'H' or 'h' 3 or so times the software locks up and I have to terminate the Arduino IDE.

     

        #include <avr/interrupt.h> 
        #include <avr/io.h> 
        #include <SERCOM.h>
    
    
    char tempflip = 0;
    #define DATA_SERCOM5           0x42001C00
        
    void setup()
    {
      // initialize serial:
      Serial.begin(9600);
      // initialize digital pin LED_BUILTIN as an output.
      pinMode(LED_BUILTIN, OUTPUT);
    }
    
    
    void loop()
    {
      char temp;
    //  while (Serial.available() > 0) {
    //    temp = Serial.read();
    //    if (temp == 'h' || temp == 'H'){
    //      digitalWrite(LED_BUILTIN, HIGH);
    //    }
    //    else if (temp == 'l' || temp == 'L'){
    //      digitalWrite(LED_BUILTIN, LOW);
    //    }
    //    
    //  }
    }
    
    
    void SERCOM5_Handler()
    {
      readDataUART();
    //  SERCOM5->USART.DATA.reg;
    //  sercom->USART.DATA.bit.DATA;
    //  SERCOM5->USART.DATA.bit.DATA;
    //   unsigned char *status,*intflag,*data;
    //
    //  data=(unsigned char *)DATA_SERCOM5;
    //  status=(unsigned char *)STATUS_SERCOM1;
    //  intflag=(unsigned char *)INTFLAG_SERCOM1;
    //
    //  if((*intflag&RECV)==RECV)                                                           //character received?
    //  {
    //      recv=*data;                                                                                    //fetch received character    
    //      if((*status & 0b00000110)!=0)                                                   //receive errors happened?  
    //      {
    //           *status=6;                                                                                  //reset errors (framing and buffer overflow error)
    //           errors = errors | REC_ERR;                                                  //set global rec error flag in my global error variable not to use the char
    //      }                            
    //    }
    //  uint8_t temp = SERCOM5->USART.DATA.reg;
    //  char  temp = SERCOM5->USART.DATA.reg;
      char temp = SERCOM5->USART.DATA.bit.DATA;
    
    
    //  char temp = SERCOM5->USART.DATA.bit.DATA;
      if (temp == 'h' || temp == 'H'){
        digitalWrite(LED_BUILTIN, HIGH);
      }
      else if (temp == 'l' || temp == 'L'){
        digitalWrite(LED_BUILTIN, LOW);
      }
    
    
    
    
    //  if (tempflip == 1){
    //    digitalWrite(LED_BUILTIN, HIGH);
    //  }
    //  else {
    //    digitalWrite(LED_BUILTIN, LOW);
    //  }
    //  tempflip ^= tempflip;
    //}
    
    
    //void SERCOM4_Hand
    
    
    
    
    
    
    
    
    
    
    
    
    
    {

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube