新人求教,根据UART-ECHO改的,但是不出数据
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/rom.h"
#include "driverlib/pin_map.h"
float a[3],w[3],angle[3],T;
unsigned char Re_buf[11],counter=0;
unsigned char sign;
//串口接收中断服务程序
void UARTIntHandler(void)
{
unsigned long ulStatus;
//获取中断状态
ulStatus = ROM_UARTIntStatus(UART1_BASE, true);
//清除中断标志
ROM_UARTIntClear(UART1_BASE, ulStatus);
//直到串口FIFO中没有数据时才退出循环
while(ROM_UARTCharsAvail(UART1_BASE))
{
//读串口接收的字符并回发
Re_buf[counter]=ROM_UARTCharsAvail(UART1_BASE);//不同单片机略有异
if(counter==0&&Re_buf[0]!=0x55) return; //第 0 号数据不是帧头,跳过
counter++;
if(counter==11) //接收到 11 个数据
{
counter=0; //重新赋值,准备下一帧数据的接收
sign=1;
}
}
}
int main(void)
{
//使能FPU
FPUEnable();
FPULazyStackingEnable();
//设置时钟直接使用外部晶振
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
//使能用到的外设
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
//配置PA0和PA1为串口0引脚
ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//使能中断
ROM_IntMasterEnable();
//配置UART0为115200,8-N-1
ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE ));
//使能串口中断
ROM_IntEnable(INT_UART1);
ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);
UARTIntHandler ();
extern unsigned char Re_buf[11],counter;
extern unsigned char sign;
while(1)
{
if(sign)
{
sign=0;
if(Re_buf[0]==0x55) //检查帧头
{
switch(Re_buf [1])
{
case 0x51:
a[0] = (short)(Re_buf [3]<<8| Re_buf [2])/32768.0*16;
a[1] = (short)(Re_buf [5]<<8| Re_buf [4])/32768.0*16;
a[2] = (short)(Re_buf [7]<<8| Re_buf [6])/32768.0*16;
T = (short)(Re_buf [9]<<8| Re_buf [8])/340.0+36.25;
break;
case 0x52:
w[0] = (short)(Re_buf [3]<<8| Re_buf [2])/32768.0*2000;
w[1] = (short)(Re_buf [5]<<8| Re_buf [4])/32768.0*2000;
w[2] = (short)(Re_buf [7]<<8| Re_buf [6])/32768.0*2000;
T = (short)(Re_buf [9]<<8| Re_buf [8])/340.0+36.25;
break;
case 0x53:
angle[0] = (short)(Re_buf [3]<<8| Re_buf [2])/32768.0*180;
angle[1] = (short)(Re_buf [5]<<8| Re_buf [4])/32768.0*180;
angle[2] = (short)(Re_buf [7]<<8| Re_buf [6])/32768.0*180;
T = (short)(Re_buf [9]<<8| Re_buf [8])/340.0+36.25;
break;
}
}
}
}
while(1) {}
}