Zigbee TX, RX Port From 1 to USART 2

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Contact:

Zigbee TX, RX Port From 1 to USART 2

Post 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

User avatar
Steve
Matrix Staff
Posts: 3183
Joined: Tue Jan 03, 2006 3:59 pm
Contact:

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

Post 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

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Contact:

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

Post 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.

User avatar
Steve
Matrix Staff
Posts: 3183
Joined: Tue Jan 03, 2006 3:59 pm
Contact:

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

Post 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.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Contact:

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

Post by Ondra »

Boy, that was fast.
You will be missed. Enjoy.
Anybody else out there can help, I'd much appreciate it.

Ondra

User avatar
Benj
Matrix Staff
Posts: 14878
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

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

Post 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.

Post Reply