工具/软件:Code Composer Studio
大家好、我的代码遇到了问题。 我 正在尝试从传感器集线器获取陀螺仪信息并 通过 uart1控制一个伺服。
另外、代码运行正常、但当我尝试组合时、当我尝试为 PWM (ROM_GPIOPinConfigure (GPIO_PB4_M0PWM2)配置引脚时、我会遇到问题;)我看到缓冲区被卡住。
这是代码,如果您在“简单”上(Ctrl+F),则问题的开始位置是。 我还在这里保存了项目 :
#include
#include
#include
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/SysTick .h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "sensorlib/hw_bmp180.h"
#include "sensorlib/i2cm_drv.h"
#include "sensorlib/bmp180.h"
#include "drivers/rgb.h"
#include "sensorlib/ak8975.h"
#include "sensorlib/mpu9150.h"
#include "sensorlib/mpu6050.h"
#include "sensorlib/hw_mpu9150.h"
#include
#include
#include
#include
#include
#include
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_hibernate.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/hibernate.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/SysTick .h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include
#include
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/debug.h"
#include "driverlib/pwm.h"
#include "driverlib/pin_map.h"
#include "inc/hw_gpio.h"
#include "driverlib/rom.h"
#define PWM_FREQUENCY 55
//
//
//! \addtogroup example_list
//!
使用 BMP180测量压力(Pressure_bmp180)
//!
//! 此示例演示了传感器库 TM4C123G 的基本用法
//! LaunchPad 和 SensHub BoosterPack 来获取空气压力和
//! 使用 BMP180传感器进行温度测量。
//!
//! 将串行终端程序连接到 LaunchPad 的 ICDI 虚拟串行
//! 波特率为115、200波特。 每字节使用8位、无奇偶校验和1个停止位。
//! 原始传感器测量值打印到终端。 RGB LED
//! 初始化完成后、以1Hz 的频率闪烁、示例为
//! 运行。
//
//
//
//
//定义 BMP180 I2C 地址。
//
//
#define BMP180_I2C_ADDRESS 0x77
//
#define MPU9150_I2C_ADDRESS 0X68
//
//
//用于保存 RGB 颜色值的全局数组。
//
//
uint32_t g_pui32Colors[3];
//
//
// I2C 主驱动程序的全局实例结构。
//
//
tI2CMInstance g_sI2CInst;
//
//
// BMP180传感器驱动程序的全局实例结构。
//
//
tBMP180 g_sBMP180Inst;
//
// MPU9150传感器驱动程序的全局实例结构
//
//
tMPU9150 sMPU9150;
//
//
//全局新数据标志,以提醒 main BMP180数据已就绪。
//
//
volatile uint_fast8_t g_vui8DataFlag;
//
//
//完成 MPU9150命令后设置的布尔值。
//
//
volatile bool g_bMPU9150Done;
//
//
//驱动程序库遇到错误时调用的错误例程。
//
//
#ifdef 调试
无效
_error__(char * pcFilename、uint32_t ui32Line)
{
}
#endif
int32_t functie (int32_t n)
{
int32_t rez;
REZ = 2*n;
返回(雷兹);
}
void comenzi (char *str、float *COM1、float *com2)
{
浮点温度[3];
char buffer[16];
char com[5];
int32_t i、j、k、p;
int32_t n、ns、nf;
i=0;j=0;k=0;p=0;
N=0;ns=0;nf=0;
strcpy (buffer、str);
N=strlen (缓冲区);
for (i=0;<n; i++))
{
if (buffer[i]='、')
{
NF = I;
对于(j=ns;<nf;j++)
{
com[p]=缓冲器[j];
P++;
}
com[p]='\0';
temp[k]= atof (com);
P = 0;
com[p]='\0';
K++;
Ns = I+1;
}
}
*COM1 =temp[0];
*com2 =temp[1]/2;
}
//
//
// BMP180传感器回调函数。 在 BMP180传感器驱动器的末尾调用
//交易。 这是从 I2C 中断上下文中调用的。 因此、我们只是这样
//设置一个标志并让 main 执行大量计算和显示。
//
//
void BMP180AppCallback (void* pvCallbackData、uint_fast8_t ui8Status)
{
if (ui8Status = I2CM_STATUS_SUCCESS)
{
G_vui8DataFlag = 1;
}
}
/*********
//
//此示例在 MPU9150时作为回调提供的函数
//交易已完成。
void MPU9150Callback (void * pvCallbackData、uint_fast8_t ui8Status)
{
//
//查看是否发生错误。
//
if (ui8Status!= I2CM_STATUS_SUCCESS)
{
//
//发生了错误,所以如果需要,请在此处处理。
//
}
//
//表示 MPU9150传输已完成。
//
G_bMPU9150Done = true;
}
//
//
//由 NVIC 作为 I2C3中断的结果调用。 I2C3是 I2C 连接
//到 BMP180。
//
//
无效
BMP180I2CIntHandler (空)
{
//
//传递到传感器库提供的 I2CM 中断处理程序。
//需要在应用程序级别执行此操作,以便 I2CMIntHandler 可以执行此操作
//接收实例结构指针作为参数。
//
I2CMIntHandler (&g_sI2CInst);
}
//
//
//由 NVIC 作为 I2C3中断的结果调用。 I2C3是 I2C 连接
//至 MPU9150。
//
//
无效
MPU9150I2CIntHandler (空)
{
//
//传递到传感器库提供的 I2CM 中断处理程序。
//需要在应用程序级别执行此操作,以便 I2CMIntHandler 可以执行此操作
//接收实例结构指针作为参数。
//
I2CMIntHandler (&g_sI2CInst);
}
//
//
//由 NVIC 调用作为 SysTick 中断,用于生成
//采样间隔
//
//
无效
SysTickIntHandler()
{
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_1、GPIO_PIN_1);
BMP180DataRead (&g_sBMP180Inst、BMP180AppCallback、&g_sBMP180Inst);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_1、0x00);
}
//
//
//配置 UART 及其引脚。 这必须在 UARTprintf()之前调用。
//
//
无效
配置 UART (空)
{
//
//启用 UART 使用的 GPIO 外设。
//
ROM_SysCtlPeripheralEnable (SYSCTL_Periph_GPIOA);
//
//启用 UART0
//
ROM_SysCtlPeripheralEnable (SYSCTL_Periph_UART0);
//
//为 UART 模式配置 GPIO 引脚。
//
ROM_GPIOPinConfigure (GPIO_PA0_U0RX);
ROM_GPIOPinConfigure (GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART (GPIO_Porta_base、GPIO_PIN_0 | GPIO_PIN_1);
//
//使用内部16MHz 振荡器作为 UART 时钟源。
//
UARTClockSourceSet (UART0_BASE、UART_CLOCK_PIOSC);
//
//初始化控制台 I/O 的 UART
//
UARTStdioConfig (0、9600、16000000);
}
//
//
//主"C"语言入口点。
//
//
内部
main (空)
{
volatile uint32_t ui32Load;
volatile uint32_t ui32PWMClock;
volatile uint8_t ui8Adcust;
ui8Adsit= 83;
////////////////////////////////////////////// ------
fTemperature、fPressure、fAltitude;
int32_t i32IntegerPart、i32IntegerPartAx、i32IntegerPartAy、i32IntegerPartAz;
int32_t i32FractionPart、i32FractionPartAx、i32FractionPartAy、i32FractionPartAz;
UINT_fast16_t TemperatureRaw;
fAccel[3]、fGyro[3];
uint_fast16_t fMagnete[3];
//
//将系统时钟设置为以晶体基准从 PLL 以40MHz 频率运行
//
ROM_SysCtlClockSet (SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHz |
SYSCTL_OSC_MAIN);
//
//初始化 UART。
//
ConfigureUART();
//
//将欢迎消息打印到终端。
//
UARTprintf ("\033[2JBMP180示例\n");
//
//将颜色设置为白色近似值。
//
G_pui32Colors[红色]= 0x8000;
G_pui32Colors[蓝色]= 0x8000;
G_pui32Colors[绿色]= 0x8000;
//
//初始化 RGB 驱动器。 使用默认强度和闪烁速率。
//
RGBInit (0);
RGBColorSet (g_pui32Colors);
RGBIntensitySet (0.5f);
RGBEnable();
//
//使用前必须启用 I2C3外设。
//
ROM_SysCtlPeripheralEnable (SYSCTL_Periph_I2C3);
ROM_SysCtlPeripheralEnable (SYSCTL_Periph_GPIOD);
//
//为端口 D0和 D1上的 I2C3功能配置引脚复用。
//如果您的器件不支持引脚复用、则无需执行此步骤。
//
ROM_GPIOPinConfigure (GPIO_PD0_I2C3SCL);
ROM_GPIOPinConfigure (GPIO_PD1_I2C3SDA);
//
//为这些引脚选择 I2C 功能。 此函数也会
//为 I2C 操作配置 GPIO 引脚,将其设置为
//开漏操作,弱上拉。 请参阅数据表
//查看每个引脚分配了哪些功能。
//
GPIOPinTypeI2CSCL (GPIO_PORTD_BASE、GPIO_PIN_0);
ROM_GPIOPinTypeI2C (GPIO_PORTD_base、GPIO_PIN_1);
//
//初始化 LED 的 GPIO。
//
ROM_SysCtlPeripheralEnable (SYSCTL_Periph_GPIOF);
ROM_GPIOPinTypeGPIOOutput (GPIO_PORTF_BASE、GPIO_PIN_1);
ROM_GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_1、0x00);
ROM_SysCtlPWMClockSet (SYSCTL_PWMDIV_64);
ROM_SysCtlPeripheralEnable (SYSCTL_Periph_PWM1);
ROM_SysCtlPeripheralEnable (SYSCTL_Periph_GPIOD);
ROM_SysCtlPeripheralEnable (SYSCTL_Periph_GPIOF);
ROM_GPIOPinTypePWM (GPIO_PORTD_BASE、GPIO_PIN_0);
//
//启用到处理器的中断。
//
ROM_IntMasterEnable();
//
//初始化 I2C3外设。
//
I2CMInit (&g_sI2CInst、I2C3_base、INT_I2C3、0xff、0xff、
ROM_SysCtlClockGet ();
//
//初始化 BMP180。
//
BMP180Init (&g_sBMP180Inst、&g_sI2CInst、BMP180_I2C_address、
BMP180AppCallback、&g_sBMP180Inst);
//
//等待初始化回调以指示复位请求已完成。
//
while (g_vui8DataFlag = 0)
{
//
//等待 I2C 事务完成。
//
}
//
//重置数据就绪标志
//
G_vui8DataFlag = 0;
//初始化 MPU9150。
G_bMPU9150Done == false;
MPU9150Init (&sMPU9150、&g_sI2CInst、MPU9150_I2C_address、MPU9150Callback、0);
while (!g_bMPU9150Done)
{
}
G_bMPU9150Done = false;
MPU9150ReadModifyWrite (&sMPU9150、MPU9150_O_ACCEL_CONFIG、
~MPU9150_ACCEL_CONFIG_AFS_SEL_M、
MPU9150_ACCEL_CONFIG_AFS_SEL_4G、MPU9150Callback、
0);
//
//启用10Hz 的系统节拍。
//
ROM_SysTickPeriodSet (ROM_SysCtlClockGet ()/(10 * 3));
ROM_SysTickIntEnable();
ROM_SysTickEnable();
//
//在所有初始化和配置之后,我们开始闪烁 LED
//
RGBBlinkRateSet (1.0f);
//
//开始数据收集和打印。 永远循环。
//简单
ROM_GPIOPinConfigure (GPIO_PB4_M0PWM2);
ui32PWMClock = SysCtlClockGet ()/64;
ui32Load =(ui32PWMClock/PWM_FREQUENCY)- 1;
PWMGenConfigure (PWM0_BASE、PWM_GEN_0、PWM_GEN_MODE_DOWN);
PWMGenPeriodSet (PWM0_BASE、PWM_GEN_0、ui32Load);
ROM_PWMPulseWidthSet (PWM0_BASE、PWM_OUT_0、ui8Adust * ui32Load / 1000);
ROM_PWMOutputState (PWM0_BASE、PWM_OUT_0_BIT、TRUE);
ROM_PWMGenEnable (PWM0_BASE、PWM_GEN_0);
char g_cInput[16];
浮动 D1、D2;
ROM_FPUEnable();
ROM_FPUStackingEnable();
UARTprintf ("test");
while (1)
{
if (UARTPeek ('\r')!=1)
{
///
///
UARTgets (g_cInput、sizeof (g_cInput));
UARTprintf ("CE s-a printtat:%s\n"、g_cInput);
Comenzi (g_cInput、&D1、&D2);
UARTprintf ("%d、%d\n"、(int32_t) D1、(int32_t) D2);
}
ui8Adcust =(int32_t) d1;
ROM_PWMPulseWidthSet (PWM1_base、PWM_OUT_0、ui8Adust * ui32Load / 1000);
ROM_SysCtlDelay (100000);
//
//通过 I2C 从 BMP180读取数据。 此命令用于启动
//温度测量。 然后轮询、直到温度就绪。
//然后自动开始压力测量并进行轮询
//完成。 测量完成后、在本地进行测量
//缓冲区、然后从 I2C 调用应用程序回调
//中断上下文。 轮询在 I2C 中断允许的情况下完成
//处理器继续执行所需的其他任务。
//
BMP180DataRead (&g_sBMP180Inst、BMP180AppCallback、&g_sBMP180Inst);
while (g_vui8DataFlag = 0)
{
//
//等待新数据集可用。
//
}
//
//重置数据就绪标志。
//
G_vui8DataFlag = 0;
while (!g_bMPU9150Done)
{
}
G_bMPU9150Done = false;
MPU9150DataRead (&sMPU9150、MPU9150Callback、0);
while (!g_bMPU9150Done)
{
}
MPU9150DataAccelGetFloat (&sMPU9150、&fAccel[0]、&fAccel[1]、&fAccel[2]);
//
//获取浮点格式的最新温度数据的本地副本。
//
BMP180DataTemperatureGetFloat (&g_sBMP180Inst、&fTemperature);
BMP180DataTemperatureGetRaw (&g_sBMP180Inst、&TemperatureRaw);
//
//将浮点值转换为整数部分和小数部分以便于使用
//打印。
//
/*
i32IntegerPart =(int32_t) fTemperature;
i32FractionPart =(int32_t)(fTemperature * 1000.0f);
i32FractionPart = i32FractionPart -(i32IntegerPart * 1000);
if (i32FractionPart < 0)
{
i32FractionPart *=-1;
}
*
i32集成器件 Ax =(int32_t) fAccel[0];
i32FractionPartAx =(int32_t)(fAccel[0]* 1000.0f);
i32FractionPartAx = i32FractionPartAx -(i32IntegerPartAx * 1000);
if (i32FractionPartAx < 0)
{
i32FractionPartAx *=-1;
}
i32IntegerPartAy =(int32_t) fAccel[1];
i32FractionPartAy =(int32_t)(fAccel[1]* 1000.0f);
i32FractionPartAy = i32FractionPartAy -(i32IntegerPartAy * 1000);
if (i32FractionPartAy < 0)
{
i32FractionPartAy *=-1;
}
i32IntegerPartAz =(int32_t) fAccel[2];
i32FractionPartAz =(int32_t)(fAccel[2]* 1000.0f);
i32FractionPartAz = i32FractionPartAz -(i32IntegerPartAz * 1000);
if (i32FractionPartAz < 0)
{
i32FractionPartAz *=-1;
}
//香蕉
//打印精度为三位十进制的温度。
//
// UARTprintf ("温度%3d.%03d\t\t、i32IntegerPart、i32FractionPart);
// UARTprintf ("%3d.%3d %3d.%3d.%3D"、i32IntegerPartAx、i32FractionPartAx、i32IntegerPartAy、i32FractionPartAy、 i32 IntegerPartAz、i32 FractionPartAz);
UARTprintf ("%3d.%03d"、i32IntegerPartAx、i32FractionPartAx);
UARTprintf ("、");
UARTprintf ("%3d.%03d"、i32IntegerPartAy、i32FractionPartAy);
UARTprintf ("、");
UARTprintf ("%3d.%03d"、i32IntegerPartAz、i32FractionPartAz);
//UARTprintf ("\033[5;63H%3D.%03d"、i32IntegerPartAx、i32FractionPartAx);
//UARTprintf ("\033[5;63H%3D.%03d"、i32IntegerPartAy、i32FractionPartAy);
//UARTprintf ("%3d.%3d \n"、i32IntegerPartAy、i32FractionPartAy);
//UARTprintf ("%3d.%3d \n"、i32IntegerPartAz、i32FractionPartAz);
// UARTprintf ("x %3d.%03d\t\t"、i32IntegerPart、i32FractionPart);
// UARTprintf ("%d"、fAccel[2]);
// UARTprintf ("Pressure %.6F"、fTemperature);
//
//获取浮点格式的最新气压数据的本地副本。
//
//BMP180DataPressureGetFloat (&g_sBMP180Inst、&fPressure);
MPU9150DataMagnetoGetRaw (&sMPU9150、&fMagneto[0]、&fMagneto[1]、&fMagneto[2]);
//
//将浮点值转换为整数部分和小数部分以便于使用
//打印。
//
i32IntegerPart =(int32_t) fMagnete[0];
i32FractionPart =(Int32_t)(fMagnete[0]* 1000.0f);
i32FractionPart = i32FractionPart -(i32IntegerPart * 1000);
if (i32FractionPart < 0)
{
i32FractionPart *=-1;
}
//
//打印压力,三位十进制精度。
//
//UARTprintf ("MagX %3d.%03d\t\t"、i32IntegerPart、i32FractionPart);
//
//计算海拔高度。
//
fAltitude = 44330.0f *(1.0f - powf (fPressure / 101325.0f、
1.0f / 5.255f);
//
//将浮点值转换为整数部分和小数部分以便于使用
//打印。
//
i32 IntegerPart =(int32_t) fAltitude;
i32FractionPart =(int32_t)(fAltitude * 1000.0f);
i32FractionPart = i32FractionPart -(i32IntegerPart * 1000);
if (i32FractionPart < 0)
{
i32FractionPart *=-1;
}
//
//打印高度,三位十进制精度。
//
//UARTprintf ("海拔%3d.%03d"、i32IntegerPart、i32FractionPart);
//
//打印新行。
//
UARTprintf ("\n");
//
//延迟以保持打印速度合理。 大约100毫秒。
//
ROM_SysCtlDelay (ROM_SysCtlClockGet ()/(10 * 3));
}//while 结束
}