久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標題: STM32讀取兩個陀螺儀 [打印本頁]

作者: 加油zzy    時間: 2019-12-25 14:17
標題: STM32讀取兩個陀螺儀
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "UART3.h"
#include "UART2.h"
#include <string.h>
#include <stdio.h>
#include "JY901.h"
extern float dx2[3],vx2[3],aax2[3],dx3[3],vx3[3],aax3[3];
int main(void)
{  
        int i;
        uart_init(115200);//接PC的串口
        USART2_Config();//接JY-901模塊的串口       
        USART3_Config();//接JY-901模塊的串口       
        LED_Init();
        delay_init();
        NVIC_Configuration();
        delay_ms(2000);//等等JY-91初始化完成
        printf("角度01x\ty\tz\t02x\ty\tz\t每行數據間隔50毫秒\r\n");
        while(1)
        {       
                printf("%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\r\n",dx2[0],dx2[1],dx2[2],dx3[0],dx3[1],dx3[2]);
                delay_ms(100);
        }
}
#include "led.h"
#include "sys.h"
#include "UART2.h"
#include <string.h>
#include <stdio.h>
#include "JY901.h"
float dx2[3],vx2[3],aax2[3];
struct SAcc         Acc;//加速度
struct SGyro         Gyro;//角速度
struct SAngle         Angle;//角度
void CopeSerial2Data(unsigned char ucData)//讀jy901
{
        static unsigned char ucRxBuffer[250];
        static unsigned char ucRxCnt = 0;       
        ucRxBuffer[ucRxCnt++]=ucData;
       
        if (ucRxBuffer[0]!=0x55) //數據頭不對,則重新開始尋找0x55數據頭
        {
                ucRxCnt=0;LED0=!LED0;
                return;
        }
        if (ucRxCnt<11) {return;}//數據不滿11個,則返回
        else
        {
               
                switch(ucRxBuffer[1])
                {
                        case 0x51:        memcpy(&Acc,&ucRxBuffer[2],8);break;
                        case 0x52:        memcpy(&Gyro,&ucRxBuffer[2],8);break;
                        case 0x53:        memcpy(&Angle,&ucRxBuffer[2],8);break;
                }
                ucRxCnt=0;
        }
}
void USART2_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        USART_InitTypeDef USART_InitStructure;
       
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 , ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA,ENABLE);

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
         
        USART_InitStructure.USART_BaudRate = 9600;//一般來講9600的波特率,采樣頻率是不能超過20Hz的。
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_No ;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Rx;
        USART_Init(USART2, &USART_InitStructure);

        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//設置優先級配置的模式,第1組:搶占優先級0(0:7),搶占優先級1(0:7),
        NVIC_InitStructure.NVIC_IRQChannel =USART2_IRQn;                //B(右)碼盤中斷函數,在encoder.c中定義使用
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5; //0
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
       
        USART_ITConfig(USART2, USART_IT_TXE, DISABLE);   
        USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
       
        USART_Cmd(USART2, ENABLE);
        USART_ClearFlag(USART2,USART_FLAG_TC);       
}
void USART2_IRQHandler(void)
{
        int j;
        if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
        {
                CopeSerial2Data((unsigned char)USART2->DR);//處理數據讀到JY901的數據
                USART_ClearITPendingBit(USART2, USART_IT_RXNE);       
                for(j=0;j<3;j++)
                {
                        dx2[j]=(float)Angle.Angle[j]/32768*180;
                }                       
        }
        USART_ClearITPendingBit(USART2,USART_IT_ORE);//溢出中斷
}       


#include "led.h"
#include "sys.h"
#include "UART3.h"
#include <string.h>
#include <stdio.h>
#include "JY901.h"
float dx3[3] ,vx3[3], aax3[3];   
struct SAcc         Acc3;//加速度
struct SGyro         Gyro3;//角速度
struct SAngle         Angle3;//角度
void CopeSerial3Data(unsigned char ucData)//讀jy901
{

        static unsigned char ucRxBuffer[250];
        static unsigned char ucRxCnt = 0;       
        ucRxBuffer[ucRxCnt++]=ucData;
       
        if (ucRxBuffer[0]!=0x55) //數據頭不對,則重新開始尋找0x55數據頭
        {
                ucRxCnt=0;LED0=!LED0;
                return;
        }
        if (ucRxCnt<11) {return;}//數據不滿11個,則返回
        else
        {
               
                switch(ucRxBuffer[1])
                {
                        case 0x51:        memcpy(&Acc3,&ucRxBuffer[2],8);break;
                        case 0x52:        memcpy(&Gyro3,&ucRxBuffer[2],8);break;
                        case 0x53:        memcpy(&Angle3,&ucRxBuffer[2],8);break;
                }
                ucRxCnt=0;
               
        }
}

void USART3_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        USART_InitTypeDef USART_InitStructure;
       
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3 , ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOB,ENABLE);

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
         
        USART_InitStructure.USART_BaudRate = 9600;//一般來講9600的波特率,采樣頻率是不能超過20Hz的。
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_No ;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Rx;
        USART_Init(USART3, &USART_InitStructure);

        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//設置優先級配置的模式,第1組:搶占優先級0(0:7),搶占優先級1(0:7),
        NVIC_InitStructure.NVIC_IRQChannel =USART3_IRQn;                //B(右)碼盤中斷函數,在encoder.c中定義使用
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 7; //0
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
       
        USART_ITConfig(USART3, USART_IT_TXE, DISABLE);   
        USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
       
        USART_Cmd(USART3, ENABLE);
        USART_ClearFlag(USART3,USART_FLAG_TC);       
}
void USART3_IRQHandler(void)
{
        int j;
        if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)

        {
                CopeSerial3Data((unsigned char)USART3->DR);//處理數據讀到JY901的數據
                USART_ClearITPendingBit(USART3, USART_IT_RXNE);       
                   for(j=0;j<3;j++)
                {
                        dx3[j]=(float)Angle3.Angle[j]/32768*180;
                }
        }
        USART_ClearITPendingBit(USART3,USART_IT_ORE);//溢出中斷
}       








歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 久久久人成影片免费观看 | 毛片a级毛片免费播放100 | 免费一区 | 亚洲日本免费 | 日韩精品久久久久 | 国产一区精品在线 | 色婷婷av一区二区三区软件 | 精品在线免费观看视频 | 欧美高清性xxxxhdvideosex | 国产日韩欧美精品一区二区三区 | 国产成人福利在线观看 | 特a毛片 | 手机av在线 | aⅴ色国产 欧美 | 中文欧美日韩 | 麻豆精品国产91久久久久久 | 欧美在线视频一区 | 精品av| 国产激情精品一区二区三区 | 久草久| 欧洲一区二区三区 | 成人性生交大片免费看中文带字幕 | 亚洲精品成人在线 | 国产精品成人一区二区三区 | 91成人在线 | 日韩成人影院 | 国产乱码精品一区二区三区中文 | 亚洲成人精品在线 | 欧美.com | 91亚洲一区 | 国产精品久久久久久妇女6080 | 日本精品视频在线观看 | 宅男噜噜噜66一区二区 | 国产一级特黄真人毛片 | 色综久久| 在线观看av网站 | 久草在线在线精品观看 | 久草热视频 | 精品国产久 | 亚洲日本视频 | 精品欧美一区二区精品久久久 |