📄 adis16350.c
字号:
#include "ADIS16350.h"
#include "LPC214x.h"
unsigned short temp;
signed short map_14bit_to_16bit_format(unsigned short data14bit)
{
signed short tp;
if(data14bit&SIGN_BIT_MASK)
{
tp=(signed)(data14bit|(0x11<<14));
}
else
{
tp=(signed)(data14bit&0x3FFF);
}
return (tp);
}
void delay_loop(unsigned long count1)
{
while(count1 > 0) {count1--;} // Loop Decrease Counter
}
void SPI_write16_ADIS16350(unsigned short adis16350_addr)
{
temp = S0SPDR;//read for empty buffer
temp = S0SPSR;//dummy to clear status
CS_ADIS16350_LOW;//start conection
temp= adis16350_addr|Cmd_Wr;
S0SPDR = temp;
while(((S0SPSR & SPIF_MASK) >> 7) == 0);
temp=S0SPDR;
CS_ADIS16350_HIGH; //end connection
delay_loop(800);//delay more than 9us for t_datastall
}
void SPI_read16_ADIS16350(unsigned short *rbuffer)
{
temp = S0SPSR;//dummy to clear status
CS_ADIS16350_LOW;//start conection
S0SPDR = (unsigned short) XGYRO_OUT|Cmd_Rd;
while(((S0SPSR & SPIF_MASK) >> 7) == 0);
temp = S0SPDR;//PREVIOUS COMMAND data
CS_ADIS16350_HIGH; //end connection
delay_loop(800);//delay more than 9us for t_datastall
CS_ADIS16350_LOW;//start conection
S0SPDR = (unsigned short) YGYRO_OUT|Cmd_Rd;
while(((S0SPSR & SPIF_MASK) >> 7) == 0);
rbuffer[0] = S0SPDR;// XGYRO_OUT
CS_ADIS16350_HIGH; //end connection
delay_loop(800);//delay more than 9us for t_datastall
CS_ADIS16350_LOW;//start conection
S0SPDR = (unsigned short) ZGYRO_OUT|Cmd_Rd;
while(((S0SPSR & SPIF_MASK) >> 7) == 0);
rbuffer[1] = S0SPDR;// YGYRO_OUT
CS_ADIS16350_HIGH; //end connection
delay_loop(800);//delay more than 9us for t_datastall
CS_ADIS16350_LOW;//start conection
S0SPDR = (unsigned short) XACCL_OUT|Cmd_Rd;
while(((S0SPSR & SPIF_MASK) >> 7) == 0);
rbuffer[2] = S0SPDR;// ZGYRO_OUT
CS_ADIS16350_HIGH; //end connection
delay_loop(800);//delay more than 9us for t_datastall
CS_ADIS16350_LOW;//start conection
S0SPDR = (unsigned short) YACCL_OUT|Cmd_Rd;
while(((S0SPSR & SPIF_MASK) >> 7) == 0);
rbuffer[3] = S0SPDR;// XACCL_OUT
CS_ADIS16350_HIGH; //end connection
delay_loop(800);//delay more than 9us for t_datastall
CS_ADIS16350_LOW;//start conection
S0SPDR = (unsigned short) ZACCL_OUT|Cmd_Rd;
while(((S0SPSR & SPIF_MASK) >> 7) == 0);
rbuffer[4] = S0SPDR;// YACCL_OUT
CS_ADIS16350_HIGH; //end connection
delay_loop(800);//delay more than 9us for t_datastall
CS_ADIS16350_LOW;//start conection
S0SPDR = (unsigned short) SUPPLY_OUT|Cmd_Rd;
while(((S0SPSR & SPIF_MASK) >> 7) == 0);
rbuffer[5] = S0SPDR;// ZACCL_OUT
CS_ADIS16350_HIGH; //end connection
delay_loop(800);//delay more than 9us for t_datastall
CS_ADIS16350_LOW;//start conection
S0SPDR = (unsigned short) SUPPLY_OUT|Cmd_Rd;
while(((S0SPSR & SPIF_MASK) >> 7) == 0);
rbuffer[6] = S0SPDR;// SUPPLY_OUT
CS_ADIS16350_HIGH; //end connection
}
//init SPI0 of LPC2148
void init_SPI_to_connect_ADIS16350(void)
{
// Initial SPI0 Pin Connect on P0[4] to P0[6]
PINSEL0 &= 0xFFFF00FF; // Reset GPIO Pin Control Status Bit[15:8]
PINSEL0 |= 0x00000100; // Bit[09:08] = 01 = P0.4 is SCK(SPI0)
PINSEL0 |= 0x00000400; // Bit[11:10] = 01 = P0.5 is MISO(SPI0)
PINSEL0 |= 0x00001000; // Bit[13:12] = 01 = P0.6 is MOSI(SPI0)
CS_ADIS16350_SELECT_PIN;
CS_SETUP_OUTPUT_PIN;
CS_ADIS16350_HIGH;
S0SPCR=0;//reset value
//S0SPCR = (unsigned short)(~LSBF)&(~SPIE); //MSB first;use polling
S0SPCR |=(unsigned short) CPHA|CPOL|SPI_MASTER|BIT_ENABLE; //SPI master mode cpol=1;cpha=1 ;16bit mode
//clock setup 1.5Mhz
S0SPCCR = 10 ; //Pclk=15Mhz/10
}
//read_write data function
void ReadWrite_SPI16_ADIS16350(unsigned short adis16350_addr,unsigned short *rbuffer)
{
temp = S0SPDR;//read for empty buffer
temp = S0SPSR;//dummy to clear status
CS_ADIS16350_LOW;//start conection
S0SPDR = adis16350_addr;
while(((S0SPSR & SPIF_MASK) >> 7) == 0);
*rbuffer= (unsigned short)S0SPDR;
CS_ADIS16350_HIGH; //end connection
}
//init code
void init_ADIS16350 (void)
{
//calibration
/*A single-command, automatic bias calibration measures all
three gyroscope output registers, then loads the three bias
correction registers with values that return their outputs to zero */
SPI_write16_ADIS16350((unsigned short)(COMMAND_MSB|0x00));
SPI_write16_ADIS16350((unsigned short)(COMMAND_LSB|0x02)); //factory calib
//setup sample rate
/*The default value is the minimum register setting, 0x01, which
corresponds to the maximum sample rate of 819.2 samples per second.
The contents of this register are nonvolatile. */
SPI_write16_ADIS16350((unsigned short)(SMPL_PRD_MSB|0x00));
SPI_write16_ADIS16350((unsigned short)(SMPL_PRD_LSB|0x01));//
//setup Digital Filtering and choose dynamic range
/*The signal conditioning circuit of each sensor has an analog
bandwidth of approximately 350 Hz. A programmable-length
Bartlett Window FIR filter provides opportunity for additional
noise reduction on all of the output data registers.*/
SPI_write16_ADIS16350((unsigned short)(SENS_AVG_MSB|0x02));//chose range 150degree / and 8 tape for filter
SPI_write16_ADIS16350((unsigned short)(SENS_AVG_MSB|0x02));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -