I am currently using MQX 3.7 with the k60twr512 and I am having alot of problems reading characters in from the data terminal using interrupts. I have gone into the twrk60n512 and enabled the "ittyd:" (RS-232) as the default. I have also disabled all other UARTs. I am able to sucessfully write data out using printf but I can not read data in. What am I missing? I have also attached my twrk60n512 file for verification that I enabled the drivers correctly.
#define _get_task_td(x) _task_get_td(_task_get_id_from_name(x))#if ! BSPCFG_ENABLE_IO_SUBSYSTEM#error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined non-zero in user_config.h. Please recompile BSP with this option.#endif#ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED#error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in user_config.h and recompile BSP with this option.#endif#define _get_task_td(x) _task_get_td(_task_get_id_from_name(x))/* Task IDs */#define HELLO_TASK 5#define TASK1 6#define TASK2 7#define READ_TASK 8extern void hello_task(uint_32);extern void task1(uint_32);extern void task2(uint_32);extern void read_task(uint_32);const TASK_TEMPLATE_STRUCT MQX_template_list[] = { /* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */ { HELLO_TASK, hello_task, 1500, 7, "hello", MQX_AUTO_START_TASK, 0, 0 }, { TASK1, task1, 1500, 6, "task1", 0 , 0, 0 }, { TASK2, task2, 1500, 5, "task2", 0 , 0, 0 }, { READ_TASK, read_task, 1500, 4, "read task", 0 , 0, 0 }, { 0 }};/*TASK*-----------------------------------------------------* * Task Name : hello_task* Comments :* This task prints " Hello World "**END*-----------------------------------------------------*/void hello_task ( uint_32 initial_data ){ _task_id task1_id, task2_id, read_task_id; pointer td2_ptr, td1_ptr; boolean nonblocktask = 0; char x; task1_id = _task_create(0,TASK1,0); task2_id = _task_create(0,TASK2,0); read_task_id = _task_create(0,READ_TASK,0); td2_ptr = _get_task_td("task2"); /* Defined in macro to get td_ptr */ td1_ptr = _get_task_td("task1"); printf("\nHello main task\n"); _time_delay(500); while(1) { _task_restart(task1_id,NULL,0); _task_restart(task2_id,NULL,0); _time_delay(1000); }}void task1(uint_32 initial_data){ printf("\nHello Task 1\n"); _task_block(); /*Can not let task die in order to restart*/ }void task2(uint_32 initial_data){ printf("\nHello Task 2\n"); _task_block(); /*Can not let task die in order to restart*/}extern void read_task(uint_32){ /*Insert Read data here*/ char c = (char)NULL; while(!c){ //c = _io_getchar(); scanf("%d",(int)c); } printf("CHAR RECEIVED");}/* EOF */
Solved! Go to Solution.
try this
void read_task(uint_32 initial_data)
{
char ch;
pointer fh_ptr;
fh_ptr =(pointer)fopen("ittyd:", (char const*)BSP_DEFAULT_IO_OPEN_MODE); // Interrupt mode uart3
if(fh_ptr == NULL)
{
printf("cannot open file: ittyd\n"); // print to uart3
}
unsigned char status;
do
{
if(fstatus(fh_ptr))
{
ch = fgetc(fh_ptr );
}
else
{
_time_delay(1);
}
}while(1);
}
try this
void read_task(uint_32 initial_data)
{
char ch;
pointer fh_ptr;
fh_ptr =(pointer)fopen("ittyd:", (char const*)BSP_DEFAULT_IO_OPEN_MODE); // Interrupt mode uart3
if(fh_ptr == NULL)
{
printf("cannot open file: ittyd\n"); // print to uart3
}
unsigned char status;
do
{
if(fstatus(fh_ptr))
{
ch = fgetc(fh_ptr );
}
else
{
_time_delay(1);
}
}while(1);
}
That worked, Thanks so much.
I didn't realize that you had to use the fopen for the serial line because I thought it was opened by default.