This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

UART programming

Other Parts Discussed in Thread: Z-STACK, CC2530
In the manual 'HAL Drives Application Programming interface' (Document nr. F8W-2005-1504)
 
[page 22] 
section 9.6  - HalUARTIoctl()  function
 
I have two problems with HalUARTIoctl function
 
Problem 1) In the example code for zstack 1.4.3 e there are no declarations for  the parameter HAL_UART_IOCTL_FLUSH
 
Problem 2) the function HalUARTIoctl() is no defined anywhere
 
In file hal_uart.h I found only the declaration:
 
extern uint8 HalUARTIoctl ( uint8 port, uint8 cmd, halUARTIoctl_t *pIoctl );
 
 
the IAR IDE compiler reports
 
for problem (1): "HAL_UART_IOCTL_FLUSH" is undefined
for problem (2): Error[e46]: Undefined external   "HalUARTIoctl::?relay" referred in ...
 
  • You have encountered an unfortunate hole in thie Driver API as this function is not implemented as you saw.

    Taking a quick look at the Z-Stack-v2.1.0, which is really geared at integrating the Z-Stack on the MSP430 processor family, the implementation of this API is as follows.

     

    /**************************************************************************************************
     * @fn      HalUARTIoctl()
     *
     * @brief   This function is used to get/set a control
     *
     * @param   port   - UART port
     *          cmd    - Command
     *          pIoctl - control
     *
     * @return  none
     ***************************************************************************************************/
    uint8 HalUARTIoctl ( uint8 port, uint8 cmd, halUARTIoctl_t *pIoctl )
    {
      return HAL_UART_SUCCESS;
    }

    Basically a shell function at this point.

     

  • Thanks for your reply.
    This is a bad news
    I need to flush Rx buffer of the UART port.
    How I can do it using HAL driver for UART ?
    I am not an expert programmer in C language for embedded system, so a very simple trick that I'm using is this:
    void flushUART (uint8 port )
    {
      uint16 bytesRead;
      /* Read the number of bytes in Rx buffer      */
      uint16 rxBufLen = Hal_UART_RxBufLen(port);
      /* Dummy buffer for flushing                          */
      char rxbuf [ rxBufLen + 1 ];
      /* Read all the data of Rx buffer to flush it */
      bytesRead  =  HalUARTRead( SERIAL_APP_PORT,  rxbuf,  rxBufLen );
    }
    Is there a better system to do the flush of the UART ?
  • errata corrige

    the code that I'm trying is this
    void flushUART (uint8 port, uint8 cmd )
    {
      uint16 bytesRead;
     
      /* Dummy buffer declaration */
      char rxbuf[100];
      /* Read the number of bytes in Rx buffer      */
      uint16 rxBufLen = Hal_UART_RxBufLen(port);
     
      /* Prevent dummy buffer overflow              */
      if (rxBufLen > 100)
      rxBufLen = 100; 
      /* Read all the data of Rx buffer to flush it */
      bytesRead = HalUARTRead( port, rxbuf, rxBufLen );
    }
    as I wrote before, I am not an expert programmer in C language...
  • I think this seems appropriate.  Reviewing the implementation of the HalUARTRead() function indicates that it will not return "more" data than the Rx buffer has in it.  Even if  you specify a length, using your example rxBufLen, which is greater than the actual number of bytes in the Rx buffer, the HalUARTRead() function will return only the number of bytes that were in the buffer.

     

  • Hi

    I have issue regarding code that when i send some real time data it transmit accurately. when i add new data then it over write the previously written data from left and if written data less that previously send data then it transmit new data with the previous data . I tried the UARTflush code but it does not resolve my issue .I am using cc2530 to send real time data between router and coordinator . can any one help me in this regards

  • You say you are using cc2530 to send data between router and coordinator in real time. Does this mean that you continuously sending UART data to CC2530?
  • i am sending data from port 0 of serial port real time and by cc2530 coordinator send it to cc2530 router
  • What is the UART command you use? MT command or your private one?

  • HalUARTRead(0, TxBuf, 12);

    uint16 HalUARTWrite(uint8 port, uint8 *buf, uint16 len);

    void flushUART (uint8 port)
    {
    uint16 bytesRead;

    /* Dummy buffer declaration */
    char rxbuf[100];
    /* Read the number of bytes in Rx buffer */
    uint16 rxBufLen = Hal_UART_RxBufLen(port);

    /* Prevent dummy buffer overflow */
    if (rxBufLen > 100)
    rxBufLen = 100;
    /* Read all the data of Rx buffer to flush it */
    bytesRead = HalUARTRead( port, rxbuf, rxBufLen );

    }

    these codes i use in coding .i never use mt commands because of no devices found error . i do coding in generic app .c by adding HAL UART functions

  • OK, can you show me how you do in your application to receive UART data?
  • /*********************************************************************
    * @fn GenericApp_SendTheMessage
    *
    * @brief Send "the" message.
    *
    * @param none
    *
    * @return none
    */
    static void GenericApp_SendTheMessage( void )
    {

    uint8 strLen = 0;
    HalUARTRead(0, TxBuf, 12);
    // flushUART (0);

    strLen = (uint8)osal_strlen( (char*)TxBuf );


    char theMessageData[] = "NO SERIAL IN";
    if(strLen==0)

    {

    if ( AF_DataRequest( &GenericApp_DstAddr, &GenericApp_epDesc,
    GENERICAPP_CLUSTERID,
    (byte)osal_strlen( theMessageData ) + 1,
    (byte *)&theMessageData,
    &GenericApp_TransID,
    AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
    {
    // Successfully requested to be sent.
    #if defined( LCD_SUPPORTED )
    HalLcdWriteString( theMessageData, HAL_LCD_LINE_1 );
    HalLcdWriteStringValue( "sent:", strLen, 10, HAL_LCD_LINE_2 );
    flushUART (0);

    #endif
    }
    else
    {
    // Error occurred in request to send.
    }

    }
    else
    {
    if ( AF_DataRequest( &GenericApp_DstAddr, &GenericApp_epDesc,
    GENERICAPP_CLUSTERID,
    (byte)osal_strlen( TxBuf ) + 1,
    (byte *)&TxBuf,
    &GenericApp_TransID,
    AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
    {




    // Successfully requested to be sent.

    #if defined( LCD_SUPPORTED )
    HalLcdWriteString( TxBuf, HAL_LCD_LINE_1 );
    HalLcdWriteStringValue( "sent:", strLen, 10, HAL_LCD_LINE_2 );

    #endif
    // for(int y; y<strLen;y++)
    // {
    //TxBuf[12]=0;
    //

    // }

    else
    {
    // Error occurred in request to send.
    }



    }

    //flushUART (0);

    //theMessageData[12]=0;

    }
    #if defined( IAR_ARMCM3_LM )
  • TxBuf never clear after sending receive data
  • I suggest you clear TxBuf before you call HalUARTRead.
  • How often does your application call GenericApp_SendTheMessage()? If I remember correct, it is called every 5 seconds. If your UART host application send UART message too fast and GenericApp_SendTheMessage is called only once every 5 seconds, there is problem in RX buffer.
  • what should i do now ??
  • Try to change GENERICAPP_SEND_MSG_TIMEOUT to 200. And tell me how often you send 12 byte from UART host applicaiton to CC2530.
  • #define GENERICAPP_SEND_MSG_TIMEOUT 5000 should i change it to 200????i send data 3 times in a minuite
  • Your current implementation is polling for UART information and I think it is not a good idea. I suggest you register a UART RX callback and call GenericApp_SendTheMessage to send message when there is RX data coming.
  • any example for this ???
  • You can refer to MT_UartInit() and RX callback is to refer to uartConfig.callBackFunc.
  • but actually my issue is that buffers not clear i dont think it will resolve with this approach what u say
  • You said "i send data 3 times in a minuite". May I know the data you send in this 3 times?
  • Maybe you can try to remove the following define from compile options

    ZTOOL_P1

    MT_TASK

    MT_SYS_FUNC

    MT_ZDO_FUNC