新手上路
- 积分
- 29
- 金钱
- 29
- 注册时间
- 2020-4-1
- 在线时间
- 16 小时
|
10金钱
刚接触STM32没多久还是个小白,希望大家指导一下,用的原子哥的mini板,串口2接收角度模块的数据,串口1打印出来,目前在串口助手查看是可以正确读取到的。
我想在TFTLCD上把读到的变量数据显示出来,LCD_ShowString写的静态的字符串可以正确显示,但是加进去LCD_ShowNum显示变量就会白屏或者一直是0,
用Jlink调试了一下,设置的显示变量都是正常变化的,也尝试过把变量转换成字符串用LCD_ShowString显示,还是不行。
下边红色代码是我尝试显示的其中一条信息,不知道怎么写函数才能正确实现,希望大家指点一下我。。谢谢啦
#include "stm32f10x.h"
#include "string.h"
#include "delay.h"
#include "LED.h"
#include "usart.h"
#include "stdio.h"
#include "lcd.h"
/*
Keil: MDK5.10.0.2
MCU:stm32f103c8
????:
GY---STM32
1GY_RX---STM32_TX2(PIN_A2),STM32
2GY_TX---STM32_RX2(PIN_A3)
3STM32_TX1(PIN_A9)---FT232_RX,STM32
*/
static void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_X;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_X.NVIC_IRQChannel = USART2_IRQn;//????
NVIC_X.NVIC_IRQChannelPreemptionPriority = 0;//?????
NVIC_X.NVIC_IRQChannelSubPriority = 0;//?????
NVIC_X.NVIC_IRQChannelCmd = ENABLE;//??????
NVIC_Init(&NVIC_X);
}
/*
void send_Instruction(void)
{
uint8_t send_data[4]={0};
send_data[0]=0xa5;
send_data[1]=0x55;
send_data[2]=0x50;
send_data[3]=0x4a;
USART_Send_bytes(send_data,4);//????/???????
delay_ms(100);
send_data[0]=0xa5;
send_data[1]=0x56;
send_data[2]=0x02;
send_data[3]=0xfd;
USART_Send_bytes(send_data,4);//????????
delay_ms(100);
}*/
int fputc(int ch, FILE *f)
{
while (!(USART1->SR & USART_FLAG_TXE));
USART_SendData(USART1, (unsigned char) ch);//
return (ch);
}
int main(void)
{
short ROLL;
char str[20];
// u8 ROL[12];
uint8_t data_buf[50]={0},count=0;
int16_t rpy[3],Acc[3],Gyr[3],Mag[3],Q[4],Temp=0,Altitude=0;
// uint32_t pressure=0;
delay_init(72);//72M
LED_Int(GPIOB,GPIO_Pin_9,RCC_APB2Periph_GPIOB);//led
Usart_Int(9600);//115200
Usart_Int2(9600);
LCD_Init();
LCD_ShowString(30,200,200,16,16," Temp: . C");
LCD_ShowString(30,220,200,16,16,"Pitch: . C");
LCD_ShowString(30,240,200,16,16," Roll: . C");
LCD_ShowString(30,260,200,16,16," Yaw : . C");
NVIC_Configuration();//设置串口中断
//send_Instruction();//
GPIO_SetBits(GPIOB,GPIO_Pin_9);
while(1)
{
GPIO_SetBits(GPIOB,GPIO_Pin_9);//LED
if(!stata)
continue;
stata=0;
if(CHeck(data_buf))
{
count=0;
if(data_buf[2]&0x01) //ACC
{
Acc[0]=(data_buf[4]<<8)|data_buf[5];
Acc[1]=(data_buf[6]<<8)|data_buf[7];
Acc[2]=(data_buf[8]<<8)|data_buf[9];
// printf("GYRO: %.2f,%.2f ,%.2f ",(float) Acc[0]/32767,(float) Acc[1]/32767,(float) Acc[2]/32767);
count=6;
}
if(data_buf[2]&0x02) //GYRO
{
Gyr[0]=(data_buf[4+count]<<8)|data_buf[5+count];
Gyr[1]=(data_buf[6+count]<<8)|data_buf[7+count];
Gyr[2]=(data_buf[8+count]<<8)|data_buf[9+count];
// printf("GYRO: %.2f,%.2f ,%.2f ",(float) Gyr[0]/2000,(float) Gyr[1]/2000,(float) Gyr[2]/2000);
count+=6;
}
// if(data_buf[2]&0x04) //MAG
// {
// Mag[0]=(data_buf[4+count]<<8)|data_buf[5+count];
// Mag[1]=(data_buf[6+count]<<8)|data_buf[7+count];
// Mag[2]=(data_buf[8+count]<<8)|data_buf[9+count];
// count+=6;
// }
if(data_buf[2]&0x10) //???
{
rpy[0]=(data_buf[4+count]<<8)|data_buf[5+count];
rpy[1]=(data_buf[6+count]<<8)|data_buf[7+count];
rpy[2]=(data_buf[8+count]<<8)|data_buf[9+count];
ROLL=rpy[0]/100;
LCD_ShowNum(100,160,ROLL,10,16);
printf("RPY: %.2f,%.2f ,%.2f ",(float) rpy[0]/100,(float) rpy[1]/100,(float) rpy[2]/100);
count+=6;
}
if(data_buf[2]&0x40) //??
{
Temp=(data_buf[4+count]<<8)|data_buf[5+count];
printf(" ,Temp: %.2f ? \r\n",(float) Temp/100);
count+=2;
}
delay_ms(10);
}
}
}
把完整程序上传给大家看一下,感谢!
|
|