This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Writing a better code in better format

Hi guys I am a new learner in this field;
I am working on STR912x;

I am using the following code for sending a string which have saved in memory

          memset(sign_packet_data, 0, 0xFF);
              sign_packet_data = &sign_UART_txBuff[0];//char *sign_packet_data =0;
              strncpy(sign_packet_data, cmd,16);//cmd stores the string
              if(sign_packet_data != 0)
              {
               NbrOfDataToTransfer = strlen(sign_UART_txBuff);
               while(NbrOfDataToTransfer--)
               {
                UART_SendData(UART0, sign_UART_txBuff[TxCounter++]);
                while(UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOFull) != RESET);
               }
               }

may i have a better way to do the same.

Parents
  • OK, so this is rather specifc:

    while( UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOFull) != RESET );
    


    But it could easily (and should?) be generalised to:

    while( UART_IsBusy(UART0) );
    

    or similar - thus keeping all the target-specific detail separate from the generic string handling.

Reply
  • OK, so this is rather specifc:

    while( UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOFull) != RESET );
    


    But it could easily (and should?) be generalised to:

    while( UART_IsBusy(UART0) );
    

    or similar - thus keeping all the target-specific detail separate from the generic string handling.

Children
No data