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 » Sat Apr 23, 2011 12:14 pm

Hmm... almost there.

Which code is that running there?
Have your clock settings it your .xn file?
Try setting the output high for one character time at start up to ensure the synch is right.
Ganux
Active Member
Posts: 35
Joined: Tue Mar 08, 2011 12:58 pm

Postby Ganux » Sat Apr 23, 2011 9:01 pm

Hi,

I set it to low for a cycle, but that doesn't change anything..
i didn't totally get the thing you said about the .xn file :S
can you explain that a little more?

Thx for the help anyway!!

Ganux_
Heater
Respected Member
Posts: 296
Joined: Thu Dec 10, 2009 10:33 pm

Postby Heater » Sun Apr 24, 2011 5:13 am

In your project you have a .xn file. Like XC-1A.xn. In that file you can change the clock settings of your processor. Look for a line like:

<Node Id="0" InPackageId="0" Type="XS1-G4B" Oscillator="20MHz" SystemFrequency="400MHz">

If you have never changed that file I guess the clock settings are set to the normal defaults anyway.

As you are receiving something, but incorrectly, I just thought maybe there is a problem with the baud rate not being correct.

Actually I was suggesting setting the output HIGH for one character time (10 bits say) at start up just to be sure the first start bit is detected properly. However my effort here works with or without that.
Ganux
Active Member
Posts: 35
Joined: Tue Mar 08, 2011 12:58 pm

Postby Ganux » Sun Apr 24, 2011 10:38 am

Hi,

tried both of the things.. but still can't get it working.. =(
the clock was set to 400Mhz..
and setting the txd-pin to 1 doesn't seem to work either =(

Here is a piece of the XC-3.xn file i'm using in the project:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<Network xmlns="http://www.xmos.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xmos.com http://www.xmos.com">
  <Type>Board</Type>
  <Name>XC-3 LED Tile Control Board</Name>

  <Declarations>
    <Declaration>core stdcore[4]</Declaration>
  </Declarations>

  <Packages>
    <Package id="0" Type="XS1-G4B-FB144">
      <Nodes>
        <Node Id="0" InPackageId="0" Type="XS1-G4B" Oscillator="20MHz" SystemFrequency="400MHz">
          <Boot>
            <Source Location="SPI:bootFlash"/>
          </Boot>
          <Core Number="0" Reference="stdcore[0]">
            <Port Location="XS1_PORT_1A" Name="PORT_SPI_MISO"/>
            <Port Location="XS1_PORT_1B" Name="PORT_SPI_SS"/>
            <Port Location="XS1_PORT_1C" Name="PORT_SPI_CLK"/>
            <Port Location="XS1_PORT_1D" Name="PORT_SPI_MOSI"/>
            <Port Location="XS1_PORT_1E" Name="PORT_LED_IN_CLK"/>
            <Port Location="XS1_PORT_1F" Name="PORT_LED_OUT_R0"/>
            <Port Location="XS1_PORT_1G" Name="PORT_LED_OUT_G0"/>
            <Port Location="XS1_PORT_1H" Name="PORT_LED_OUT_B0"/>
            <Port Location="XS1_PORT_1I" Name="PORT_LED_OUT_R1"/>
            <Port Location="XS1_PORT_1J" Name="PORT_LED_OUT_G1"/>
            <Port Location="XS1_PORT_1K" Name="PORT_LED_OUT_B1"/>
            <Port Location="XS1_PORT_1L" Name="PORT_LED_OUT_CLK"/>
            <Port Location="XS1_PORT_1M" Name="PORT_LED_OUT_LATCH"/>
            <Port Location="XS1_PORT_1N" Name="PORT_LED_OUT_OE"/>
            <Port Location="XS1_PORT_1O" Name="PORT_GPIO_CLK"/>
            <Port Location="XS1_PORT_1P" Name="PORT_UART_RX"/>
            <Port Location="XS1_PORT_4A" Name="PORT_LED_OUT_ADDR"/>
            <Port Location="XS1_PORT_4B" Name="PORT_UART_TX"/>
            <Port Location="XS1_PORT_8B" Name="PORT_LED_IN"/>
          </Core>
I saw you can import the .xn file in the project..
I tried this, but is doesn't change anything.. =(

Ganux_
Heater
Respected Member
Posts: 296
Joined: Thu Dec 10, 2009 10:33 pm

Postby Heater » Sun Apr 24, 2011 11:43 am

Looks good to me.
As far as I can tell importing the xn file only enables you to edit it otherwise it is read only.

Are you working on Windows or Linux or what?
Have you tried running this from the command line with xrun?
Like: xrun --id 0 --uart uart_Debug.xe
Have you tried running under the simulator and checking the output waveform?
Ganux
Active Member
Posts: 35
Joined: Tue Mar 08, 2011 12:58 pm

Postby Ganux » Sun Apr 24, 2011 12:00 pm

Hi,

I'm working on a Windows 7 Professional 32-bit.

I'm not familiar with the command line, so where should i drop my .xe files?

Have tried the simulator.. but didn't really see how that worked.. :S

Ganux_
Heater
Respected Member
Posts: 296
Joined: Thu Dec 10, 2009 10:33 pm

Postby Heater » Sun Apr 24, 2011 12:26 pm

You should not have to move the xe file.
Presumably it is being built in a project directory like: workspace/uart/Debug

Firstly you have to run something to set up a path to the command line tools. Not sure what that is in Windows but my bet is that it's called SetEnv.bat.

After that you can chage to your debug directory and run xrun. Something like:
xrun --id 0 --uart uart_Debug.xe

Use xrun -l to list the available device ids. As you have only one it's probably 0 anyway.

The simulator requires a bit of getting used to. I still have trouble getting it to trace signals I want sometimes.
Ganux
Active Member
Posts: 35
Joined: Tue Mar 08, 2011 12:58 pm

Postby Ganux » Sun Apr 24, 2011 12:40 pm

I tried running it from the command line.

I added the picture of the output..
ScreenShot001.jpg
It came from this code:

Code: Select all

#include <platform.h>
#define BIT_RATE 115200
#define BIT_TIME XS1_TIMER_HZ / BIT_RATE

on stdcore[0] : out port uart_tx = PORT_UART_TX;

// Forward declaration
void txByte (out port TXD, int byte);

int main()
{
   char msg[] = "Hello World /n";
   int i;
   for(int j=0;j<10;j++){
	   uart_tx <: 1;
   }
   /*while (1)
   {*/
      for (i = 0; i < sizeof(msg) - 1; i++)
      {
         txByte(uart_tx, msg[i]);
      }
   //}
   return 0;
}

void txByte (out port TXD, int byte)
{
   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 <: >> byte;
       time += BIT_TIME;
       t when timerafter (time) :> void;
    }

    // Output stop bit
    TXD <: 1;
    time += BIT_TIME;
    t when timerafter (time) :> void;
}
Ganux_
You do not have the required permissions to view the files attached to this post.
Heater
Respected Member
Posts: 296
Joined: Thu Dec 10, 2009 10:33 pm

Postby Heater » Sun Apr 24, 2011 12:59 pm

I'm at a loss to know what to suggest.
I just copied that code into a new project and it runs fine here.

Except. At least you are getting something out and it looks like something you might get if the baud rate was wrong.

I'd be tempted to tweak the baud rate up and down by a little bit.
Ganux
Active Member
Posts: 35
Joined: Tue Mar 08, 2011 12:58 pm

Postby Ganux » Sun Apr 24, 2011 1:04 pm

Heater wrote: Except. At least you are getting something out and it looks like something you might get if the baud rate was wrong.

I'd be tempted to tweak the baud rate up and down by a little bit.
Tried that one too..
but still can't get it going.. =(

I'm still thinking that i programmed something wrong in the flash.. (using xflash)
But i really wouldn't know what should be programmed in it..

Who is online

Users browsing this forum: No registered users and 2 guests