USART callbacks not being triggered

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

Hi,

I'm new to Atmel and ASF but i'm trying to work with interrupts on the USART RX interface because data is coming in at random periods and needs to be decoded.

 

I reviewed the ASF topic: " Quick Start Guide for SERCOM USART - Callback ".

Did the step by step configuration but the "usart_read_callback" won't hit.

 

Here is my setup:

 

uart.c:
 

#include <asf.h>
#include "uart.h"
#include "gpio.h"

struct usart_module usart_instance_1;
volatile uint8_t rx_buffer[MAX_RX_BUFFER_LENGTH];

void write_message(void)
{
	uint8_t string[] = "Hello World!\r\n";
	usart_write_buffer_wait(&usart_instance_1, string, sizeof(string)-1);
}

// Configure USART instance 1 as SERCOM3. PA22 (TX) and PA23 (RX)
void configure_usart_info(void)
{
	struct usart_config config_usart_info;
	usart_get_config_defaults(&config_usart_info);

	config_usart_info.baudrate    = 9600;
	config_usart_info.mux_setting = USART_RX_1_TX_0_XCK_1;
	config_usart_info.pinmux_pad0 = PINMUX_PA22C_SERCOM3_PAD0;
	config_usart_info.pinmux_pad1 = PINMUX_PA23C_SERCOM3_PAD1;
	config_usart_info.pinmux_pad2 = PINMUX_UNUSED;
	config_usart_info.pinmux_pad3 = PINMUX_UNUSED;

	while (usart_init(&usart_instance_1,SERCOM3, &config_usart_info) != STATUS_OK) {}

	usart_enable(&usart_instance_1);
}

// Callback function to be executed when an character is being received.
void usart_read_callback(struct usart_module *const usart_module)
{
		port_pin_set_output_level(LEDR, 0);				//	Enable status led
		port_pin_set_output_level(LEDG, 0);				//	Enable status led
		port_pin_set_output_level(LEDB, 0);				//	Enable status led
}

// Callback function to be executed when an character is being send.
void usart_write_callback(struct usart_module *const usart_module)
{
		port_pin_set_output_level(LEDR, 0);				//	Enable status led
		port_pin_set_output_level(LEDG, 0);				//	Enable status led
		port_pin_set_output_level(LEDB, 0);				//	Enable status led
}

// Register callbacks for USART instance 1.
void configure_usart_callbacks(void)
{
	usart_register_callback(&usart_instance_1,usart_write_callback, USART_CALLBACK_BUFFER_RECEIVED);
	usart_register_callback(&usart_instance_1,usart_read_callback, USART_CALLBACK_BUFFER_RECEIVED);
	usart_enable_callback(&usart_instance_1, USART_CALLBACK_BUFFER_RECEIVED);
	usart_enable_callback(&usart_instance_1, USART_CALLBACK_BUFFER_RECEIVED);
}

 

main.c

 

#include <asf.h>

#include "uart.h"
#include "gpio.h"

int main (void)
{
	system_init();

	configure_port_pins();							//	Configure the GPIO pins.

	configure_usart_info();							//	Configure the USART port.
	configure_usart_callbacks();					//	Setup the callbacks to be used for the USART.

	port_pin_set_output_level(LEDR, 1);				//	Disable status led
	port_pin_set_output_level(LEDG, 1);				//	Disable status led
	port_pin_set_output_level(LEDB, 1);				//	Disable status led

	system_interrupt_enable_global();				//	Enable global interrupts.

	write_message();								// Write message to UART.

	while(true)
	{
	}

	/* Insert application code here, after the board has been initialized. */
}

 

Thanks in Advance

 

Usually

 

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

You need to read, i.e., call usart_read_job or usart_read_buffer_job. 

/Lars

 

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

Hi Lars,

 

Thanks for the quick response. I suppose that i need to call this one in "usart_read_callback" but when i do a debug and send a character the code doesn't jump in the "usart_read_callback" routine. Have i forgotten something?

 

Do i need to call this "usart_read_job" in my main loop?

 

Thanks in advance.

 

Usually

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

Hi Lars,

 

I found the solution that you suggested, on this topic https://www.avrfreaks.net/forum/samc21-uart-receive-interrupt

I just need to call this one to enable interrupt and recall this one to re-enable the interrupt routine. The same like STM32.

 

Thanks you your quick answer!

 

Usually