串口与FPGA通信问题

2019-08-14 04:11发布

使用FPGA发送数据,STM32串口接收数据。两方使用串口调试助手都能正常,但是使用FPGA与stm32进行通信时数据乱码,可能是什么原因。
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "lcd.h"
#include "usart.h"  
#include "adc.h"
//ALIENTEK战舰STM32开发板实验17
//ADC 实验  
//技术支持:www.openedv.com
//广州市星翼电子科技有限公司   
 int main(void)
 {
  u8  t;
u8  len;
u16 times=0; 
    u16 adcx;
int i;
long int  usart = 0;
long int  time_int = 0;
long int  zhan_int = 0;
float time_float = 0;
float zhan_float = 0;
double temp;
int a[15] = {0};
//int i,j,k;
delay_init();     //延时函数初始化  
NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
uart_init(19200); //串口初始化为9600
  LED_Init();     //LED端口初始化
LCD_Init();
  Adc_Init();   //ADC初始化

POINT_COLOR=RED;//设置字体为红 {MOD}
LCD_ShowString(60,50,200,16,16,"Display test");
LCD_ShowString(60,70,200,16,16,"By Donny");
LCD_ShowString(60,90,200,16,16,"2015/7/17");
//显示提示信息
POINT_COLOR=BLUE;//设置字体为蓝 {MOD}
// LCD_ShowString(60,130,200,16,16,"Time:");
// LCD_ShowString(60,180,200,16,16,"Duty:");
// LCD_ShowString(60,230,200,16,16,"Usart:");
//
// LCD_ShowString(220,130,200,16,16,"us");
// LCD_ShowString(220,180,200,16,16,"%");
// LCD_ShowString(220,230,200,16,16,"Hz");      
//LCD_ShowString(60,150,200,16,16,"ADC_CH0_VOL:0.000V");       
while(1)
{
//adcx=Get_Adc_Average(ADC_Channel_1,10);
//LCD_ShowxNum(156,130,adcx,4,16,0);//显示ADC的值
//temp=(float)adcx*(3.3/4096);
//adcx=temp;
//LCD_ShowxNum(156,150,adcx,1,16,0);//显示电压值
//temp-=adcx;
//temp*=1000;
//LCD_ShowxNum(172,150,temp,3,16,0X80);
//LED0=!LED0;
//delay_ms(250);
if(USART_RX_STA&0x8000)
{   
//len=USART_RX_STA&0x3fff;//得到此次接收到的数据长度
//printf(" 您发送的消息为: ");
//for(i=0;i<15;i++)
//USART_SendData(USART1, USART_RX_BUF);//向串口1发送数据
for(i=0;i<15;i++)
{
a = USART_RX_BUF;
}
// time_int = USART_RX_BUF[0];
// time_int = time_int <<8;
// time_int = time_int + USART_RX_BUF[1];
// time_int = time_int <<8;
// time_int = time_int + USART_RX_BUF[2];
// time_int = time_int <<8;
// time_int = time_int + USART_RX_BUF[3];
// time_float = time_int * 1.0 / 400;
// time_int = time_float;
// time_float = time_float - time_int;
// time_float = time_float * 1000;
// LCD_ShowxNum(156,130,time_int,7,16,0);
// LCD_ShowxNum(172,130,time_float,7,16,0);
//
// zhan_int = USART_RX_BUF[4];
// zhan_int = zhan_int <<8;
// zhan_int = zhan_int + USART_RX_BUF[5];
// zhan_int = zhan_int <<8;
// zhan_int = zhan_int + USART_RX_BUF[6];
// zhan_int = zhan_int <<8;
// zhan_int = zhan_int + USART_RX_BUF[7];
// zhan_float = zhan_int * 1.0 / 400;
//
// usart = USART_RX_BUF[8];
// usart = usart <<8;
// usart = usart + USART_RX_BUF[9];
// usart = usart <<8;
// usart = usart + USART_RX_BUF[10];
// usart = usart <<8;
// usart = usart + USART_RX_BUF[11];
// //temp = usart * (9000000 * 1.0 /9000048);
// //usart = (temp+0.5)/1;
//
// LCD_ShowxNum(156,230,usart,7,16,0);
//   
// zhan_float = zhan_float * usart * 100000;
// zhan_int = zhan_float;
// zhan_float = zhan_float - zhan_int;
// LCD_ShowxNum(156,180,zhan_int,7,16,0);
// LCD_ShowxNum(172,180,zhan_float,7,16,0);
// delay_ms(5);

//while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束




//printf(" ");//插入换行
USART_RX_STA=0;


if(a[0] == 0x0e)
{
LCD_ShowxNum(20,150,a[1],4,16,0);
LCD_ShowxNum(70,150,a[2],4,16,0);
LCD_ShowxNum(120,150,a[3],4,16,0);
LCD_ShowxNum(170,150,a[4],4,16,0);
LCD_ShowxNum(20,180,a[5],4,16,0);
LCD_ShowxNum(70,180,a[6],4,16,0);
LCD_ShowxNum(120,180,a[7],4,16,0);
LCD_ShowxNum(170,180,a[8],4,16,0);
LCD_ShowxNum(20,230,a[9],4,16,0);
LCD_ShowxNum(70,230,a[10],4,16,0);
LCD_ShowxNum(120,230,a[11],4,16,0);
LCD_ShowxNum(170,230,a[12],4,16,0);
}
}
 }

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。