微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI无线射频设计 > 请教TI工程师CC1310串口中断问题

请教TI工程师CC1310串口中断问题

时间:12-23 整理:3721RD 点击:

TI工程师您好

我有几个问题请教一下

1:TI的串口中断是用的回调,假如串口正在接收数据,这时我在主线程里发送数据会有什么问题吗?

2:串口的32字节缓冲是发送和独立共享的还是 发送就是发送的 接收就是接收的 ?

3:我用了最新的串口驱动,利用中断读数据,但是我测试发现中断是来一个数据中断一次,并且再次触发中断必须在中断里read一下,这种情况导致一个问题出现,就是我发送100个字节的时候一次发送完,后面我再打印接收的数据发现本来我发的是1234567890结果后面几个字节偶尔会间隔丢失,只会受到13579。

不知道是否有更好的例程!方便的话给我一份,谢谢, jnq123@qq.com

1. 没有问题

2.接受 发送是独立的FIFO缓冲,请看http://www.ti.com/lit/ug/swcu117h/swcu117h.pdf 19.2章

3, 是哪一个例子? Uartecho? 可修改接收长度

您好工程师

感谢您的回答

串口接收发送丢失的情况 我发现是 波特率太高导致,我降低到19200 就很好了 

TI工程师您好

我在下面的测试发现 串口 我在及短的时间内发送数据,,会导致串口中断不再响应,,,感觉应该是 发满了 缓冲区,,,这时 如果 我想办法 1310的串口发送一个数据 那么串口就活了。。。

极短时间是怎么做到呢?代码贴出来?

TI工程师您好

我就是用下面这个代码做的,我用间隔10MS的时间发送100个字节,连续发送几次 就会死掉,然后等待多久也不会再次工作,但是无意中触发一下串口的发送,他又活了。。。

/*
* Copyright (c) 2015, 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 ========
*/
/***** Includes *****/
#include "UartTask.h"

/* XDCtools Header files */
//#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>


#include <ti/drivers/rf/RF.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/drivers/uart/UARTCC26XX.h>

/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>
#include <ti/drivers/UART.h>

/* Example/Board Header files */
#include "Board.h"
#include <time.h>
#include <ti/sysbios/hal/Seconds.h>

extern time_rx_cs;

//#include <stdint.h>

/***** Defines *****/
#define UART_TASK_STACK_SIZE 2048
#define UART_TASK_PRIORITY 2

//#define UART_EVENT_ALL 0xFFFFFFFF
//#define UART_EVENT_PRINT 0x00000001

//add by barbara -- begin
uint8_t len; ///length of RX'ed packet
int8_t payload[128]; ///payload of RX'ed packet
//add by barbara -- end

#define UART_ACTIVITY_LED Board_LED4


/***** Variable declarations *****/
static Task_Params uartTaskParams;
Task_Struct uartTask; /* not static so you can see in ROV */
static uint8_t uartTaskStack[UART_TASK_STACK_SIZE];
Event_Struct uartEvent; /* not static so you can see in ROV */
static Event_Handle uartEventHandle;

/***** Prototypes *****/
static void uartTaskFunction(UArg arg0, UArg arg1);

char a[10];
void Int_to_Ascii(uint16_t i);


UART_Params uartParams;

int RxBufPos = 0;
int RxBufRead = 0;
uint8_t Uart_TxBuf[UART_FIFO_FULL_SIZE];
int TxBufPos = 0;

char Uart_TxTempBuf[120];

extern time_t t1;
extern struct tm *ltm;
extern char *curTime;
extern int time_rx_cs;
/***** Function definitions *****/

// Callback function
void Uart_ReadCallback(UART_Handle handle, void *rxBuf, size_t size)
{
// Copy bytes from RX buffer to TX buffer
int i;

UART_readCancel(handle);

if((size<120)&&(size>0))
{

for (i = 0; i < size; i++) {
if(RxBufPos != UART_FIFO_FULL_SIZE )
{
Uart_RxBuf[RxBufPos] = ((uint8_t *)rxBuf)[i];
RxBufPos++;
}
}

time_rx_cs=0;
}
// UART_read(handle, uart_da_buf, 1);
UART_read(uart, Uart_RxTempBuf, 1);

/*
for (i = 0; i < size; i++) {
if(RxBufPos != UART_FIFO_FULL_SIZE )
{
Uart_RxBuf[RxBufPos] = ((uint8_t *)rxBuf)[i];
RxBufPos++;
}
else
{
RxBufPos = 0;
Uart_RxBuf[RxBufPos] = ((uint8_t *)rxBuf)[i];
RxBufPos++;
}
}
*/

//// // Echo the bytes received back to transmitter
//Uart_TxBuf[0] = ((uint8_t *)rxBuf)[0];


// Start another read, with size the same as it was during first call to UART_read()

// if(Uart_RxBuf[RxBufPos-1] == 'Z')
{
// UART_write(uart, "Send", 4);
//post event to rf
// Uart_PostEvent(UART_EVENT_RECEIVED);
}
/**/
}

// Callback function
void Uart_WriteCallback(UART_Handle handle, void *txBuf, size_t size)
{

// Start another read, with size the same as it was during first call to UART_read()
UART_read(handle, Uart_RxTempBuf, 1);

}


void UartTask_init() {

/* Create event used internally for state changes */
Event_Params eventParam;
Event_Params_init(&eventParam);
Event_construct(&uartEvent, &eventParam);
uartEventHandle = Event_handle(&uartEvent);

/* Create the node task */
Task_Params_init(&uartTaskParams);
uartTaskParams.stackSize = UART_TASK_STACK_SIZE;
uartTaskParams.priority = UART_TASK_PRIORITY;
uartTaskParams.stack = &uartTaskStack;
Task_construct(&uartTask, (Task_FuncPtr)uartTaskFunction, &uartTaskParams, NULL);

/* Create a UART with data processing off. */

UART_Params_init(&uartParams);
uartParams.readMode = UART_MODE_CALLBACK;
uartParams.readCallback = Uart_ReadCallback;
uartParams.writeCallback = Uart_WriteCallback;
uartParams.writeMode = UART_MODE_CALLBACK;

uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 57600;
uart = UART_open(Board_UART0, &uartParams);

UART_control(uart, UARTCC26XX_CMD_RETURN_PARTIAL_ENABLE, NULL);

if (uart == NULL) {
System_abort("Error opening the UART");
}
//PIN_setOutputValue(ledPinHandle, Board_LED2, 1);
UART_write(uart, "", 0);
}


extern void rx_exit(void);
/*
* ======== echoFxn ========
* Task for this function is created statically. See the project's .cfg file.
*/
static void uartTaskFunction(UArg arg0, UArg arg1)
{
UART_read(uart, Uart_RxTempBuf, 1);
/* Loop forever echoing */
while (1)
{

/* Wait for event */

uint32_t events = Event_pend(uartEventHandle, 0, UART_EVENT_ALL, BIOS_WAIT_FOREVER);
//If new ADC value, send this data
if(events & UART_EVENT_PRINT)
{
if((len<120)&&(len>0))
UART_write(uart, payload, len);
}


if(events & UART_EVENT_RECEIVED)
{

// UART_write(uart, Uart_RxBuf, RxBufPos);

xxx=RxBufPos;

RxBufPos = 0;


}
if(events & UART_EVENT_FORWARD)
{

}
}
}
/* Post event */
void Uart_PostEvent(uint32_t event)
{
Event_post(uartEventHandle, event);
}


void Int_to_Ascii(uint16_t i)
{
int n;
for(n=9;n>0;n--){
a[n]=(i%10);
if(a[n]!=0)
a[n]+=0x30;
else
a[n]=0;
i/=10;
}
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top