在用NRF作四轴的无线通信,四轴的各种数据都能得到,怎么通过NRF传到另一个32的板子上,然后我在通过串口打到上位机软件上以实现实时的数据传输[mw_shl_code=applescript,true]void ANO_DT_Send_Data(u8 *data, u8 len)
{
u8 i;
if (len>28)return; //最多28字节数据
if(!OPENPRINTF){
for (i = 0;i<len;i++)
{
usart1_send_char(data);
tmp_buf = data;
}
}//发送数据到串口1
if(NRF24L01_TxPacket(tmp_buf)==TX_OK)
{
for(i=0;i<=32;i++) data =0;
if(OPENPRINTF)
printf("发送无线成功");
}else
{
if(OPENPRINTF)
printf("发送无线失败");
}
}
[/mw_shl_code]通过以上代码并不能实现,读STATUES寄存器的值为0X0F
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
[mw_shl_code=applescript,true]#include "usart.h"
#include "ano.h"
#include "24l01.h"
/////////////////////////////////////////////////////////////////////////////////////
//数据拆分宏定义,在发送大于1字节的数据类型时,比如int16、float等,需要把数据拆分成单独字节进行发送
#define BYTE0(dwTemp) ( *( (char *)(&dwTemp) ) )
#define BYTE1(dwTemp) ( *( (char *)(&dwTemp) + 1) )
#define BYTE2(dwTemp) ( *( (char *)(&dwTemp) + 2) )
#define BYTE3(dwTemp) ( *( (char *)(&dwTemp) + 3) )
u8 data_to_send[50]; //发送数据缓存
u8 tmp_buf[32];
//////////////////////////////////////////////////////////////////////////////////
/**
**********************************
* @brief 串口1发送1个字节
* @param c:发送数据
* @retval None
**********************************
*/
void usart1_send_char(u8 c)
{
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); //循环发送,直到发送完毕
USART_SendData(USART1, c);
}
/**
**********************************
* @brief 传送数据给匿名地面站软件(V4.0版本)
* @param data:数据缓存区,最多28字节!!
len:data区有效数据个数
* @retval None
**********************************
*/
void ANO_DT_Send_Data(u8 *data, u8 len)
{
u8 i;
if (len>28)return; //最多28字节数据
if(!OPENPRINTF){
for (i = 0;i<len;i++)
{
usart1_send_char(data);
tmp_buf = data;
}
}//发送数据到串口1
if(NRF24L01_TxPacket(tmp_buf)==TX_OK)
{
for(i=0;i<=32;i++) data =0;
if(OPENPRINTF)
printf("发送无线成功");
}else
{
if(OPENPRINTF)
printf("发送无线失败");
}
}
/**
**********************************
* @brief 发送加速度传感器数据和陀螺仪数据
* @param aacx,aacy,aacz:x,y,z三个方向上面的加速度值
gyrox,gyroy,gyroz:x,y,z三个方向上面的陀螺仪值
* @retval None
**********************************
*/
void ANO_DT_Send_Senser(s16 a_x,s16 a_y,s16 a_z,s16 g_x,s16 g_y,s16 g_z)
{
u8 _cnt=0;
vs16 _temp;
u8 sum = 0;
u8 i=0;
data_to_send[_cnt++]=0xAA;
data_to_send[_cnt++]=0xAA;
data_to_send[_cnt++]=0x02;
data_to_send[_cnt++]=0;
_temp = a_x;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = a_y;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = a_z;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = g_x;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = g_y;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = g_z;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
data_to_send[3] = _cnt-4;
for(i=0;i<_cnt;i++)
sum += data_to_send;
data_to_send[_cnt++] = sum;
ANO_DT_Send_Data(data_to_send, _cnt);
}
void ANO_DT_Send_Status(float angle_rol, float angle_pit, float angle_yaw, s32 alt, u8 fly_model, u8 armed)
{
u8 _cnt=0;
vs16 _temp;
vs32 _temp2 = alt;
u8 sum = 0;
u8 i=0;
data_to_send[_cnt++]=0xAA;
data_to_send[_cnt++]=0xAA;
data_to_send[_cnt++]=0x01;
data_to_send[_cnt++]=0;
_temp = (int)(angle_rol*100);
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = (int)(angle_pit*100);
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = (int)(angle_yaw*100);
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
data_to_send[_cnt++]=BYTE3(_temp2);
data_to_send[_cnt++]=BYTE2(_temp2);
data_to_send[_cnt++]=BYTE1(_temp2);
data_to_send[_cnt++]=BYTE0(_temp2);
data_to_send[_cnt++] = fly_model;
data_to_send[_cnt++] = armed;
data_to_send[3] = _cnt-4;
for(i=0;i<_cnt;i++)
sum += data_to_send;
data_to_send[_cnt++]=sum;
ANO_DT_Send_Data(data_to_send, _cnt);
}
void ANO_DT_Send_RCData(u16 thr,u16 yaw,u16 rol,u16 pit,u16 aux1,u16 aux2,u16 aux3,u16 aux4,u16 aux5,u16 aux6)
{
u8 _cnt=0;
data_to_send[_cnt++]=0xAA;
data_to_send[_cnt++]=0xAA;
data_to_send[_cnt++]=0x03;
data_to_send[_cnt++]=0;
data_to_send[_cnt++]=BYTE1(thr);
data_to_send[_cnt++]=BYTE0(thr);
data_to_send[_cnt++]=BYTE1(yaw);
data_to_send[_cnt++]=BYTE0(yaw);
data_to_send[_cnt++]=BYTE1(rol);
data_to_send[_cnt++]=BYTE0(rol);
data_to_send[_cnt++]=BYTE1(pit);
data_to_send[_cnt++]=BYTE0(pit);
data_to_send[_cnt++]=BYTE1(aux1);
data_to_send[_cnt++]=BYTE0(aux1);
data_to_send[_cnt++]=BYTE1(aux2);
data_to_send[_cnt++]=BYTE0(aux2);
data_to_send[_cnt++]=BYTE1(aux3);
data_to_send[_cnt++]=BYTE0(aux3);
data_to_send[_cnt++]=BYTE1(aux4);
data_to_send[_cnt++]=BYTE0(aux4);
data_to_send[_cnt++]=BYTE1(aux5);
data_to_send[_cnt++]=BYTE0(aux5);
data_to_send[_cnt++]=BYTE1(aux6);
data_to_send[_cnt++]=BYTE0(aux6);
data_to_send[3] = _cnt-4;
u8 sum = 0;
for(u8 i=0;i<_cnt;i++)
sum += data_to_send;
data_to_send[_cnt++]=sum;
ANO_DT_Send_Data(data_to_send, _cnt);
}
void ANO_DT_Send_Power(u16 votage, u16 current)
{
u8 _cnt=0;
u16 temp;
data_to_send[_cnt++]=0xAA;
data_to_send[_cnt++]=0xAA;
data_to_send[_cnt++]=0x05;
data_to_send[_cnt++]=0;
temp = votage;
data_to_send[_cnt++]=BYTE1(temp);
data_to_send[_cnt++]=BYTE0(temp);
temp = current;
data_to_send[_cnt++]=BYTE1(temp);
data_to_send[_cnt++]=BYTE0(temp);
data_to_send[3] = _cnt-4;
u8 sum = 0;
for(u8 i=0;i<_cnt;i++)
sum += data_to_send;
data_to_send[_cnt++]=sum;
ANO_DT_Send_Data(data_to_send, _cnt);
}
void ANO_DT_Send_MotoPWM(u16 m_1,u16 m_2,u16 m_3,u16 m_4,u16 m_5,u16 m_6,u16 m_7,u16 m_8)
{
u8 _cnt=0;
data_to_send[_cnt++]=0xAA;
data_to_send[_cnt++]=0xAA;
data_to_send[_cnt++]=0x06;
data_to_send[_cnt++]=0;
data_to_send[_cnt++]=BYTE1(m_1);
data_to_send[_cnt++]=BYTE0(m_1);
data_to_send[_cnt++]=BYTE1(m_2);
data_to_send[_cnt++]=BYTE0(m_2);
data_to_send[_cnt++]=BYTE1(m_3);
data_to_send[_cnt++]=BYTE0(m_3);
data_to_send[_cnt++]=BYTE1(m_4);
data_to_send[_cnt++]=BYTE0(m_4);
data_to_send[_cnt++]=BYTE1(m_5);
data_to_send[_cnt++]=BYTE0(m_5);
data_to_send[_cnt++]=BYTE1(m_6);
data_to_send[_cnt++]=BYTE0(m_6);
data_to_send[_cnt++]=BYTE1(m_7);
data_to_send[_cnt++]=BYTE0(m_7);
data_to_send[_cnt++]=BYTE1(m_8);
data_to_send[_cnt++]=BYTE0(m_8);
data_to_send[3] = _cnt-4;
u8 sum = 0;
for(u8 i=0;i<_cnt;i++)
sum += data_to_send;
data_to_send[_cnt++]=sum;
ANO_DT_Send_Data(data_to_send, _cnt);
}
void ANO_DT_Send_PID(u8 group,float p1_p,float p1_i,float p1_d,float p2_p,float p2_i,float p2_d,float p3_p,float p3_i,float p3_d)
{
u8 _cnt=0;
vs16 _temp;
data_to_send[_cnt++]=0xAA;
data_to_send[_cnt++]=0xAA;
data_to_send[_cnt++]=0x10+group-1;
data_to_send[_cnt++]=0;
_temp = p1_p * 1000;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = p1_i * 1000;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = p1_d * 1000;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = p2_p * 1000;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = p2_i * 1000;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = p2_d * 1000;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = p3_p * 1000;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = p3_i * 1000;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
_temp = p3_d * 1000;
data_to_send[_cnt++]=BYTE1(_temp);
data_to_send[_cnt++]=BYTE0(_temp);
data_to_send[3] = _cnt-4;
u8 sum = 0;
for(u8 i=0;i<_cnt;i++)
sum += data_to_send;
data_to_send[_cnt++]=sum;
ANO_DT_Send_Data(data_to_send, _cnt);
}
[/mw_shl_code]
一周热门 更多>