problem with UART

Technical questions regarding the XTC tools and programming with XMOS.
daleonpz
Member++
Posts: 26
Joined: Thu Nov 04, 2010 1:18 pm

problem with UART

Post by daleonpz »

I've made a UART code, but i dont know why it isnt working... I want to send a motor command by RS232, the motor command is supposed to be !M nn mm, where nn is the power level of the motor 1 and mm is the power level of the second one. The motor controller config is: 115200,8,n,1

here's my code

Code: Select all

#define BIT_RATE 115200
#define BIT_TIME 100000000 / BIT_RATE

out port TX1 = XS1_PORT_1A;
in port  RX1 = XS1_PORT_1B;

unsigned char M[]="!M ";

void txByte(out port TXD, 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;
}

void Mcmd(out port TXD, char Mcmd1[], char Mcmd2[])
{
	for(int i=0;M[i]!=0;i++)
		txByte(TXD,M[i]);
	for(int i=0;Mcmd1[i]!=0;i++)
		txByte(TXD,Mcmd1[i]);
	for(int i=0;Mcmd2[i]!=0;i++)
		txByte(TXD,Mcmd2[i]);
}

int main(void)
{
	int out1=400;
	int out2=-950;
	char outS1[33];
	char outS2[33];
	IntToSt(out1,outS1);
	IntToSt(out2,outS2);
Mcmd(TX1,outS1,outS2);
	return 0;
}

any help will be appreciated.


User avatar
Jerry
Member++
Posts: 30
Joined: Sat Dec 12, 2009 7:14 pm
Location: Silicon Valley

Post by Jerry »

Please be a little more specific than "it isn't working".

Are you seeing any activity on the Tx port (XS1_PORT_1A)?