void UART1Init(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB0_U1RX);
GPIOPinConfigure(GPIO_PB1_U1TX);
GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |UART_CONFIG_PAR_NONE));
//IntRegister(UART1_BASE,UART1IntHandler);
MAP_UARTIntDisable(UART1_BASE, 0xFFFFFFFF);
UARTIntEnable(UART1_BASE,UART_INT_RX|UART_INT_RT);
//UARTIntEnable(UART1_BASE,UART_INT_TX);
IntEnable(INT_UART1);
UARTEnable(UART1_BASE);
}
u8 Tx1Buffer[256];
u8 Tx1Counter=0;
u8 count1=0;
u8 com_data;
void UART1IntHandler(void)
{
uint32_t ulStatus;
ulStatus = UARTIntStatus(UART1_BASE,true);
if( ulStatus== UART_INT_RX )
{
UARTIntClear(UART1_BASE,UART_INT_RX);
com_data = HWREG(UART1_BASE + UART_O_DR);
//ANO_DT_Data_Receive_Prepare(com_data);
}
else if(ulStatus== UART_INT_TX )
{
HWREG(UART1_BASE + UART_O_DR) = Tx1Buffer[Tx1Counter++];
UARTIntClear(UART1_BASE,UART_INT_TX);
if(Tx1Counter == count1)
{
UARTIntDisable(UART1_BASE,UART_INT_TX);
}
}
else UARTIntClear(UART1_BASE,ulStatus);
}
void UART1Send(unsigned char *DataToSend ,u8 data_num)
{
u8 i;
for(i=0;i<data_num;i++)
{
Tx1Buffer[count1++] = *(DataToSend+i);
}
UARTIntEnable(UART1_BASE,UART_INT_TX);
}
不知道为什么一直进不了发送中断,这是我的主循环函数。
UART1Send(&a,1);
DelayUs(100000);
这是在住循环里运行的。总中断已打开,中断函数也注册了
DCD UART1IntHandler
extern UART1IntHandler
不明白啊,求解答。
Maka Luo:
中断向量表中是否有添加中断函数名称,建议参照TI例程来修改,详细见TIVAWARE中工程。
//*****************************************************************************//// uart_echo.c – Example for reading data from and writing data to the UART in// an interrupt driven fashion.//// Copyright (c) 2012-2015 Texas Instruments Incorporated. All rights reserved.// Software License Agreement// // Texas Instruments (TI) is supplying this software for use solely and// exclusively on TI's microcontroller products. The software is owned by// TI and/or its suppliers, and is protected under applicable copyright// laws. You may not combine this software with "viral" open-source// software in order to form a larger program.// // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL// DAMAGES, FOR ANY REASON WHATSOEVER.// // This is part of revision 2.1.1.71 of the EK-TM4C123GXL Firmware Package.////*****************************************************************************
#include <stdint.h>#include <stdbool.h>#include "inc/hw_ints.h"#include "inc/hw_memmap.h"#include "driverlib/debug.h"#include "driverlib/fpu.h"#include "driverlib/gpio.h"#include "driverlib/interrupt.h"#include "driverlib/pin_map.h"#include "driverlib/rom.h"#include "driverlib/sysctl.h"#include "driverlib/uart.h"
//*****************************************************************************////! \addtogroup example_list//! <h1>UART Echo (uart_echo)</h1>//!//! This example application utilizes the UART to echo text. The first UART//! (connected to the USB debug virtual serial port on the evaluation board)//! will be configured in 115,200 baud, 8-n-1 mode. All characters received on//! the UART are transmitted back to the UART.////*****************************************************************************
//*****************************************************************************//// The error routine that is called if the driver library encounters an error.////*****************************************************************************#ifdef DEBUGvoid__error__(char *pcFilename, uint32_t ui32Line){}#endif
//*****************************************************************************//// The UART interrupt handler.////*****************************************************************************voidUARTIntHandler(void){ uint32_t ui32Status;
// // Get the interrrupt status. // ui32Status = ROM_UARTIntStatus(UART0_BASE, true);
// // Clear the asserted interrupts. // ROM_UARTIntClear(UART0_BASE, ui32Status);
// // Loop while there are characters in the receive FIFO. // while(ROM_UARTCharsAvail(UART0_BASE)) { // // Read the next character from the UART and write it back to the UART. // ROM_UARTCharPutNonBlocking(UART0_BASE, ROM_UARTCharGetNonBlocking(UART0_BASE));
// // Blink the LED to show a character transfer is occuring. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
// // Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks. // SysCtlDelay(SysCtlClockGet() / (1000 * 3));
// // Turn off the LED // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
}}
//*****************************************************************************//// Send a string to the UART.////*****************************************************************************voidUARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count){ // // Loop while there are more characters to send. // while(ui32Count–) { // // Write the next character to the UART. // ROM_UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++); }}
//*****************************************************************************//// This example demonstrates how to send a string of data to the UART.////*****************************************************************************intmain(void){ // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUEnable(); ROM_FPULazyStackingEnable();
// // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
// // Enable the GPIO port that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
// // Enable the GPIO pins for the LED (PF2). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
// // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
// // Enable processor interrupts. // ROM_IntMasterEnable();
// // Set GPIO A0 and A1 as UART pins. // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
// // Configure the UART for 115,200, 8-N-1 operation. // ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
// // Enable the UART interrupt. // ROM_IntEnable(INT_UART0); ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
// // Prompt for text to be entered. // UARTSend((uint8_t *)"\033[2JEnter text: ", 16);
// // Loop forever echoing data through the UART. // while(1) { }}
Qiusen He:
回复 Maka Luo:
你好,谢谢您的解答,我使用的是KEIL,在相应的启动文件中已经加入该中断函数且名字相同。我想用的是通过中断发送,如果采用例程中的发送方式,会有一个等待时间,会增大MCU的开销。请问有解决办法吗?
xyz549040622:
回复 Qiusen He:
开中断发送的话,你配置好,只需要给FIFO中送数据就好了,就会自动发送出去的。
TI中文支持网
