[HC08 - MC1321] Uart & ZTC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[HC08 - MC1321] Uart & ZTC

3,924 Views
CecchiSandrone
Contributor II
Hi,

I'm writing a simple Zigbee app, with a coordinator and a router.
After the network is created, I send a packet from router to coordinator and the coordinator writes the packet contents to the UART2 port (USB). I'm sniffing these data with a serial port watcher and, yes, I see the packet data but together there are some strange characters. Is this dued to ZTC?
Labels (1)
0 Kudos
Reply
10 Replies

928 Views
Mads
Contributor V
Cecchi,
 
the ZTC is using the UART interface if it is enabled, so if you want to use the UART your self, then you must make sure that ZTC is disabled.
 
this is done on the component SSM in Beekit.
 
BR,
Mads
0 Kudos
Reply

928 Views
CecchiSandrone
Contributor II
Ok..thanks for help!
0 Kudos
Reply

928 Views
CecchiSandrone
Contributor II
Ok now I disabled ZTC and in fact I don't receive strange symbols due to ZTC. Now, the problem is that I can't see correctly my string on UART. For example I want to receive: "Link quality = 256" and instead I receive: Li...Œ... ..KaN.P...

This is the code used:
Code:
/* Initialize UART */Uart2_SetRxCallBack(AppUartRxCallBack);Uart2_SetBaud(gUARTBaudRate38400_c);/* Format string */ItoaMsg(&msg[0],"Link Quality = ",pIndication->linkQuality,3,0);/* Send message via UART */(void)Uart2_Transmit(msg,sizeof(msg),NULL);

Maybe do I wrong UART initialization? What's the 3rd parameter of Uart2_Transmit? Is it correct to set NULL?


0 Kudos
Reply

928 Views
Mads
Contributor V
you problem is that you free the msg, that contains the data before you are done transmitting.
 
here is an example on how to do it:
 
Add to top of BeeApp.c
uint8_t UartTxBuffer[20];
uint8_t UartTxLength = 0;
bool_t  UartTxFlag = FALSE;
const uint8_t text[] = "Welcome \r\n";
Add to BeeAppInit():
UartX_SetBaud(gUARTBaudRate19200_c);
UartX_Transmit(text, sizeof(text), NULL);
 
Example of how your BeeAppIndication() function could look like:
void BeeAppDataIndication
  (
  void
  )
{
  apsdeToAfMessage_t *pMsg;
  zbApsdeDataIndication_t *pIndication;
  while(MSG_Pending(&gAppDataIndicationQueue))
  {
    /* Get a message from a queue */
    pMsg = MSG_DeQueue( &gAppDataIndicationQueue );
    /* ask ZCL to handle the frame */
    pIndication = &(pMsg->msgData.dataIndication);
    /*
      Note: if multiple endpoints are supported by this app, insert
      endpoint filtering here...
      This app assumes only 1 active endpoint. APS layer has already
      filtered by endpoint and profile.
      Note: all multi-byte over-the-air fields are little endian.
      That is 0x1101 would come in byte order 0x01 0x11.
    */
    /* is the cluster for accelerometer? */
    if(pIndication->aClusterId[1] != appDataCluster[1]) {
      MSG_Free(pMsg); /* no, free it and we're done */
      continue;
    }
    /* handle the command */
    if(pIndication->aClusterId[0] == appDataCluster[0]) {
        if (UartTxFlag == FALSE) // only transmit if we are not already transmitting...
        {         
          UartTxFlag = TRUE;       
          FLib_MemCpy(UartTxBuffer, pIndication->pAsdu, pIndication->asduLength);          
          (void) UartX_Transmit(UartTxBuffer, pIndication->asduLength, UartTxCallBack);
        }       
    }
  
    /* Free memory allocated by data indication */
    MSG_Free(pMsg);
  }
}
 
This will transmit correctly over the uart.
Notice that tehe data from the Msg is copied so when the MSG_Free() is called we still got a copy of the data.
 
BR,
Mads Westergreen
 
 
0 Kudos
Reply

928 Views
CecchiSandrone
Contributor II
Mads, how do I define UartTxCallBack? What should be done in that function?
0 Kudos
Reply

928 Views
Mads
Contributor V
the callback is just used to clear the TxFlag when transmission is done so a second transmission is not initiated before the first is done.
 
static void UartTxCallBack(unsigned char const *pBuf) {
  (void) pBuf;
  UartTxFlag = FALSE; // Signal that Tx is done by setting tx flag to false
}                                       /* UartTxCallBack() */
 
 
Note the API is also described in the Platform reference manual, and the wirelessUART application show how you could use the uart driver.
 
BR,
Mads
0 Kudos
Reply

928 Views
CecchiSandrone
Contributor II
Excuse me again Mads...another problem :smileysad:
I tried to send another string message into BeeAppDataIndication but the UART output seems like this:

Welcome..
Te.¡¨ˆï..ç Œ.C.m..`a

Maybe is there a problem with buffers?

Here it is the code:
Code:

uint8_t UartTxBuffer[20];
uint8_t UartTxLength = 0;
bool_t  UartTxFlag = FALSE;
const uint8_t text[] = "Welcome\r\n";

void BeeAppInit
  (
  void
  )
{
......
 
  UartX_SetBaud(gUARTBaudRate19200_c);
  (void)UartX_Transmit(text, sizeof(text), NULL);

......
  }

void BeeAppDataIndication  (  void  ){  apsdeToAfMessage_t *pMsg;  zbApsdeDataIndication_t *pIndication;
  uint8_t msg[] = "Test message\n"
 
  while(MSG_Pending(&gAppDataIndicationQueue))  {    /* Get a message from a queue */    pMsg = MSG_DeQueue( &gAppDataIndicationQueue );    /* ask ZCL to handle the frame */    pIndication = &(pMsg->msgData.dataIndication);    /*      Note: if multiple endpoints are supported by this app, insert       endpoint filtering here...      This app assumes only 1 active endpoint. APS layer has already      filtered by endpoint and profile.      Note: all multi-byte over-the-air fields are little endian.      That is 0x1101 would come in byte order 0x01 0x11.    */    /* handle the command */    if(pIndication->aClusterId[0] == appDataCluster[0]) {             if(UartTxFlag == FALSE) // only transmit if we are not already transmitting...        {                   UartTxFlag = TRUE;                 (void)UartX_Transmit(msg,sizeof(msg),UartTxCallBack);        }                             }    /* Free memory allocated by data indication */    MSG_Free(pMsg);  }}static void UartTxCallBack(unsigned char const *pBuf) {  (void) pBuf;  UartTxFlag = FALSE; // Signal that Tx is done by setting tx flag to false}

 

0 Kudos
Reply

928 Views
Mads
Contributor V
I have tested the code so i know it works....
 
Please check what you actually are sending from the transmitting side - if you use the GenericApp the payload content is the accelerometer data and is ofcause binary.
 
Else use a ZigBee protocol analyzer to see what is sent over the air.
 
BR,
Mads
0 Kudos
Reply

928 Views
CecchiSandrone
Contributor II
It looks strange...as you can see I transmit 2 times a uint8_t[ ]. The first time the code works (welcome string) while the other (test message string) causes those strange characters. I will try better tomorrow...it's too late here (11 pm). Thanks again Mads

0 Kudos
Reply

928 Views
FPatrick
Contributor I
Hello,
 
I'm afraid, that the problem should be the same as was. The msg is a local variable, and you call an asynchronous function. The memory could be rewritten by the other portion of your program. As you can see in Mad's previous sample, he first copied the content of the message to the Uart tx buffer, and frees the msg.
Try to declare the msg as a global, and you will see.
 
Regards,
Pat


Message Edited by FPatrick on 2007-11-28 01:22 PM
0 Kudos
Reply