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.

Sensor Controller - UART example

Other Parts Discussed in Thread: CC2640, CC2650, CC2640R2F

Hi everyone,

I'm trying to implement a UART using the sensor controller example, but probably I'm doing something wrong. I created a new project and just copy the code from sensor controller to CCS.

This code:

// Start the UART emulator task
scifExecuteTasksOnceNbl(BV(SCIF_UART_TASK_ID));

// Enable baud rate generation
scifUartSetBaudRate(57600);

// Enable RX
scifUartSetRxEnableReqIdleCount(1);
scifUartRxEnable(1);

// Main loop
while (1) {

    // Loop back any received characters
    while (scifUartGetRxFifoCount()) {
        scifUartTxPutChar((char) scifUartRxGetChar());
    }
} 

I'm using PuTTy to see the characters coming from UART TX when I write something in the keyboard and nothing, do you know what i'm missing?

Thank you.

Best Regards,

Miguel 

  • Miguel,

    You did not specify what device you are trying to program.  Please provide the device or module you are using in this design.  Thanks,

    ~Leonard

  • Through SCS, you need to generate the related code first, and then you can find the related files, for example, scif.c, scif.h, main.c or main_tirtos.c, and else for a specific chipset, CC2640/CC2650 or CC2640R2.
    when generating the files, you will have to configure the UART port you want from the 'I/O mapping' menu.
    The setting could be confirmed in the scif.c and scif.h.
    actually, the main_xx.c and scif.c and scif.h only changed when changing the configuration like IO mapping and else.
    And simply you need to build the files from CCS or iAR. That is it.
    Simply you can confirm the UART operation through PC terminal program.

    In my case,

    I simply renamed the task creation parts as below and then call it from main.c from simplecentral or simpleperipheral.

    void ScUart_createTask(void)
    {
    Task_Params taskParams;

    // Configure the OS task
    Task_Params_init(&taskParams);
    taskParams.stack = ScUartTaskStack;
    taskParams.stackSize = sizeof(ScUartTaskStack);
    taskParams.priority = 4; // 3
    Task_construct(&ScUartTask, ScUart_taskFxn, &taskParams, NULL);

    // Create the semaphore used to wait for Sensor Controller ALERT events
    Semaphore_Params semParams;
    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_BINARY;
    Semaphore_construct(&semScTaskAlert, 0, &semParams);
    }
    #if 0
    int main(void) {

    // Initialize the PIN driver
    PIN_init(BoardGpioInitTable);

    // Configure the OS task
    ScUart_createTask();

    // Start TI-RTOS
    BIOS_start();
    return 0;

    } // main
    #endif

    Ji Won

  • For now I'm using CC2650 with smartRF06 Evaluation board, after I have a successful test with it I will change for other board.

    Thank you for your reply.

    Regards,

    Miguel

  • Thank you Ji Won for your reply.
    I changed the main program with main_tirtos.c and works fine so I tried the next step, that is send commands to a peripheral and check the answers. When i was testing that, I notice that the program leave the the Sensor Controller task when something is added to the RX buffer, but what i want is send the command first and then check the device answer, do you know if exists any mode or function for that?

    Best Regards,
    Miguel
  • Does "send commands to a peripheral" means that your peripheral application sends a command to external MCU over UART Tx?

    And if there are answers over UART Rx from the external MCU, you will handle that. right?

    If right,

    after sending a command to external MCU, your application will wait for something through "Semaphore_pend(Semaphore_handle(&semScTaskAlert), BIOS_WAIT_FOREVER);",

    and finally, something arrives, the waiting loop will be released and then your application will reach to "int rxFifoCount = scifUartGetRxFifoCount();"

    If needed, you can generate a handler to be used in peripheral application. The handler in peripheral application could handle the receiving parts I highlighted in red.

    ------------------------------------------------------------------------------------

       // Enable events (half full RX FIFO or 10 bit period timeout

       scifUartSetEventMask(BV_SCIF_UART_RX_FRAMING_ERROR | BV_SCIF_UART_ALERT_RX_FIFO_ABOVE_THR | BV_SCIF_UART_ALERT_RX_BYTE_TIMEOUT);

       char output[] = { "Terminal Debug Display Starts" };

       scifUartTxPutChars(output, sizeof(output));

       // Main loop

       while (1) {

           // Wait for an ALERT callback

           // Allow application to sleep until receiving the desired number of characters.

           Semaphore_pend(Semaphore_handle(&semScTaskAlert), BIOS_WAIT_FOREVER);

           // Clear the ALERT interrupt source

           scifClearAlertIntSource();

           // Echo all characters currently in the RX FIFO

           int rxFifoCount = scifUartGetRxFifoCount();

           // even though rxFifoCount is 0, the below posting should be used, and then APP CPU will clear the related event flags.

           //SimpleBLECentrall_scUartTransferHandler(rxFifoCount);

           while (rxFifoCount--) {

               char rx_data = scifUartRxGetChar();

               scifUartTxPutChar(rx_data);

           }

     

  • Hi Ji Won,
    You are right and you solution work, but i notice that I don't catch all caracters in pRxBuffer, only in the next cicle i'm able to see it, do you know why and how can I change it? It will be possible to flush de rxfifo or something like that to not collect garbage for the next cicles?

    Thank you.

    Best Regards,
    Miguel
  • As I understand, even though the external MCU sent 20 bytes in length, for example, your application will receive the data, divided into more than 1, because the RX interrupt is generated after at least 4 bytes filled. So, the 'rxFifoCount' will be continue to be updated before receiving the 20 bytes data.
    So, please monitor the count variable.

    Regarding the at least 4 bytes, you can find the related information from this forum.
    I hope this would be useful for you to solve this issue.

    BR,
    Ji Won

  • It is possible to change the number of bytes needed to generate an interrupt? For example 7 instead of 4.

    BR,
    Miguel

  • Regarding, I don't know how.

    In my case, I added one more Rx ring buffer in application side to avoid loss.

    But, FYI

    And, please refer to my post named "RTOS/CC2640R2F: how to signal an event from scs task to app task".