Page 1 of 1

Zigbee TX, RX Port From 1 to USART 2

Posted: Tue Aug 16, 2011 4:29 pm
by Ondra
Good day all.
I'm using a chip that has 2 USARTs. Using the zigbee componet, I would like to know how to set the component
to use USART 2.


Ondra

Re: Zigbee TX, RX Port From 1 to USART 2

Posted: Wed Aug 17, 2011 7:51 am
by Steve
You'll need to customise the C code behind the Zigbee component. Looking at the code, I think the only code you'll need to customise are the following:
  • [Defines]
    [Initialization]
    Receive_Char
    Send_Char

Re: Zigbee TX, RX Port From 1 to USART 2

Posted: Wed Aug 17, 2011 11:52 am
by Ondra
Thanks Dave.
I was hoping it could be done.
To tell you the truth I'm a flowcode programmer.
I need lots of help when It comes to working in C.
If you find the time could you assist with the changes.
Thanks in advance.

Re: Zigbee TX, RX Port From 1 to USART 2

Posted: Wed Aug 17, 2011 11:54 am
by Steve
Unfortunately (or fortunately for me!) I will be on holiday from tomorrow, so I do not have the time to do this for you.

Re: Zigbee TX, RX Port From 1 to USART 2

Posted: Wed Aug 17, 2011 11:58 am
by Ondra
Boy, that was fast.
You will be missed. Enjoy.
Anybody else out there can help, I'd much appreciate it.

Ondra

Re: Zigbee TX, RX Port From 1 to USART 2

Posted: Mon Aug 22, 2011 11:36 am
by Benj
Hello Ondra,

Ok here is how its done,

Init Section.

Code: Select all

	clear_bit (MX_ZIG_TRIS, MX_UART_TX);		// TX pin is an output
	set_bit (MX_ZIG_TRIS, MX_UART_RX);			// RX pin is an input
	txsta = MX_ZIG_TXSTA;   					// 8-bit, async, low speed, off
	spbrg = MX_ZIG_SPBRG;   					// set the baud rate 9600
	rcsta = 0;                    				// 8-bit, disabled
	st_bit(rcsta, SPEN);         				// turn on serial interface
Replace with

Code: Select all

	clear_bit (MX_ZIG_TRIS, MX_UART_TX);		// TX pin is an output
	set_bit (MX_ZIG_TRIS, MX_UART_RX);			// RX pin is an input
	txsta2 = MX_ZIG_TXSTA;   					// 8-bit, async, low speed, off
	spbrg2 = MX_ZIG_SPBRG;   					// set the baud rate 9600
	rcsta2 = 0;                    				// 8-bit, disabled
	st_bit(rcsta2, SPEN);         				// turn on serial interface
Replacing "MX_ZIG_TRIS" with your actual tris eg trisa and replacing MX_UART_TX, MX_UART_RX with the actual UART pin numbers eg 0 and 1.



Send Char.

Code: Select all

	st_bit(txsta, TXEN);
	while (ts_bit(pir1, TXIF) == 0);
	#if MX_ZIG_HWFC == 1
		while ((MX_ZIG_PORT & (1 << MX_ZIG_CTSP) ) != 0); 	//wait until CTS is low
	#endif
	txreg = nChar;	
replace with

Code: Select all

	st_bit(txsta2, TXEN);
	while (ts_bit(pir3, TX2IF) == 0);
	#if MX_ZIG_HWFC == 1
		while ((MX_ZIG_PORT & (1 << MX_ZIG_CTSP) ) != 0); 	//wait until CTS is low
	#endif
	txreg2 = nChar;	

Finally Receive Char Function.

Code: Select all

while (rxStatus == 0)
	{
		if (ts_bit(pir1, RCIF) != 0)
		{
			//received a Char
			rxStatus = 2;
		}
		else
		{
			if (bWaitForever == 0)
			{
				//don't wait forever, so do timeout thing...
				if (nTimeout == 0)
				{
					rxStatus = 1;
				}
				else
				{
					//decrement timeout
					delay1--;
					if (delay1 == 0)
					{
						nTimeout--;
	}	}	}	}	}

	if (rxStatus == 2)
	{
		if (ts_bit(rcsta, FERR) != 0)
		{
			dummy = rcreg;      //need to read the rcreg to clear FERR
		}
		else
		{
			if (ts_bit(rcsta, OERR) != 0)
			{
				//need to read the rcreg to clear error
				cr_bit(rcsta, CREN);
				st_bit(rcsta, CREN);
			}
			else
			{
				retVal = rcreg; //no error, so rx byte is valid
	}	}	}
Replace with

Code: Select all

while (rxStatus == 0)
	{
		if (ts_bit(pir3, RC2IF) != 0)
		{
			//received a Char
			rxStatus = 2;
		}
		else
		{
			if (bWaitForever == 0)
			{
				//don't wait forever, so do timeout thing...
				if (nTimeout == 0)
				{
					rxStatus = 1;
				}
				else
				{
					//decrement timeout
					delay1--;
					if (delay1 == 0)
					{
						nTimeout--;
	}	}	}	}	}

	if (rxStatus == 2)
	{
		if (ts_bit(rcsta2, FERR) != 0)
		{
			dummy = rcreg2;      //need to read the rcreg to clear FERR
		}
		else
		{
			if (ts_bit(rcsta2, OERR) != 0)
			{
				//need to read the rcreg to clear error
				cr_bit(rcsta2, CREN);
				st_bit(rcsta2, CREN);
			}
			else
			{
				retVal = rcreg2; //no error, so rx byte is valid
	}	}	}
I would suggest you change one function at a time and then do a test compilation to ensure you are not introducing errors to the code and so you know which bit is causing problems should you run into any.