问题遇到的现象和发生背景
数据发送一部分后停止工作了
问题相关代码,请勿粘贴截图
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "usart2.h"
#include "timer.h"
#include "oled.h"
#include "HX711.h"
#include "string.h"
extern char j_buf[4];
extern int n_cnt;
extern s16 angles[3];
float Weight = 0;
extern s16 axis_x,axis_y,axis_z;
int main(void)
{
delay_init(); //延时函数初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
uart_init(115200); //串口初始化为115200
usart2_init(9600); //串口初始化为9600
OLED_Init();
OLED_ColorTurn(0);//0正常显示,1 反色显示
OLED_DisplayTurn(0);//0正常显示 1 屏幕翻转显示
OLED_Clear();
TIM2_Int_Init(2499,7199);
Init_Hx711();
delay_ms(2000);
Get_Maopi();
while(1)
{
/**接收倾角**/
start_work();
if(n_cnt == 12)
{
/**x轴的数据存在[5][6]**/
axis_x = (USART2_RX_BUF[5]<<8)| USART2_RX_BUF[6];
angles[0]=axis_x;
if((USART2_RX_BUF[5]&0x80)!=0x00)
{
angles[0]=-angles[0];
printf("x: -%d.%d °",angles[0]/10,angles[0]%10);
}
else
{
printf("x: %d.%d °",angles[0]/10,angles[0]%10);
}
/**y轴的数据存在[7][8]**/
axis_y = (USART2_RX_BUF[7]<<8)| USART2_RX_BUF[8];
angles[1]=axis_y;
if((USART2_RX_BUF[7]&0x80)!=0x00)
{
angles[1]=-angles[1];
printf("y: -%d.%d °",angles[1]/10,angles[1]%10);
}
else
{
printf("y: %d.%d °",angles[1]/10,angles[1]%10);
}
/**z轴的数据存在[9][10]**/
axis_z = (USART2_RX_BUF[9]<<8)| USART2_RX_BUF[10];
angles[2]=axis_z;
if((USART2_RX_BUF[9]&0x80)!=0x00)
{
angles[2]=-angles[2];
printf("z: -%d.%d °",angles[2]/10,angles[2]%10);
}
else
{
printf("z: %d.%d °",angles[2]/10,angles[2]%10);
}
usart2_clear();
}
/**接收重力**/
Weight = Get_Weight();
Weight = (float)Weight/1000.0f;
printf("weigh;%0.3f N ",Weight*9.8); //串口显示重量
delay_ms(1000);
}
}
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "usart2.h"
#include "timer.h"
#include "oled.h"
#include "HX711.h"
#include "string.h"
extern char j_buf[4];
extern int n_cnt;
extern s16 angles[3];
float Weight = 0;
extern s16 axis_x,axis_y,axis_z;
int main(void)
{
delay_init(); //延时函数初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
uart_init(115200); //串口初始化为115200
usart2_init(9600); //串口初始化为9600
OLED_Init();
OLED_ColorTurn(0);//0正常显示,1 反色显示
OLED_DisplayTurn(0);//0正常显示 1 屏幕翻转显示
OLED_Clear();
TIM2_Int_Init(2499,7199);
Init_Hx711();
delay_ms(2000);
Get_Maopi();
while(1)
{
/**接收倾角**/
start_work();
if(n_cnt == 12)
{
/**x轴的数据存在[5][6]**/
axis_x = (USART2_RX_BUF[5]<<8)| USART2_RX_BUF[6];
angles[0]=axis_x;
if((USART2_RX_BUF[5]&0x80)!=0x00)
{
angles[0]=-angles[0];
printf("x: -%d.%d °",angles[0]/10,angles[0]%10);
}
else
{
printf("x: %d.%d °",angles[0]/10,angles[0]%10);
}
/**y轴的数据存在[7][8]**/
axis_y = (USART2_RX_BUF[7]<<8)| USART2_RX_BUF[8];
angles[1]=axis_y;
if((USART2_RX_BUF[7]&0x80)!=0x00)
{
angles[1]=-angles[1];
printf("y: -%d.%d °",angles[1]/10,angles[1]%10);
}
else
{
printf("y: %d.%d °",angles[1]/10,angles[1]%10);
}
/**z轴的数据存在[9][10]**/
axis_z = (USART2_RX_BUF[9]<<8)| USART2_RX_BUF[10];
angles[2]=axis_z;
if((USART2_RX_BUF[9]&0x80)!=0x00)
{
angles[2]=-angles[2];
printf("z: -%d.%d °",angles[2]/10,angles[2]%10);
}
else
{
printf("z: %d.%d °",angles[2]/10,angles[2]%10);
}
usart2_clear();
}
/**接收重力**/
Weight = Get_Weight();
Weight = (float)Weight/1000.0f;
printf("weigh;%0.3f N ",Weight*9.8); //串口显示重量
delay_ms(1000);
}
}
运行结果及报错内容
我的解答思路和尝试过的方法
想使用间隔变量发送,但也只发送几次就结束了
我想要达到的结果
能够不停止的循环发送