RX and TX in single thread isnt working

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

RX and TX in single thread isnt working

Post by daleonpz »

i don't know why my code isnt working. I'm sending a command and then eventually i'll get a reply.

here's my code:

Code: Select all

int main(void)
{
	while (1){
		Acmd(TX1);
		rxData();
	}
	return 0;
}
as soon as I send the command i get the reply, which it means that it's not neccesary to use multitask for this, or that's what i think.. when i use par instead of while(1), it works.. why?

Code: Select all

void rxThread(void)
{	char c[33];
	char p[]="AI=";
	int count=34;
	char temp[33];

		for(int i=0;i<33;i++)
			c[i]=rxByte(RX1);	
            	for(int i=0;i<33;i++) /*To vizualize the recieved data using commnad prompt*/
			{
				txByte(TX,c[i]);
				delay(100);
			}
}

void Acmd(out port TXD)
{

		for(int i=0;A[i]!=0;i++)
			{
			txByte(TXD,A[i]);
			delay(100);
			}
		txByte(TXD,13);

}


User avatar
TSC
Experienced Member
Posts: 111
Joined: Sun Mar 06, 2011 11:39 pm

Post by TSC »

Are rxThread() and rxData() supposed to be the same function? Just wondering if you renamed something for posting.

I've never seen a while loop used inside an XC main function. Normally it's just a par{} with various thread calls within.

If you really need to do this with just one thread, maybe try this sort of structure:

Code: Select all

int main(void)
{
   par{
      UART_loop();
      // other threads to be added;
   }
   return 0;
}

void UART_loop(){
   while (1){
      Acmd(TX1);
      rxData();
   }

}
Be aware that with what you have now, rxThread() won't return until all 33 characters have been received, so Acmd() will be blocked from running most of the time. I'm not sure what's happening on the other side of the UART... If you want Acmd() and rxData() to run independently they really have to be in separate threads.
daleonpz
Member++
Posts: 26
Joined: Thu Nov 04, 2010 1:18 pm

Post by daleonpz »

thank you for you reply, I 'll keep in mind what you said about running in parallel Acmd and Rx.