UART won't run

New to XMOS and XCore? Get started here.
Heater
Respected Member
Posts: 296
Joined: Thu Dec 10, 2009 10:33 pm

Re: UART won't run

Postby Heater » Mon Aug 22, 2011 12:10 pm

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.
User avatar
xcorific
Member++
Posts: 17
Joined: Fri Aug 12, 2011 2:36 pm

Postby xcorific » Thu Sep 01, 2011 1:46 am

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.
User avatar
rp181
Respected Member
Posts: 395
Joined: Tue May 18, 2010 12:25 am

Postby rp181 » Thu Sep 01, 2011 3:04 am

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);
User avatar
mifay
Member++
Posts: 29
Joined: Wed Dec 28, 2011 4:15 pm

Postby mifay » Sun Jan 22, 2012 2:07 am

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;
}
User avatar
leon_heller
XCore Expert
Posts: 546
Joined: Thu Dec 10, 2009 10:41 pm
Location: St. Leonards-on-Sea, E. Sussex, UK.

Postby leon_heller » Sun Jan 22, 2012 8:31 pm

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 ;
}


User avatar
mifay
Member++
Posts: 29
Joined: Wed Dec 28, 2011 4:15 pm

Postby mifay » Mon Jan 23, 2012 2:15 am

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:

Who is online

Users browsing this forum: No registered users and 1 guest