我用lm3s811写的uart中断成只能触发一次!每次必须复位一次才能触发一次!这是什么原因??
代码如下:
#include <hw_types.h>
#include <hw_memmap.h>
#include <hw_ints.h>
#include <hw_uart.h>
#include <interrupt.h>
#include <sysctl.h>
#include <gpio.h>
#include <uart.h>
#include <string.h>
//*****************************************************************************
//通过key触发相应管脚中断
//进入中断后,翻转LED电平
//
//*****************************************************************************
#define KEY_PERIPH SYSCTL_PERIPH_GPIOB
#define KEY_PORT GPIO_PORTB_BASE
#define KEY_PIN GPIO_PIN_5
// 防止JTAG失效
void jtagWait(void)
{
SysCtlPeripheralEnable(KEY_PERIPH); // 使能KEY所在的GPIO端口
GPIOPinTypeGPIOInput(KEY_PORT, KEY_PIN); // 设置KEY所在管脚为输入
if (GPIOPinRead(KEY_PORT, KEY_PIN) == 0x00) // 若复位时按下KEY,则进入
{
for (;;); // 死循环,以等待JTAG连接
}
SysCtlPeripheralDisable(KEY_PERIPH); // 禁止KEY所在的GPIO端口
}
//**********************************************************************************
//防止jtag被锁
//**********************************************************************************
// Send strings to the UART0.
void Uart0SendStrings(unsigned char *pStr)
{
while((*pStr!=' '))
{
//Sends the character ucData to the transmit FIFO for the specified port.
//If there is no space available in the transmit FIFO, this
//function will wait until there is space available before return-ing.
UARTCharPut(UART0_BASE, *(pStr++)); //发送字符,若FIFO满,自动等待
//Writes the character ucData to the transmit FIFO for the speci?ed port.
//This function does not block, so if there is no space available,
//then a false is returned, and the application will have to retry the function later.
//UARTCharPutNonBlocking(UART0_BASE, *(pStr++)); //发送字符,若FIFO满,返回false
}
}
long Uart0ReceiveStrings(unsigned char s[4],unsigned char a,unsigned char i)
{
while(UARTCharsAvail(UART0_BASE))
{
a= UARTCharGet(UART0_BASE);
s
=a;
i=i+1;
// SysCtlDelay(200);
// UARTCharPut(UART0_BASE, i+48);
}
// UARTCharPut(UART0_BASE, '/');
return i;
}
//主函数
int main(void)
{
unsigned char s[7];
unsigned char i;
unsigned int j;
unsigned char a;
//函数开始,调用Jta g防锁死程序
jtagWait();
// Set the clocking to run directly from the crystal.配置时钟
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_6MHZ);
// Enable the peripherals used by this example.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
// Set GPIO A0 and A1 as UART pins.
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
// Configure the UART for 115,200, 8-N-1 operation.
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 9600,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
UARTFIFOLevelSet(UART0_BASE,UART_FIFO_TX4_8,UART_FIFO_RX6_8);
UARTIntEnable(UART0_BASE,UART_INT_RX|UART_INT_RT);
IntEnable(INT_UART0);
IntMasterEnable();
for(;;);
}
void UART0_ISR(void)
{ unsigned char a;
unsigned long ulStatus;
IntMasterDisable();
ulStatus=UARTIntStatus(UART0_BASE,true);
UARTIntClear(UART0_BASE,ulStatus);
if((ulStatus&UART_INT_RX)||(ulStatus&UART_INT_RT))
{ a= UARTCharGet(UART0_BASE);
UARTCharPut(UART0_BASE,a);
}
IntEnable(INT_UART0);
IntMasterEnable();
}
此帖出自小平头技术问答
出现无法写的地址的时候,一般是由于你将程序的起始地址改变了。
一周热门 更多>