[START][SAMD21 xplained] USART only writing 2 bytes of 15 w/ io_write()

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

I have set up a project in start with two synchronous USART modules and a LCD connected through SPI. My code is below, and it's basically completely borrowed from Atmel examples. I'm trying to write out of USART_1 every 2 seconds using a callback task from TIMER_0, which then gets read from USART_0, and displayed on the LCD.

#include <atmel_start.h>
#include <hal_gpio.h>
#include "gfx_mono_main.h"
#include "gfx_mono_font_basic_6x7.h"
#include <string.h>

struct timer_task TIMER_task1;

static void TIMER_task1_cb(const struct timer_task *const timer_task)
{
	struct io_descriptor *io1;
	usart_sync_get_io_descriptor(&USART_1, &io1);
	const uint8_t str[30] = "Hello, world!";
	if (usart_sync_is_tx_empty(&USART_1)){
		io_write(io1, str, 15);
	}
	
}

void TIMER_100ms_init(void)
{
	TIMER_task1.interval = 2000;
	TIMER_task1.cb       = TIMER_task1_cb;
	TIMER_task1.mode     = TIMER_TASK_REPEAT;
	timer_add_task(&TIMER_0, &TIMER_task1);
	timer_start(&TIMER_0);
}


int main(void)
{
	/* Initializes MCU, drivers and middleware */
	atmel_start_init();
	const uint8_t str[30] = "Hello, world!";
	uint8_t buf[15];
	
	//Have to re-enable graphics after enabling SPI interface. 8 hours of debugging.
	spi_m_sync_enable(&SPI_INSTANCE);
	gfx_mono_init();
	
	gfx_mono_draw_rect(
	&MONOCHROME_GRAPHICS_0_desc, 0, 0, UG2832HSWEG04_LCD_WIDTH, UG2832HSWEG04_LCD_HEIGHT, GFX_PIXEL_SET);

	usart_sync_enable(&USART_0);
	usart_sync_enable(&USART_1);
	
	TIMER_100ms_init();
	
	struct io_descriptor *io0;
	usart_sync_get_io_descriptor(&USART_0, &io0);

	struct io_descriptor *io1;
	usart_sync_get_io_descriptor(&USART_1, &io1);	

	
	while(1) {
		
		//delay_ms(100);
		if(usart_sync_is_rx_not_empty(&USART_0)) {
			io_read(io0,buf,15);
		}
		gfx_mono_text_draw_string(&MONOCHROME_TEXT_0_desc, buf, 30, 12, &basic_6x7);
	}
}

 

The problem is that it's only outputting the first two bytes of "Hello world!", so only "He" is showing up on the LCD screen. I have it hooked up to a cheap oscilloscope with no protocol capabilities, and the USART pulse is short enough that I'm fairly sure that it's the io_write that's the problem and not the io_read. 

 

I'm really new to serial communications, so it's entirely possible that I'm just not understanding the capabilities of USART correctly.

 

I've attached the project. Baud rate is set in the configurator at 50k, and the processor is running at 48Mhz off the DPLL.

Attachment(s): 

This topic has a solution.
Last Edited: Sun. Apr 22, 2018 - 07:39 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yup, turns out I don't know much about USART yet. Changed the drivers from sync to async, and now everything works as expected.