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.

Serial RS232/UART communication

Other Parts Discussed in Thread: CC2541

Hi,

I am working with cc2541, I need to make a bidirectional communication with the PC to get configurations from the PC to store in the NVM.

so I need to build the interface from both sides: the cc2541 and the PC.

can I find an example including source code for that in the ble stack or any other place?

Thanks.

  • I just went through this and was surprised at the lack of examples and documentation for the UART.  However, from a few posts here and by looking at the source code in the "Components" directories, I pieced together the following quick example:

    First, you'll need to include "hal_uart.h" in your source file and add the symbol "HAL_UART_DMA=1" to the Preprocessor section of your project.  (Project \ Options \ C/C++ Compiler \ Preprocessor \ Defined symbols).  (This symbol is a bit of mystery to me - not sure whether using HAL_UART_ISR would be better or worse, but I couldn't get it to compile unless I used _DMA).

    Then, during init, do something like this:

      halUARTCfg_t uConfig;
    
    // Init the UART HalUARTInit(); uConfig.baudRate = HAL_UART_BR_115200; uConfig.flowControl = 0; uConfig.callBackFunc = uartCallback; HalUARTOpen(HAL_UART_PORT_0, &uConfig);

    To send a message, call HalUARTWrite:

      static uint8 initMessage[] = "Test (" __DATE__ " " __TIME__ ")\r\n";
    
      // Send out the initial test message
      HalUARTWrite ( HAL_UART_PORT_0, initMessage, sizeof(initMessage) );
    

    Finally, there's the callback function.  In my simple example, it's not needed, but for anything "real", you'll need to do something like this:

    void uartCallback( uint8 port, uint8 event ) {
       // look at "event" and do some magic ...  :-)
    }
    

    I haven't tried reading data, yet, but I'm hopeful that it'll be relatively simple.