This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RTX-TINY serial port problems

Hello all, I am trying to write program using TINY that will eventually need to be able to read from both serial ports and send on one of them. To accomplish this, it would work best if I could get the round-robin task switching working.

I have the following code that creates a task and attempts to read from serial port 0 (my 8051 has two). For some reason neither the printf or putchar in Init come out, and task 1 does not echo anything that is sent to it.

any ideas would be very welcome, thanks

#include <rtx51tny.h>                 /* RTX-51 tiny functions & defines      */
#include <reg420.h>
#include <stdio.h>                    /* standard I/O .h-file                 */

#define INIT      0                   /* task number of task:  init           */
#define COMMAND   1                   /* task number of task:  command        */

void serial_init();
char _getkey0 ();

void Init (void) _task_ INIT  {

	serial_init();

	printf("hello world");

	putchar('h');

	os_create_task(COMMAND);
	os_delete_task(INIT);
	while(1);
}

void Command (void) _task_ COMMAND
{
char c;
	while (1)
	{
		c = _getkey0();
		putchar(c);
	}
}

char _getkey0 (){
  char c;

  while (!RI_0);
  c = SBUF0;
  RI_0 = 0;
  return (c);
}

void serial_init (void)  {
  SCON  = 0x50;                      /* mode 1: 8-bit UART, enable receiver   */
  TMOD |= 0x20;                      /* timer 1 mode 2: 8-Bit reload          */
  PCON |= 0x80;			     /* Set SMOD_0			      */
  TH1   = 0xf7;                      /* reload value 19200baud                */
  TL1 	= 0xf7;
  TR1   = 1;                         /* timer 1 run                           */
  ES    = 1;                         /* enable serial port interrupt          */
}