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.

CC2640 串口接收

Other Parts Discussed in Thread: CC2650, CC2640, LAUNCHXL-CC2650

串口接收外设数据时候,运行到信号量阻塞处Semaphore_pend就卡死,是什么原因。

注:串口发送数据可以成功

  • 用的是例程C:\ti\simplelink_cc2640r2_sdk_4_30_00_08\examples\rtos\CC2640R2_LAUNCHXL\drivers\uartecho吗
  • 用的是例程C:\ti\tirtos_cc13xx_cc26xx_2_21_01_08\examples\TI\CC2650_LAUNCHXL\drivers\uartecho
  • 看下这里的说明:dev.ti.com/.../node
    默认读取是阻塞模式
  • 看了文档说明,将板卡上的串口收发连到了一起,仍然未收到数据。
  • 原始uartecho例程沒有用Semaphore_pend阿,你是不是用到修改過的例程,建議你重新import一份新的uartecho例程再測試看看
  • 上午重装了IAR环境,重新导入示例程序。软件修改情况:根据硬件端口定义重新设置了Board_UART_RX、Board_UART_TX,串口发送数据和接收数据分别建了一个任务。硬件这边的连接情况是:cc2640处理器的uart串口挂接EC20模块,将EC20的串口收发连接到了一起。故障现象是:串口可以打开,可以通过串口发送AT指令,接收数据的任务调度函数UART_read(uart, &recputput, 3)收不到EC20反馈的数据。
  • 這個根本不是原始的UARTecho例程,原始的檔案應該如附件

    /*
     * Copyright (c) 2015-2016, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /*
     *  ======== uartecho.c ========
     */
    
    /* XDCtools Header files */
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    
    /* BIOS Header files */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    
    /* TI-RTOS Header files */
    #include <ti/drivers/PIN.h>
    #include <ti/drivers/UART.h>
    
    /* Example/Board Header files */
    #include "Board.h"
    
    #include <stdint.h>
    
    #define TASKSTACKSIZE     768
    
    Task_Struct task0Struct;
    Char task0Stack[TASKSTACKSIZE];
    
    /* Global memory storage for a PIN_Config table */
    static PIN_State ledPinState;
    
    /*
     * Application LED pin configuration table:
     *   - All LEDs board LEDs are off.
     */
    PIN_Config ledPinTable[] = {
        Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        Board_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        PIN_TERMINATE
    };
    
    /*
     *  ======== echoFxn ========
     *  Task for this function is created statically. See the project's .cfg file.
     */
    Void echoFxn(UArg arg0, UArg arg1)
    {
        char input;
        UART_Handle uart;
        UART_Params uartParams;
        const char echoPrompt[] = "\fEchoing characters:\r\n";
    
        /* Create a UART with data processing off. */
        UART_Params_init(&uartParams);
        uartParams.writeDataMode = UART_DATA_BINARY;
        uartParams.readDataMode = UART_DATA_BINARY;
        uartParams.readReturnMode = UART_RETURN_FULL;
        uartParams.readEcho = UART_ECHO_OFF;
        uartParams.baudRate = 9600;
        uart = UART_open(Board_UART0, &uartParams);
    
        if (uart == NULL) {
            System_abort("Error opening the UART");
        }
    
        UART_write(uart, echoPrompt, sizeof(echoPrompt));
    
        /* Loop forever echoing */
        while (1) {
            UART_read(uart, &input, 1);
            UART_write(uart, &input, 1);
        }
    }
    
    /*
     *  ======== main ========
     */
    int main(void)
    {
        PIN_Handle ledPinHandle;
        Task_Params taskParams;
    
        /* Call board init functions */
        Board_initGeneral();
        Board_initUART();
    
        /* Construct BIOS objects */
        Task_Params_init(&taskParams);
        taskParams.stackSize = TASKSTACKSIZE;
        taskParams.stack = &task0Stack;
        Task_construct(&task0Struct, (Task_FuncPtr)echoFxn, &taskParams, NULL);
    
        /* Open LED pins */
        ledPinHandle = PIN_open(&ledPinState, ledPinTable);
        if(!ledPinHandle) {
            System_abort("Error initializing board LED pins\n");
        }
    
        PIN_setOutputValue(ledPinHandle, Board_LED1, 1);
    
        /* This example has logging and many other debug capabilities enabled */
        System_printf("This example does not attempt to minimize code or data "
                      "footprint\n");
        System_flush();
    
        System_printf("Starting the UART Echo example\nSystem provider is set to "
                      "SysMin. Halt the target to view any SysMin contents in "
                      "ROV.\n");
        /* SysMin will only print to the console when you call flush or exit */
        System_flush();
    
        /* Start BIOS */
        BIOS_start();
    
        return (0);
    }
    

  • 您发的这个是确实是例程文件,我用的也是这个uartecho.c文件。我跟您发的截图是跟进到 uart_read()这个函数后的底层操作,也就是UARTCC26XX.c这个文件中的内容。

  • 你是卡在UART_read還是UART_write? 硬件是自己做的嗎?
  • 在UART_read接收时候有问题,UART_write没问题 可以成功发送数据,硬件是自己设计的
  • 通过例程中的回显方式,可以在串口正常显示数据吗
    关于阻塞:UART_MODE_BLOCKING uses a semaphore to block while data is being sent. The context of calling UART_read() or UART_write() must be a Task when using UART_MODE_BLOCKING. The UART_write() or UART_read() call will block until all data is sent or received, or the write timeout or read timeout expires, whichever happens first.
  • 你有沒有LAUNCHXL-CC2650?如果有,先試試同樣的程序能不能在LAUNCHXL-CC2650上正確運行