![ElecMaster JY-61 Series Скачать руководство пользователя страница 11](http://html1.mh-extra.com/html/elecmaster/jy-61-series/jy-61-series_user-manual_2378393011.webp)
http://www.aliexpress.com/store/1836321
- 11 -
The data packet is used to indicate the module whether enter into the IIC mode, the module
will release the IIC MPU6050 bus, and the user can access to the original data of the MPU6050
chip by IIC. If you receive 0x55 0x50 at the beginning of the data packet, the module works in the
IIC mode, when you want to switch to the serial mode, please send a command 0xFF 0xAA 0x61,
or use the PC program to modify.
5.3
Data analysis sample code(Language C)
:
double
a[3],w[3],Angle[3],T;
void
DecodeIMUData(
unsigned
char
chrTemp[])
{
switch
(chrTemp[1])
{
case
0x51:
a[0] = ((
short
)(chrTemp[3]<<8|chrTemp[2]))/32768.0*16;
a[1] = ((
short
) (chrTemp[5]<<8|chrTemp[4]))/32768.0*16;
a[2] = ((
short
) (chrTemp[7]<<8|chrTemp[6]))/32768.0*16;
T = ((
short
) (chrTemp[9]<<8|chrTemp[8]))/340.0+36.25;
break
;
case
0x52:
w[0] = ((
short
) (chrTemp[3]<<8|chrTemp[2]))/32768.0*2000;
w[1] = ((
short
) (chrTemp[5]<<8|chrTemp[4]))/32768.0*2000;
w[2] = ((
short
) (chrTemp[7]<<8|chrTemp[6]))/32768.0*2000;
T = ((
short
) (chrTemp[9]<<8|chrTemp[8]))/340.0+36.25;
break
;
case
0x53:
Angle[0] = ((
short
) (chrTemp[3]<<8|chrTemp[2]))/32768.0*180;
Angle[1] = ((
short
) (chrTemp[5]<<8|chrTemp[4]))/32768.0*180;
Angle[2] = ((
short
)(chrTemp[7]<<8|chrTemp[6]))/32768.0*180;
T = ((
short
)(chrTemp[9]<<8|chrTemp[8]))/340.0+36.25;
printf(
"a = %4.3f\t%4.3f\t%4.3f\t\r\n"
,a[0],a[1],a[2]);
printf(
"w = %4.3f\t%4.3f\t%4.3f\t\r\n"
,w[0],w[1],w[2]);
printf(
"Angle = %4.2f\t%4.2f\t%4.2f\tT=%4.2f\r\n"
,Angle[0],Angle[1],Angle[2],T);
break
;
}
}
5.4
Examples of analytical data in embedded environment
The code is divided into two parts, one is in interrupt to receive, to find the data's head, and
then put the packet into the array. The other is data analysis in the main code.
Interrupt part(The following is the AVR microcontroller code. The other microcontroller will
be a little difference)
unsigned char Re_buf[11],counter=0;
unsigned char sign;
interrupt [USART_RXC] void usart_rx_isr(void) //USART receive
{
Re_buf[counter]=UDR;//
Slight difference between different microcontroller
if(counter==0&&Re_buf[0]!=0x55) return; //
if the first data is not frame header, skip
+;
if(counter==11) //
Receive 11 data
{
counter=0; //
Re assignment, prepare for the next frame of data receiving
sign=1;
}
}
Main code
:
float a[3],w[3],angle[3],T;
extern unsigned char Re_buf[11],counter;
extern unsigned char sign;