Page 4 of 4

Re: UART won't run

Posted: Mon Aug 22, 2011 12:10 pm
by Heater
It's a while now since I had time to look at xcores and UARTs. I did run my UART transmitter in the simulator and did see that it was outputting I nice looking signal as I expected. I'll have to try this again.

Re: UART won't run

Posted: Thu Sep 01, 2011 1:46 am
by xcorific
I apologize for possibly hijacking here, but my question is related to UARTs. I'd like my first project to be an implementation of a multi-UART, so perhaps trying to use the XMOS as a "hub" for 8 RS-232 ports. Since there is plenty of I/O available, and four cores on my XC-1A, shouldn't I be able to support 2 UARTS in software on each of the four cores, following the example that the OP is using? I'd just want to aggregate the comms into a global structure for sending over another physical communication medium, which could be Zigbee, ethernet, etc.

Re: UART won't run

Posted: Thu Sep 01, 2011 3:04 am
by rp181
I'le admit, I didn't read all four pages.

When I first started, I was getting something similar. It only worked when I casted it as unsigned.

Code: Select all

chan <: ((unsigned)data);

Re: UART won't run

Posted: Sun Jan 22, 2012 2:07 am
by mifay
I'm reviving this thread because I am having a similar problem when doing the uart tutorial. Instead of "Hello World" strings, strange characters are displayed in the console as shown below.

Image

I'm using this code:

Code: Select all

#include <xs1.h>

#define BIT_RATE 115200
#define BIT_TIME XS1_TIMER_HZ / BIT_RATE

out port TXD = XS1_PORT_1J;

void txByte (out port TXD, char byte);

int main()
{
    char msg[]="Hello World!\n";
    int bytes=sizeof(msg);
    // send the message continuously, so you don't miss it
    while(1){
        for (int i=0;i<bytes;i++) {
            txByte(TXD,msg[i]);
        }
    }
    return 0;
}

void txByte(out port TXD, char byte) {
	unsigned time;
	timer t;
	/* get initial time */
	t :> time;
	/* send start bit */
	TXD <: 0;
	time += BIT_TIME;
	t when timerafter(time) :> void;
	/* send data bits */
	for (int i=0; i<8; i++) {
		TXD <: >> byte;
		time += BIT_TIME;
		t when timerafter(time) :> void;
	}
	/* send stop bit */
	TXD <: 1;
	time += BIT_TIME;
	t when timerafter(time) :> void;
}

Re: UART won't run

Posted: Sun Jan 22, 2012 8:31 pm
by leon_heller
That looks similar to the code I use:

Code: Select all

// Simple UART demo for XC-1 board

#include <xs1.h>
#include <platform.h>

#define BIT_RATE 57600
#define BIT_TIME XS1_TIMER_HZ / BIT_RATE

void txByte(char);
unsigned char rxByte(void);

out port TXD = PORT_UART_TX;
in port  RXD = PORT_UART_RX;

int main(void)
{	
	int c;

	while (1)
	{
		c = rxByte();
		txByte(c);
	}
	return 0;
}

unsigned char rxByte(void)
{
   unsigned data = 0, time;
   int i;
   unsigned char c;

   // Wait for stop bit
   RXD when pinseq (1) :> int _;

   // wait for start bit
   RXD when pinseq (0) :> int _ @ time;
   time += BIT_TIME + (BIT_TIME >> 1);

   // sample each bit in the middle.
   for (i = 0; i < 8; i += 1)
   {
      RXD @ time :> >> data;
      time += BIT_TIME;
   }

   // reshuffle the data.
   c = (unsigned char) (data >> 24);

   return (c);
}

void txByte(char c)
{
	unsigned time ;
	timer t;

	/* input initial time */
	t :> time ;

	/* output start bit */
	TXD <: 0;
	time += BIT_TIME ;
	t when timerafter ( time ) :> void ;

	/* output data bits */
	for ( int i=0; i <8; i ++)
	{
		TXD <: >> c ;
		time += BIT_TIME ;
		t when timerafter ( time ) :> void ;
	}

	/* output stop bit */
	TXD <: 1;
	time += BIT_TIME ;
	t when timerafter ( time ) :> void ;
}



Re: UART won't run

Posted: Mon Jan 23, 2012 2:15 am
by mifay
Thanks, this kinda helped me. I noticed you changed your baud rate, so I started playing with my own baud rate. I didn't get much result until I found this website. I used 113636 instead of 115200 baud rate and it's working.

I still don't understand why this is happening. If someone has an explanation, I would gladly hear it. At least, now my problem is solved :)

EDIT:
Now the program just started working with 115200 baud rate. :shock: