SAMC21 UART Receive Interrupt

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Coming from an 8 bit Freescale uC, I'm finding the USART of the SAMC21 to be very complex.  I am playing with USART_QUICK_START_CALLBACK example project for the Xplained Pro, but everything is so abstracted I'm having a hard time figuring out how to do what I want.  I am hooking this up to talk serially to an LCD.  I simply want to configure it so that when a receive interrupt occurs, goes to my interrupt handler where i do nothing but stuff information in a circular buffer.  The example project has the ISR in a file called usart_interrupt.c. and I'm not sure how to direct it to a different handler.  Sorry if this is a dumb question but I'm not used to all this abstraction.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

john8791 wrote:
goes to my interrupt handler where i do nothing but stuff information in a circular buffer

Is there a problem doing exactly this but in a callback?

Just request one byte and repeat that request in the callback.

/Lars

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lajon wrote:

john8791 wrote:
goes to my interrupt handler where i do nothing but stuff information in a circular buffer

Is there a problem doing exactly this but in a callback?

Just request one byte and repeat that request in the callback.

/Lars

 

 

I would agree but this is where I get confused by the abstraction.  Here is the "Main loop" from the example program:

//! [main_loop]
	while (true) {
//! [main_loop]
//! [main_read]
		usart_read_buffer_job(&usart_instance,(uint8_t *)rx_buffer, MAX_RX_BUFFER_LENGTH);
//! [main_read]
	}
//! [main]

Let me know if I am understanding the flow right ......  main() loop constantly calls usart_read_buffer_job(...) to check for a data byte received in the background by the SERCOM ISR and puts it into rx_buffer until "MAX_RX_BUFFER_LENGTH" characters have been received at which point the callback function is triggered?  Could I just as call usart_read_buffer_job(...) from a 1mS periodic interrupt such as SysTick_Handler() to fill the rx_buffer in case my main() loop is busy doing something else?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This example is not good at all, the usart_read_buffer_job in the main loop is causing a lot of confusion, there is no need to poll like that.

Just call usart_read_buffer_job once to get things going and then call it in the callback. 

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

\o/ Yes it's works. 

 

Its true to  usart_read_job() too? 

Thiago Silva Nascimento

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, you can look at the implementation, both call _usart_read_buffer()

/Lars