TI中文支持网
TI专业的中文技术问题搜集分享网站

TMS320F28388D: UART使用DMA,怎么设置中断

Part Number:TMS320F28388DOther Parts Discussed in Thread:C2000WARE

例程中没看到相关发送完或接收完触发的DMA中断

Susan Yang:

您可以看一下

C2000Ware_3_04_00_00\driverlib\f2838x\examples\cm\uart 

下的 uart_ex2_loopback_udma

This example showcases how to use UDMA with UART to transfer and receive data

,

DSP应用:

我都说我看例程了,例程里面没有中断,实际应用不能像例程while一直等啊

while(UDMA_isChannelEnabled(UDMA_BASE, UDMA_CHANNEL_UART0_TX)); while(UDMA_isChannelEnabled(UDMA_BASE, UDMA_CHANNEL_UART0_RX));

,

Susan Yang:

DSP应用 说:我都说我看例程了

TI例程太多了,在提问时请详细说明使用、参考的例程名称

关于中断参考下面的代码,该程序使用 DMA 向 TX 写入 100 个字节,使用 DMA 从 RX(不带 fifo)读取 100 个字节,并在接收到 100 个字节后调用中断服务程序。

//#############################################################################
//
// FILE:uart_ex2_loopback_udma.c
//
// TITLE:UART loopback example
//
//! \addtogroup driver_example_cm_list
//! <h1>UART Loopback example with UDMA</h1>
//!
//! This example showcases how to use UDMA with UART to transfer and receive data
//!
//! This configures the UART in loopback mode and sends and receives data for
//! infinite time.
//! cm_common_config_c28x example needs to be run on C28x1 before running this
//! example on the CM core
//!
//! \b Configuration:
//!-Find correct COM port
//!-Bits per second = 115200
//!-Data Bits = 8
//!-Parity = None
//!-Stop Bits = 1
//!-Hardware Control = None
//!
//! \b External \b Connections \n
//!- None
//!
//! \b Watch \b Variables \n
//!- \b TxData- Data transmitted
//!- \b RxData- Data received
//!- \b errCount - Error count
//!
//
//#############################################################################
// $TI Release: $
// $Release Date: $
// $Copyright: $
//##############################################################################include <stdint.h>
#include <stdbool.h>
#include <string.h>#include "cm.h"
#include "driverlib_cm.h"#pragma DATA_ALIGN(ucControlTable, 1024)
UDMA_ControlTable ucControlTable[64];//
// Initialize the data arrays
//
uint8_t TxData[100];
uint8_t RxData[100];
//
// Function Prototypes
//
__interrupt void UART_RX_IntHandler(void);
void ConfigureUART(void)
{//// Configure UART with baud rate = 115200, dataWidth = 8//UART_setConfig(UART0_BASE,UART_CLK_FREQ , 9600,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |UART_CONFIG_PAR_NONE));//UART_setFIFOLevel(UART0_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8);//// Enable the UART0 module.//UART_enableModule(UART0_BASE);//// Enable loopback mode//UART_enableLoopback(UART0_BASE);
}void ConfigureDMA(uint8_t* TxDma, uint8_t* RxDma, uint8_t size)
{
//// Enable DMA for Tx snd Rx events//UART_enableDMA(UART0_BASE,UART_DMA_TX |UART_DMA_RX);//// Enable UDMA//UDMA_enable(UDMA_BASE);//// Point at the control table to use for channel control structures.//UDMA_setControlBase(UDMA_BASE, ucControlTable);//// Put the attributes in a known state for the uDMA software channel.// These should already be disabled by default.//UDMA_disableChannelAttribute(UDMA_BASE, UDMA_CHANNEL_UART0_TX, UDMA_CH_ATTR_ALL);UDMA_disableChannelAttribute(UDMA_BASE, UDMA_CHANNEL_UART0_RX, UDMA_CH_ATTR_ALL);//UDMA_enableChannelAttribute(UDMA_BASE, UDMA_CHANNEL_UART0_RX, UDMA_CH_ATTR_USEBURST);//// Configure the control parameters for the UART TX channels// Tx channel will be used to transfer data from the buffer to the UART Data// register.// Data size = 8// Source address increment = 8(data to be read from 8-bit buffer)// Destination address increment = 0 (data to be copied to a single address location)//// The arbitration size will be set to 1, which causes the uDMA controller// to re-arbitrate after 1 item is transferred.//UDMA_setChannelControlParams(UDMA_BASE, (UDMA_CHANNEL_UART0_TX | UDMA_PRI_SELECT),(UDMA_SIZE_8 | UDMA_SRC_INC_8 | UDMA_DST_INC_NONE| UDMA_ARB_1));UDMA_setChannelTransferParams(UDMA_BASE, (UDMA_CHANNEL_UART0_TX | UDMA_PRI_SELECT),TxDma, (void *)(UART0_BASE + UART_O_DR), UDMA_MODE_BASIC,size);//// Configure the control parameters for the UART RX channel.// Rx channel will be used to transfer data from the UART Data register to// the buffer.//// Data size = 8// Source address increment = 0(data to be read from a single address location)// Destination address increment = 8(data to be copied to a 8-bit buffer)//// The arbitration size will be set to 1, which causes the uDMA controller// to re arbitrate after 1 item is transferred.//UDMA_setChannelControlParams(UDMA_BASE, (UDMA_CHANNEL_UART0_RX | UDMA_PRI_SELECT),(UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8| UDMA_ARB_1));UDMA_setChannelTransferParams(UDMA_BASE, (UDMA_CHANNEL_UART0_RX | UDMA_PRI_SELECT),(void *)(UART0_BASE + UART_O_DR), RxDma, UDMA_MODE_BASIC,size);
}//
// Main
//
void main(void)
{uint8_t i;uint8_terrCount = 0;//// Disable WD, enable peripheral clocks.//CM_init();//// Configure the UART//ConfigureUART();for(i = 0; i < 100; i++){TxData[i] = i;RxData[i] = 0xF;}//// Configure the UDMA to read/write to the TX/RX buffers//ConfigureDMA(TxData, RxData, 100);//// Enable the UART0 interrupt on the processor (NVIC).//UART_registerInterrupt(INT_UART0,UART_RX_IntHandler);UART_disableInterrupt(UART0_BASE,0xFFFFFFFF);UART_enableInterrupt(UART0_BASE,UART_INT_DMARX);
/*
When the ìDMA is finished transferring data to the TX FIFO or from the RX FIFO, a dma_done signal is
sent to the UART to indicate completion. The dma_done status is indicated through the DMATXRIS and
DMARXIS bits of the UARTRIS register. An interrupt can be generated from these status bits by setting
the DMATXIM and DMARXIM bits in the UARTIM register.*///// Enable the UDMA channels//UDMA_enableChannel(UDMA_BASE, UDMA_CHANNEL_UART0_RX);UDMA_enableChannel(UDMA_BASE, UDMA_CHANNEL_UART0_TX);//// Wait until the complete transfer is done//while(UDMA_isChannelEnabled(UDMA_BASE, UDMA_CHANNEL_UART0_TX));while(UDMA_isChannelEnabled(UDMA_BASE, UDMA_CHANNEL_UART0_RX));//// Check the received data//for(i = 0; i < 16; i++){if(TxData[i] != RxData[i]){errCount++;}}//// Loop forever. Optional//while(1);
}
__interrupt void UART_RX_IntHandler(void)
{uint32_t ui32Status;//// Get the interrupt status.//ui32Status = UART_getInterruptStatus(UART0_BASE, UART_RAW_INT);//// Clear the asserted interrupts.//UART_clearInterruptStatus(UART0_BASE, ui32Status);}

,

DSP应用:

不能增加发送中断吗,在接收使能下面加个发送中断使能就会一直在中断中,无法跳出。除了改这里还需要改哪里吗

UART_enableInterrupt(UART0_BASE,UART_INT_DMARX);

UART_enableInterrupt(UART0_BASE,UART_INT_DMATX);

,

DSP应用:

还有个问题是我实际传输2560个字节,但是程序目前最多可传255个,大于这个数传输错误,请问该如何更改程序

赞(0)
未经允许不得转载:TI中文支持网 » TMS320F28388D: UART使用DMA,怎么设置中断
分享到: 更多 (0)

© 2024 TI中文支持网   网站地图 鲁ICP备2022002796号-1