XK-1 uart communication

Technical discussions related to any XMOS development kit or reference design. Eg XK-1A, sliceKIT, etc.
daleonpz
Member++
Posts: 26
Joined: Thu Nov 04, 2010 1:18 pm

XK-1 uart communication

Post by daleonpz »

I want to send data from my PC (windows 7) to Xk-1, however when i write in the command promt "xrun --uart <bin>.xe" i'm not able to write any data.

here's my code:

Code: Select all

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

/* - The I/O ports are clocked at 100Mhz
   - UART enables a UART server that interfaces with the UART-to-USB converter
	on the XMOS USB-to-JTAG adapters. The converter operates at a rate of
	115200 bits/sec.
	- UART: 115200,8,n,1*/

#define BIT_RATE 115200
#define BIT_TIME 100000000 / BIT_RATE

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


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

int main()
{
		int i;
		unsigned char array[10]={"HolaAmigo"};
		while(1){
			led <:1;
			for (i = 0; i < 10; i++){
				 array[i] = rxByte();
			}

			led <: 0;
			for (i = 0; i < 10; i++){
				printf("%c",array[i]);
				printf("\n");
				txByte(array[i]);
				}
			}
		return 0;
}

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

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

   // wait for start bit
   RXD when pinseq (0) :> void;
   t :> time;
   time += BIT_TIME/2;

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

   }

   // input stop it
   time +=BIT_TIME;
   t when timerafter(time) :> void;
   RXD :> void;

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

   return c;
}

void txByte(unsigned char c)
{
   unsigned time, data;

   data = c;

   // get current time from port with force out.
   TXD <: 1 @ time;

   // Start bit.
   TXD <: 0;

   // Data bits.
   for (int i = 0; i < 8; i += 1)
   {
      time += BIT_TIME;
      TXD @ time <: >> data;
   }

   // one stop bit
   time += BIT_TIME;
   TXD @ time <: 1;
}
regards.


User avatar
XMatt
XCore Addict
Posts: 147
Joined: Tue Feb 23, 2010 6:55 pm

Post by XMatt »

The XTAG-2 UART support is currently only uni-directional ... it can only be used for output logging and does not support data transmission from the host PC to the development board it is connected to.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

So its a UAR then!!

regards
Al
daleonpz
Member++
Posts: 26
Joined: Thu Nov 04, 2010 1:18 pm

Post by daleonpz »

XMatt wrote:The XTAG-2 UART support is currently only uni-directional ... it can only be used for output logging and does not support data transmission from the host PC to the development board it is connected to.

do u know how i can my PC and Xk-1?.. any ideas?
gron
New User
Posts: 3
Joined: Mon Feb 28, 2011 12:53 pm

Post by gron »

daleonpz wrote:
XMatt wrote:The XTAG-2 UART support is currently only uni-directional ... it can only be used for output logging and does not support data transmission from the host PC to the development board it is connected to.

do u know how i can my PC and Xk-1?.. any ideas?
Map two pins of the XK-1 to a UART, than connect to PC/RS232 via a level translator such as MAX232.
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

daleonpz wrote:
XMatt wrote:The XTAG-2 UART support is currently only uni-directional ... it can only be used for output logging and does not support data transmission from the host PC to the development board it is connected to.

do u know how i can my PC and Xk-1?.. any ideas?
It is also possible to access the host PC through JTAG. It it possible to create/read/write to files on the host system. However it problably isn't very fast. There is an example project somewhere.