SAMC21 USART sending problem with io_write in freeRTOS

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
/***Usart.c***/
#include <atmel_start.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>

void USART_Init(void)

{
	usart_async_get_io_descriptor(&USART, &usart_io);
	usart_async_register_callback(&USART, USART_ASYNC_TXC_CB, tx_cb);
	usart_async_register_callback(&USART, USART_ASYNC_RXC_CB, rx_cb);
	usart_async_enable(&USART);
}

 /* itoa:  convert n to characters in s */
 void itoa(int n, char s[])
 {
     int i, sign;
 
     if ((sign = n) < 0)  /* record sign */
         n = -n;          /* make n positive */
     i = 0;
     do {       /* generate digits in reverse order */
         s[i++] = n % 10 + '0';   /* get next digit */
     } while ((n /= 10) > 0);     /* delete it */
     if (sign < 0)
         s[i++] = '-';
     s[i] = '\0';
     reverse(s);
 }

 /* reverse:  reverse string s in place */
 void reverse(char s[])
 {
     int i, j;
     char c;
 
     for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
         c = s[i];
         s[i] = s[j];
         s[j] = c;
     }
 }
 
 void USART_Send_Values(int value)
{
	char		stringbuffer[50]; 
	uint16_t	str_length;
 	memset(stringbuffer, 0, 50); 
 	itoa(value, stringbuffer); 
	str_length = strnlen(stringbuffer, 50);
	io_write(usart_io, (uint8_t*) stringbuffer, str_length);
}

__________________________________________________________________________
/***main***/

#include <atmel_start.h>
#include "FreeRTOS.h"
#include "USART.h"
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include "atmel_start_pins.h"
#define TASK_50ms_STACK_SIZE (800 / sizeof(portSTACK_TYPE))
#define TASK_50ms_STACK_PRIORITY (tskIDLE_PRIORITY + 1)
static TaskHandle_t      xCreated50msTask;



/**
 * OS 50ms task
 */
static void task_50ms()
{
	while (1)
	{
	USART_Send_Values(650);         // Doesn't works
	USART_Send_TextMessage("650");  // Works well
	os_sleep(50);
	}
}

/**
 * \brief Create OS 50ms task
 */
static void task_50ms_create(void)
{
	/* Create task to make led blink */
	if (xTaskCreate(task_50ms, "50ms", TASK_50ms_STACK_SIZE, NULL, TASK_50ms_STACK_PRIORITY, &xCreated50msTask) != pdPASS) {
		while (1) {
			;
		}
	}
}

int main(void)
{
	/* Initializes MCU, drivers and middleware */
	atmel_start_init();
	USART_Init(), 
	
 	task_50ms_create();     //create 50ms task
 	vTaskStartScheduler();  //start tasks
	
	/* Replace with your application code */
	while (1) 
	{
		
	}
}

Hello,

 

I having a problem with sending characters by using io_write in a task in with freeRTOS. If I send something with "USART_Send_TextMessage("650");" it works well, but if us "USART_Send_Values(650); " i receive 65 in free running mode and 650 in debugging with a breakpoint on the end of the function. I checked the code many times and i am sure the converting into string is ok. Further, if set stringbuffer [] = "Hello World"; it also doesn't works. When used the usart handling without freeRTOS it works. Could somebody helps me?

 

Thank you :)

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

650 with Debuggen and Breakpoint on the end of function "USART_send_values()"

65 in FreeRunning Mode (every 50ms)