必威体育Betway必威体育官网
当前位置:首页 > IT技术

ADIS16448 配置

时间:2019-10-05 16:14:28来源:IT技术作者:seo实验室小编阅读:55次「手机版」
 

ADIS

void ADIS16448_Init(void)
{    
    GPIO_InitTypeDef GPIO_Initstructure;
    RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );//PORTB CLK
    //PB12 SENSOR_MPU_SPI_CSN 片选
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;  //CS
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_SetBits(GPIOB,GPIO_Pin_12);    //CS    

    SPI2_Init();

    MPU6500_spi_init();
} 

//以下是SPI模块的初始化代码,配置成主机模式,访问SD Card/W25Q64/NRF24L01                        
//SPI口初始化
//这里针是对SPI2的初始化
void SPI2_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    SPI_InitTypeDef  SPI_InitStructure;


    RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );//PORTB时钟使能 
    RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2,  ENABLE );//SPI2时钟使能   APB2 SPI1

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  //PB13/14/15复用推挽输出 
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化GPIOB

    GPIO_SetBits(GPIOB,GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);  //PB13/14/15上拉
        SPI_I2S_DeInit(SPI2);
    SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;  //设置SPI单向或者双向的数据模式:SPI设置为双线双向全双工
    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;       //设置SPI工作模式:设置为主SPI
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;  //设置SPI的数据大小:SPI发送接收8位帧结构
    SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;     //串行同步时钟的空闲状态为高电平
    SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;            //串行同步时钟的第二个跳变沿(上升或下降)数据被采样
    SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;       //NSS信号由硬件(NSS管脚)还是软件(使用SSI位)管理:内部NSS信号有SSI位控制
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;        //定义波特率预分频的值:波特率预分频值为8
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;  //指定数据传输从MSB位还是LSB位开始:数据传输从MSB位开始
    SPI_InitStructure.SPI_CRCPolynomial = 7;    //CRC值计算的多项式
    SPI_Init(SPI2, &SPI_InitStructure);  //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器

    SPI_Cmd(SPI2, ENABLE); //使能SPI外设
    SPI_I2S_ClearITPendingBit(SPI2, SPI_I2S_IT_RXNE);

//  SPI2_ReadWriteByte(0xff);//启动传输 
//        SPI_stoptransaction();// css set 1
}  


u8 ADIS16448_Read(void)
{
      while(1)
      {
        delay_us(20);
        CS = 0;   
        SPI2_ReadWriteByte(0x5600);
        delay_us(10);
        res = SPI2_ReadWriteByte(0);
        CS = 1;
        delay_us(20);
        CS = 0;    
        SPI2_ReadWriteByte(0x3800); //0x0402 ???             
        delay_us(10); 
        tmp = SPI2_ReadWriteByte(0);
        CS = 1;                
        delay_us(20);
        CS = 0;   delay_us(10);                
        SPI2_ReadWriteByte(0x0A00); 
        delay_us(10);                
        gyr_x = SPI2_ReadWriteByte(0); 
        delay_us(10); 
        CS = 1;
        delay_us(20);
        CS = 0; 
        delay_us(10);                 
        SPI2_ReadWriteByte(0x0C00);   
        delay_us(10);                
        gyr_y = SPI2_ReadWriteByte(0); 
        delay_us(10);   
        CS = 1;
        delay_us(20);
        CS = 0;   delay_us(10);                
        SPI2_ReadWriteByte(0x0E00);   
        delay_us(10);                
        gyr_z = SPI2_ReadWriteByte(0); 
        delay_us(10); 
        CS = 1;
      }
      //成组读取功能
/*    DIAG_STAT,
XGYRO_OUT,   YGYRO_OUT,ZGYRO_OUT, 
XACCL_OUT, YACCL_OUT, ZACCL_OUT,
XMAGN_OUT, YMAGN_OUT, ZMAGN_OUT,
BARO_OUT,and TEMP_OUT. */

       delay_us(20);//ok
       CS = 0;                 
       tmp = SPI2_ReadWriteByte(0x3E00);                
       for(i=0;i<12;i++){
        arr[i]  =  SPI2_ReadWriteByte(0);
       }
       CS = 1;    
       return res;
} 
     SPI_FLASH_CS_LOW(); //103,407  
         delay(100000);                
     gyr_x =  SPI2_ReadWriteByte(0x0A00); 
     delay(100000);                
        SPI_FLASH_CS_HIGH(); 
        delay(100000);   
SPI_FLASH_CS_LOW();   
         delay(100000);                
     gyr_y =  SPI2_ReadWriteByte(0x0C00); 
     delay(100000);                
        SPI_FLASH_CS_HIGH(); 
        delay(100000);  
SPI_FLASH_CS_LOW();   
         delay(100000);                
     gyr_z =  SPI2_ReadWriteByte(0x0E00); 
     delay(100000);                
        SPI_FLASH_CS_HIGH(); 
        delay(100000);      

#if 0       
        SPI_FLASH_CS_LOW();         
       SPI2_ReadWriteByte(0x3E00);                
       for(i=0;i<12;i++){delay(100000);
                arr[i]  =  SPI2_ReadWriteByte(0xff);
       }
      SPI_FLASH_CS_HIGH();    
        #endif 
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET)
    {
        retry++;
        delay(100);//适当延时!!
        if(retry>200)
            return 0;
    }   

相关阅读

SM:Sadism & Masochism (性)虐待狂与受虐狂

SM:Sadism & Masochism (性)虐待狂与受虐狂虐恋一词英文为Sadomasochism,是施虐倾向(Sadism)和受虐倾向(Masochism)二者的合成词。

Padis平台兼容性

Padis平台兼容性

分享到:

栏目导航

推荐阅读

热门阅读