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
Zigbee TX, RX Port From 1 to USART 2
Moderator: Benj
- Steve
- Matrix Staff
- Posts: 3422
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: Zigbee TX, RX Port From 1 to USART 2
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
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.
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.
- Steve
- Matrix Staff
- Posts: 3422
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: Zigbee TX, RX Port From 1 to USART 2
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
Boy, that was fast.
You will be missed. Enjoy.
Anybody else out there can help, I'd much appreciate it.
Ondra
You will be missed. Enjoy.
Anybody else out there can help, I'd much appreciate it.
Ondra
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Zigbee TX, RX Port From 1 to USART 2
Hello Ondra,
Ok here is how its done,
Init Section.
Replace with
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.
replace with
Finally Receive Char Function.
Replace with
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.
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
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
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;
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
} } }
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
} } }
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel