This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
Hello,I am facing a problem with my code. I am trying to get the gyro informations from sensor hub and control one servo via uart1 .
Separately,the codes are working fine,but when i try to combine the,i am facing a problem when i try to configure the pin for pwm(ROM_GPIOPinConfigure(GPIO_PB4_M0PWM2);) i see that the buffer is stuck.
Here is the code,if you (ctrl+F) on "mere" ,there is where the problem starts. and i also saved the procject here :
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#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 <stdint.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#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 <stdint.h>
#include <stdbool.h>
#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
//! <h1>Pressure Measurement with the BMP180 (pressure_bmp180)</h1>
//!
//! This example demonstrates the basic use of the Sensor Library, TM4C123G
//! LaunchPad and the SensHub BoosterPack to obtain air pressure and
//! temperature measurements with the BMP180 sensor.
//!
//! Connect a serial terminal program to the LaunchPad's ICDI virtual serial
//! port at 115,200 baud. Use eight bits per byte, no parity and one stop bit.
//! The raw sensor measurements are printed to the terminal. The RGB LED
//! blinks at 1Hz once the initialization is complete and the example is
//! running.
//
//*****************************************************************************
//*****************************************************************************
//
// Define BMP180 I2C Address.
//
//*****************************************************************************
#define BMP180_I2C_ADDRESS 0x77
//*****************************************************************************
#define MPU9150_I2C_ADDRESS 0X68
//*****************************************************************************
//
// Global array for holding the color values for the RGB.
//
//*****************************************************************************
uint32_t g_pui32Colors[3];
//*****************************************************************************
//
// Global instance structure for the I2C master driver.
//
//*****************************************************************************
tI2CMInstance g_sI2CInst;
//*****************************************************************************
//
// Global instance structure for the BMP180 sensor driver.
//
//*****************************************************************************
tBMP180 g_sBMP180Inst;
//*****************************************************************************
// Global instance structure for MPU9150 sensor driver
//
//*****************************************************************************
tMPU9150 sMPU9150;
//*****************************************************************************
//
// Global new data flag to alert main that BMP180 data is ready.
//
//*****************************************************************************
volatile uint_fast8_t g_vui8DataFlag;
//*****************************************************************************
//
// A boolean that is set when a MPU9150 command has completed.
//
//*****************************************************************************
volatile bool g_bMPU9150Done;
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
int32_t functie(int32_t n)
{
int32_t rez;
rez = 2*n;
return(rez);
}
void comenzi(char *str, float *com1, float *com2)
{
float temp[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(buffer);
for(i=0;i<n; i++)
{
if(buffer[i] ==',')
{
nf = i;
for(j=ns;j<nf;j++)
{
com[p] = buffer[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 Sensor callback function. Called at the end of BMP180 sensor driver
// transactions. This is called from I2C interrupt context. Therefore, we just
// set a flag and let main do the bulk of the computations and display.
//
//*****************************************************************************
void BMP180AppCallback(void* pvCallbackData, uint_fast8_t ui8Status)
{
if(ui8Status == I2CM_STATUS_SUCCESS)
{
g_vui8DataFlag = 1;
}
}
//*******************************************************************************
//
// The function that is provided by this example as a callback when MPU9150
// transactions have completed.
void MPU9150Callback(void *pvCallbackData, uint_fast8_t ui8Status)
{
//
// See if an error occurred.
//
if(ui8Status != I2CM_STATUS_SUCCESS)
{
//
// An error occurred, so handle it here if required.
//
}
//
// Indicate that the MPU9150 transaction has completed.
//
g_bMPU9150Done = true;
}
//*****************************************************************************
//
// Called by the NVIC as a result of I2C3 Interrupt. I2C3 is the I2C connection
// to the BMP180.
//
//*****************************************************************************
void
BMP180I2CIntHandler(void)
{
//
// Pass through to the I2CM interrupt handler provided by sensor library.
// This is required to be at application level so that I2CMIntHandler can
// receive the instance structure pointer as an argument.
//
I2CMIntHandler(&g_sI2CInst);
}
//*****************************************************************************
//
// Called by the NVIC as a result of I2C3 Interrupt. I2C3 is the I2C connection
// to the MPU9150.
//
//*****************************************************************************
void
MPU9150I2CIntHandler(void)
{
//
// Pass through to the I2CM interrupt handler provided by sensor library.
// This is required to be at application level so that I2CMIntHandler can
// receive the instance structure pointer as an argument.
//
I2CMIntHandler(&g_sI2CInst);
}
//*****************************************************************************
//
// Called by the NVIC as a SysTick interrupt, which is used to generate the
// sample interval
//
//*****************************************************************************
void
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);
}
//*****************************************************************************
//
// Configure the UART and its pins. This must be called before UARTprintf().
//
//*****************************************************************************
void
ConfigureUART(void)
{
//
// Enable the GPIO Peripheral used by the UART.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Enable UART0
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Configure GPIO Pins for UART mode.
//
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
//
// Initialize the UART for console I/O.
//
UARTStdioConfig(0, 9600, 16000000);
}
//*****************************************************************************
//
// Main 'C' Language entry point.
//
//*****************************************************************************
int
main(void)
{
volatile uint32_t ui32Load;
volatile uint32_t ui32PWMClock;
volatile uint8_t ui8Adjust;
ui8Adjust = 83;
///////////////////////---------
float fTemperature, fPressure, fAltitude;
int32_t i32IntegerPart, i32IntegerPartAx, i32IntegerPartAy, i32IntegerPartAz;
int32_t i32FractionPart, i32FractionPartAx,i32FractionPartAy, i32FractionPartAz;
uint_fast16_t TemperatureRaw;
float fAccel[3], fGyro[3];
uint_fast16_t fMagneto[3];
//
// Setup the system clock to run at 40 MHz from PLL with crystal reference
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);
//
// Initialize the UART.
//
ConfigureUART();
//
// Print the welcome message to the terminal.
//
UARTprintf("\033[2JBMP180 Example\n");
//
// Set the color to a white approximation.
//
g_pui32Colors[RED] = 0x8000;
g_pui32Colors[BLUE] = 0x8000;
g_pui32Colors[GREEN] = 0x8000;
//
// Initialize RGB driver. Use a default intensity and blink rate.
//
RGBInit(0);
RGBColorSet(g_pui32Colors);
RGBIntensitySet(0.5f);
RGBEnable();
//
// The I2C3 peripheral must be enabled before use.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
//
// Configure the pin muxing for I2C3 functions on port D0 and D1.
// This step is not necessary if your part does not support pin muxing.
//
ROM_GPIOPinConfigure(GPIO_PD0_I2C3SCL);
ROM_GPIOPinConfigure(GPIO_PD1_I2C3SDA);
//
// Select the I2C function for these pins. This function will also
// configure the GPIO pins pins for I2C operation, setting them to
// open-drain operation with weak pull-ups. Consult the data sheet
// to see which functions are allocated per pin.
//
GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);
//
// Initialize the GPIO for the LED.
//
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);
//
// Enable interrupts to the processor.
//
ROM_IntMasterEnable();
//
// Initialize the I2C3 peripheral.
//
I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff,
ROM_SysCtlClockGet());
//
// Initialize the BMP180.
//
BMP180Init(&g_sBMP180Inst, &g_sI2CInst, BMP180_I2C_ADDRESS,
BMP180AppCallback, &g_sBMP180Inst);
//
// Wait for initialization callback to indicate reset request is complete.
//
while(g_vui8DataFlag == 0)
{
//
// Wait for I2C Transactions to complete.
//
}
//
// Reset the data ready flag
//
g_vui8DataFlag = 0;
//Initialize the 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);
//
// Enable the system ticks at 10 Hz.
//
ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / (10 * 3));
ROM_SysTickIntEnable();
ROM_SysTickEnable();
//
// After all the init and config we start blink the LED
//
RGBBlinkRateSet(1.0f);
//
// Begin the data collection and printing. Loop Forever.
// mere
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, ui8Adjust * ui32Load / 1000);
ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0);
char g_cInput[16];
float d1, d2;
ROM_FPUEnable();
ROM_FPUStackingEnable();
UARTprintf("TEST");
while(1)
{
if(UARTPeek('\r') !=-1)
{
///
///
UARTgets(g_cInput,sizeof(g_cInput));
UARTprintf("Ce s-a printat: %s\n",g_cInput);
comenzi(g_cInput, &d1, &d2);
UARTprintf("%d, %d\n", (int32_t)d1, (int32_t)d2);
}
ui8Adjust = (int32_t)d1;
ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, ui8Adjust * ui32Load / 1000);
ROM_SysCtlDelay(100000);
//
// Read the data from the BMP180 over I2C. This command starts a
// temperature measurement. Then polls until temperature is ready.
// Then automatically starts a pressure measurement and polls for that
// to complete. When both measurement are complete and in the local
// buffer then the application callback is called from the I2C
// interrupt context. Polling is done on I2C interrupts allowing
// processor to continue doing other tasks as needed.
//
BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst);
while(g_vui8DataFlag == 0)
{
//
// Wait for the new data set to be available.
//
}
//
// Reset the data ready flag.
//
g_vui8DataFlag = 0;
while(!g_bMPU9150Done)
{
}
g_bMPU9150Done = false;
MPU9150DataRead(&sMPU9150, MPU9150Callback, 0);
while(!g_bMPU9150Done)
{
}
MPU9150DataAccelGetFloat(&sMPU9150, &fAccel[0], &fAccel[1], &fAccel[2]);
//
// Get a local copy of the latest temperature data in float format.
//
BMP180DataTemperatureGetFloat(&g_sBMP180Inst, &fTemperature);
BMP180DataTemperatureGetRaw(&g_sBMP180Inst, &TemperatureRaw);
//
// Convert the floats to an integer part and fraction part for easy
// print.
//
/*
i32IntegerPart = (int32_t) fTemperature;
i32FractionPart =(int32_t) (fTemperature * 1000.0f);
i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
if(i32FractionPart < 0)
{
i32FractionPart *= -1;
}
*/
i32IntegerPartAx = (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;
}
//banana
// Print temperature with three digits of decimal precision.
//
// UARTprintf("Temperature %3d.%03d\t\t", i32IntegerPart, i32FractionPart);
// UARTprintf("%3d.%3d %3d.%3d %3d.%3d", i32IntegerPartAx, i32FractionPartAx, i32IntegerPartAy, i32FractionPartAy, i32IntegerPartAz, i32FractionPartAz);
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);
//
// Get a local copy of the latest air pressure data in float format.
//
//BMP180DataPressureGetFloat(&g_sBMP180Inst, &fPressure);
MPU9150DataMagnetoGetRaw(&sMPU9150, &fMagneto[0], &fMagneto[1], &fMagneto[2]);
//
// Convert the floats to an integer part and fraction part for easy
// print.
//
i32IntegerPart = (int32_t) fMagneto[0];
i32FractionPart =(int32_t) (fMagneto[0] * 1000.0f);
i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
if(i32FractionPart < 0)
{
i32FractionPart *= -1;
}
//
// Print Pressure with three digits of decimal precision.
//
//UARTprintf("MagX %3d.%03d\t\t", i32IntegerPart, i32FractionPart);
//
// Calculate the altitude.
//
fAltitude = 44330.0f * (1.0f - powf(fPressure / 101325.0f,
1.0f / 5.255f));
//
// Convert the floats to an integer part and fraction part for easy
// print.
//
i32IntegerPart = (int32_t) fAltitude;
i32FractionPart =(int32_t) (fAltitude * 1000.0f);
i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
if(i32FractionPart < 0)
{
i32FractionPart *= -1;
}
//
// Print altitude with three digits of decimal precision.
//
//UARTprintf("Altitude %3d.%03d", i32IntegerPart, i32FractionPart);
//
// Print new line.
//
UARTprintf("\n");
//
// Delay to keep printing speed reasonable. About 100 milliseconds.
//
ROM_SysCtlDelay(ROM_SysCtlClockGet() / (10 * 3));
}//while end
}
Yet - even with that improvement - the search to find & assist will be pain-staking - will eat time & effort!
As "you've noted" (more than once) should not posters make the (studied) effort to "drape the patient" (i.e. present those code aspects which have "bearing") upon poster's issue? Simply "pasting in an encyclopedia" does exhaust - and shows little (i.e. NO) care/concern for crack "helper crüe..."
It is rather apparent - you/I - either individually or in combination - can "solve" poster's issue. Yet - "wading thru "acres of extraneous code" (even properly formatted - yet extraneous code) proves, 'Less than attractive!" It is not my intent to 'be mean" - instead it is a providing of a "superior means" to "engage others" - especially when one "seeks favors from strangers!"
Complicating the "helper crüe's effort" - while easing the poster's - makes little sense - and should receive (some) consideration - should it not?
Hi Charles,
To properly "drape this patient" I have captured all references to "pwm" - and present here for (greatly) eased read/review. (i.e. "modeling" what our poster "should have done" to "Speed, Ease, Enhance" the efforts of her (hapless) helpers...
While you've "found" the lack of "PWM0 Enable" - poster reports that her code does run - and note (revealed in highlight) two such mentions of "PWM1 Enable." Note that I've been ALONE in "Squawking re: needless bombardment of EXTRANEOUS code" - is it not clear that this likely "masks, delays & confounds" HER attempts - and surely those of your, "hapless crüe." It is suspected that this Code JUMBLE caused the incorrect repetition of PWM1's Enable - when in fact - both PWM1 and PWM0 enjoyed such enabling! (if this was not so - how could her code have run?)
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
GPIOPinConfigure(GPIO_PF1_M1PWM5);
GPIOPinConfigure(GPIO_PF2_M1PWM6);
GPIOPinConfigure(GPIO_PF3_M1PWM7);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
ROM_GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0);
PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ui32Load);
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, ui8Adjust * ui32Load / 1000);
ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0);
PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, ui32Load);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ui32Load);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, ui32Load);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5,ui8Adjust * ui32Load / 1000);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6,ui8Adjust * ui32Load / 1000);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7,ui8Adjust * ui32Load / 1000);
PWMGenEnable(PWM1_BASE, PWM_GEN_2);
PWMGenEnable(PWM1_BASE, PWM_GEN_3);
PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT | PWM_OUT_6_BIT | PWM_OUT_7_BIT, true);
ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, ui8Adjust * ui32Load / 1000);
ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust * ui32Load / 1000);
ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, ui8Adjust * ui32Load / 1000);
ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui8Adjust * ui32Load / 1000);
She most recently reports, "No Servo Action" - yet "NOT ONE LINE OF THIS CODE IS COMMENTED" ... How are we (hapless) to know then - which code lines prove the offender?
Being "PC" should not enable (hugely inefficient methods i.e. laundry list of ALL Code) to "camouflage code errors - reduce helper & poster focus - and EAT (unwanted time/effort!) Might you agree that (some attempt) to "Limit the code to that "MOST APPLICABLE" proves a far better method - than "everything under the sun" - "They'll figure it out!"
May it be noted that it is NOT the "abundance of comments" - but their "ABSENCE" which disturbs & confounds your helpers. Comments are good - even you - may at times - require "confirmation" that you are "reviewing the right spot" in "highly similar" code blocks! As you have "so many" references to PWM Outputs (NONE Commented) how possibly can we know "which one" targets your servo?
Understand that by "limiting your focus" (as KISS demands) you have a far greater chance of discovering mistakes - or at minimum - finding the "misbehaving code blocks."
In addition - as your code grows & bloats - is it not difficult for you to "simply navigate?" Far better I would think - is to devise small blocks of code - with a clear yet limited objective - which do NOT require "endless paging" to find the targeted feature/function.
The code you "copied/imported/added to is "SO VAST" that mastery borders upon the impossible. Smaller, highly focused & (always commented) code - "Speeds, Eases, Enhances" your effort - while being "So much easier to absorb" by your "crack" helper crüe.
This - and earlier - writings are not meant as being "mean" - instead they strive to "make the case" for an alternative presentation - one which, "Escapes the clutter" which your post (unfortunately) presents - and which (greatly) complicates "helper assistance." (and your own code testing & development...)
I've managed to make it work.If anyone needs a project that gets accelerations from mpu9150(hub) and also controls 3 servos from UART ,here it is
Have a nice day!
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#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 <stdint.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#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 <stdint.h>
#include <stdbool.h>
#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
#define BMP180_I2C_ADDRESS 0x77
#define MPU9150_I2C_ADDRESS 0X68
#define LED_PERIPH SYSCTL_PERIPH_GPIOF
#define LED_BASE GPIO_PORTF_BASE
#define RED_LED GPIO_PIN_1
uint32_t g_pui32Colors[3];
tI2CMInstance g_sI2CInst;
tBMP180 g_sBMP180Inst;
tMPU9150 sMPU9150;
volatile uint_fast8_t g_vui8DataFlag;
volatile bool g_bMPU9150Done;
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
int32_t functie(int32_t n)
{
int32_t rez;
rez = 2*n;
return(rez);
}
void comenzi(char *str, float *com1, float *com2,float *com3)
{
float temp[5];
char buffer[16];
char com[7];
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(buffer);
for(i=0;i<n; i++)
{
if(buffer[i] ==',')
{
nf = i;
for(j=ns;j<nf;j++)
{
com[p] = buffer[j];
p++;
}
com[p]='\0';
temp[k] = atof(com);
p = 0;
com[p] ='\0';
k++;
ns = i+1;
}
}
*com1 =temp[0];
*com2 =temp[1];
*com3 =temp[2];
}
void BMP180AppCallback(void* pvCallbackData, uint_fast8_t ui8Status)
{
if(ui8Status == I2CM_STATUS_SUCCESS)
{
g_vui8DataFlag = 1;
}
}
void MPU9150Callback(void *pvCallbackData, uint_fast8_t ui8Status)
{
if(ui8Status != I2CM_STATUS_SUCCESS)
{
}
g_bMPU9150Done = true;
}
void
BMP180I2CIntHandler(void)
{
I2CMIntHandler(&g_sI2CInst);
}
void
MPU9150I2CIntHandler(void)
{
I2CMIntHandler(&g_sI2CInst);
}
void
SysTickIntHandler()
{
BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst);
}
/*void
ConfigureUART(void)
{
//
// Enable the GPIO Peripheral used by the UART.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//
// Enable UART1
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
//
// Configure GPIO Pins for UART mode.
//
ROM_GPIOPinConfigure(GPIO_PB0_U1RX);
ROM_GPIOPinConfigure(GPIO_PB1_U1TX);
ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);
//
// Initialize the UART for console I/O.
//
//UARTStdioConfig(0, 115200, 16000000);
UARTStdioConfig(1, 9600, 16000000);
}*/
void
ConfigureUART(void)
{
//
// Enable the GPIO Peripheral used by the UART.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Enable UART0
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Configure GPIO Pins for UART mode.
//
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
UARTStdioConfig(0, 9600, 16000000);
}
int
main(void)
{
volatile uint32_t ui32Load;
volatile uint32_t ui32PWMClock;
volatile uint8_t ui8Adjust,ui8Adjust1,ui8Adjust2;
ui8Adjust = 83;
SysCtlPeripheralEnable(LED_PERIPH);
SysCtlDelay(3);
float fTemperature, fPressure, fAltitude;
int32_t i32IntegerPart, i32IntegerPartAx, i32IntegerPartAy, i32IntegerPartAz;
int32_t i32FractionPart, i32FractionPartAx,i32FractionPartAy, i32FractionPartAz;
uint_fast16_t TemperatureRaw;
float fAccel[3], fGyro[3];
uint_fast16_t fMagneto[3];
ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);
ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
ConfigureUART();
UARTprintf("\033[2JBMP180 Example\n");
g_pui32Colors[RED] = 0x8000;
g_pui32Colors[BLUE] = 0x8000;
g_pui32Colors[GREEN] = 0x8000;
/* RGBInit(0);
RGBColorSet(g_pui32Colors);
RGBIntensitySet(0.5f);
RGBEnable();
*/
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
ROM_GPIOPinConfigure(GPIO_PD0_I2C3SCL);
ROM_GPIOPinConfigure(GPIO_PD1_I2C3SDA);
GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
GPIOPinConfigure(GPIO_PF1_M1PWM5);
GPIOPinConfigure(GPIO_PF2_M1PWM6);
GPIOPinConfigure(GPIO_PF3_M1PWM7);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
ui32PWMClock = SysCtlClockGet() / 64;
ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, ui32Load);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ui32Load);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, ui32Load);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5,ui8Adjust * ui32Load / 1000);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6,ui8Adjust * ui32Load / 1000);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7,ui8Adjust * ui32Load / 1000);
PWMGenEnable(PWM1_BASE, PWM_GEN_2);
PWMGenEnable(PWM1_BASE, PWM_GEN_3);
PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT | PWM_OUT_6_BIT | PWM_OUT_7_BIT, true);
ROM_IntMasterEnable();
I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff,
ROM_SysCtlClockGet());
BMP180Init(&g_sBMP180Inst, &g_sI2CInst, BMP180_I2C_ADDRESS,
BMP180AppCallback, &g_sBMP180Inst);
while(g_vui8DataFlag == 0)
{
}
g_vui8DataFlag = 0;
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);
ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / (10 * 3));
ROM_SysTickIntEnable();
ROM_SysTickEnable();
// RGBBlinkRateSet(1.0f);
ui32PWMClock = SysCtlClockGet() / 64;
ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, ui32Load);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ui32Load);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, ui32Load);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5,ui8Adjust * ui32Load / 1000);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6,ui8Adjust * ui32Load / 1000);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7,ui8Adjust * ui32Load / 1000);
PWMGenEnable(PWM1_BASE, PWM_GEN_2);
PWMGenEnable(PWM1_BASE, PWM_GEN_3);
PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT | PWM_OUT_6_BIT | PWM_OUT_7_BIT, true);
char g_cInput[16];
float d1, d2, d3;
ROM_FPUEnable();
ROM_FPUStackingEnable();
UARTprintf("TEST");
while(1)
{
if(UARTPeek('\r') !=-1)
{
UARTgets(g_cInput,sizeof(g_cInput));
UARTprintf("Ce s-a printat: %s\n",g_cInput);
comenzi(g_cInput, &d1, &d2, &d3);
UARTprintf("%d,%d, %d\n", (int32_t)d1, (int32_t)d2, (int32_t)d3);
ui8Adjust = (int32_t)d1;
ui8Adjust1 = (int32_t)d2;
ui8Adjust2 = (int32_t)d3;
ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust * ui32Load / 1000);
ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, ui8Adjust1 * ui32Load / 1000);
ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui8Adjust2 * ui32Load / 1000);
ROM_SysCtlDelay(5000000);
}
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);
i32IntegerPartAx = (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", i32IntegerPartAx, i32FractionPartAx);
UARTprintf(",");
UARTprintf("%3d.%03d", i32IntegerPartAy, i32FractionPartAy);
UARTprintf(",");
UARTprintf("%3d.%03d", i32IntegerPartAz, i32FractionPartAz);
MPU9150DataMagnetoGetRaw(&sMPU9150, &fMagneto[0], &fMagneto[1], &fMagneto[2]);
i32IntegerPart = (int32_t) fMagneto[0];
i32FractionPart =(int32_t) (fMagneto[0] * 1000.0f);
i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
if(i32FractionPart < 0)
{
i32FractionPart *= -1;
}
fAltitude = 44330.0f * (1.0f - powf(fPressure / 101325.0f,
1.0f / 5.255f));
i32IntegerPart = (int32_t) fAltitude;
i32FractionPart =(int32_t) (fAltitude * 1000.0f);
i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
if(i32FractionPart < 0)
{
i32FractionPart *= -1;
}
UARTprintf("\n");
ROM_SysCtlDelay(ROM_SysCtlClockGet() / (10 * 3));
It is nice that you've updated the forum - yet not one line of that (very) LONG code - received the "benefit" of comment!
It thus remains "unclear" to those here - and likely to you too - as to, "Which code block" targets the Servo!
You've been "immersed" in this project - what you "know now" is "sure to dim" w/the passage of time - what then? Comments provide excellent "road markers" (like street signs) which help us navigate - both city streets & highly similar code blocks - best insuring that we, "find our way."
I've comented what i've chaned from the original code(the air mouse example from tivaWare),the code and project are here:
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#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 <stdint.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#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 <stdint.h>
#include <stdbool.h>
#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
#define BMP180_I2C_ADDRESS 0x77
#define MPU9150_I2C_ADDRESS 0X68
#define LED_PERIPH SYSCTL_PERIPH_GPIOF
#define LED_BASE GPIO_PORTF_BASE
#define RED_LED GPIO_PIN_1
uint32_t g_pui32Colors[3];
tI2CMInstance g_sI2CInst;
tBMP180 g_sBMP180Inst;
tMPU9150 sMPU9150;
volatile uint_fast8_t g_vui8DataFlag;
volatile bool g_bMPU9150Done;
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
int32_t functie(int32_t n)
{
int32_t rez;
rez = 2*n;
return(rez);
}
void comenzi(char *str, float *com1, float *com2,float *com3)
{
float temp[5];
char buffer[16];
char com[7];
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(buffer);
for(i=0;i<n; i++)
{
if(buffer[i] ==',')
{
nf = i;
for(j=ns;j<nf;j++)
{
com[p] = buffer[j];
p++;
}
com[p]='\0';
temp[k] = atof(com);
p = 0;
com[p] ='\0';
k++;
ns = i+1;
}
}
*com1 =temp[0];
*com2 =temp[1];
*com3 =temp[2];
}
void BMP180AppCallback(void* pvCallbackData, uint_fast8_t ui8Status)
{
if(ui8Status == I2CM_STATUS_SUCCESS)
{
g_vui8DataFlag = 1;
}
}
void MPU9150Callback(void *pvCallbackData, uint_fast8_t ui8Status)
{
if(ui8Status != I2CM_STATUS_SUCCESS)
{
}
g_bMPU9150Done = true;
}
void
BMP180I2CIntHandler(void)
{
I2CMIntHandler(&g_sI2CInst);
}
void
MPU9150I2CIntHandler(void)
{
I2CMIntHandler(&g_sI2CInst);
}
void
SysTickIntHandler()
{
BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst);
}
/*void
ConfigureUART(void)
{
//
// Enable the GPIO Peripheral used by the UART.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//
// Enable UART1
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
//
// Configure GPIO Pins for UART mode.
//
ROM_GPIOPinConfigure(GPIO_PB0_U1RX);
ROM_GPIOPinConfigure(GPIO_PB1_U1TX);
ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);
//
// Initialize the UART for console I/O.
//
//UARTStdioConfig(0, 115200, 16000000);
UARTStdioConfig(1, 9600, 16000000);
}*/
void
ConfigureUART(void)
{
//
// Enable the GPIO Peripheral used by the UART.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Enable UART0
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Configure GPIO Pins for UART mode.
//
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
UARTStdioConfig(0, 9600, 16000000);
}
int
main(void)
{
//variables for PWM
volatile uint32_t ui32Load;
volatile uint32_t ui32PWMClock;
volatile uint8_t ui8Adjust,ui8Adjust1,ui8Adjust2;
ui8Adjust = 83;
SysCtlPeripheralEnable(LED_PERIPH);//the PF1,PF2,PF2 pins are also used by the RGB led and this function enables them
SysCtlDelay(3);
//variables for Sensorhub sensors (we are using the mpu9150 )
float fTemperature, fPressure, fAltitude;
int32_t i32IntegerPart, i32IntegerPartAx, i32IntegerPartAy, i32IntegerPartAz;
int32_t i32FractionPart, i32FractionPartAx,i32FractionPartAy, i32FractionPartAz;
uint_fast16_t TemperatureRaw;
float fAccel[3], fGyro[3];
uint_fast16_t fMagneto[3];
ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);
ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
ConfigureUART();
UARTprintf("\033[2JBMP180 Example\n");
g_pui32Colors[RED] = 0x8000;
g_pui32Colors[BLUE] = 0x8000;
g_pui32Colors[GREEN] = 0x8000;
//the i2c configuration for sensorhub mpu9150
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
ROM_GPIOPinConfigure(GPIO_PD0_I2C3SCL);
ROM_GPIOPinConfigure(GPIO_PD1_I2C3SDA);
GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);
//the pwm configuration for the three servos on pin PF1,PF2,PF3
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
GPIOPinConfigure(GPIO_PF1_M1PWM5);
GPIOPinConfigure(GPIO_PF2_M1PWM6);
GPIOPinConfigure(GPIO_PF3_M1PWM7);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
ui32PWMClock = SysCtlClockGet() / 64;
ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, ui32Load);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ui32Load);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, ui32Load);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5,ui8Adjust * ui32Load / 1000);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6,ui8Adjust * ui32Load / 1000);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7,ui8Adjust * ui32Load / 1000);
PWMGenEnable(PWM1_BASE, PWM_GEN_2);
PWMGenEnable(PWM1_BASE, PWM_GEN_3);
PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT | PWM_OUT_6_BIT | PWM_OUT_7_BIT, true);
//this is from sensorHub example for "air mouse"
ROM_IntMasterEnable();
I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff,
ROM_SysCtlClockGet());
BMP180Init(&g_sBMP180Inst, &g_sI2CInst, BMP180_I2C_ADDRESS,
BMP180AppCallback, &g_sBMP180Inst);
while(g_vui8DataFlag == 0)
{
}
g_vui8DataFlag = 0;
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);
ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / (10 * 3));//setting the clock for delay
ROM_SysTickIntEnable();
ROM_SysTickEnable();
char g_cInput[16];//the array where we store what we type in console
float d1, d2, d3;//variables that we use to store the pwm control for each servo
ROM_FPUEnable();
ROM_FPUStackingEnable();
UARTprintf("TEST");
while(1)
{
if(UARTPeek('\r') !=-1)//checks if anything is typed in UART console(mine is UART0)
{
UARTgets(g_cInput,sizeof(g_cInput));//gets what is typed in UART
UARTprintf("Ce s-a printat: %s\n",g_cInput);//prints what i've typed
comenzi(g_cInput, &d1, &d2, &d3);//the comenzi function gets the char from UART and separate the numbers by","character
UARTprintf("%d,%d, %d\n", (int32_t)d1, (int32_t)d2, (int32_t)d3);//prints the numbers that control the servos
//three variables that will get the numeric command (from 50 to 120)
ui8Adjust = (int32_t)d1;
ui8Adjust1 = (int32_t)d2;
ui8Adjust2 = (int32_t)d3;
//here is where we comand the three servos{
ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust * ui32Load / 1000);
ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, ui8Adjust1 * ui32Load / 1000);
ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui8Adjust2 * ui32Load / 1000);
ROM_SysCtlDelay(5000000);
// and a litle delay of 0,5 seconds to let the servos make their move}
}
//from here on is the example from TivaWare sensorhub "air mouse"
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);
i32IntegerPartAx = (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", i32IntegerPartAx, i32FractionPartAx);
UARTprintf(",");
UARTprintf("%3d.%03d", i32IntegerPartAy, i32FractionPartAy);
UARTprintf(",");
UARTprintf("%3d.%03d", i32IntegerPartAz, i32FractionPartAz);
MPU9150DataMagnetoGetRaw(&sMPU9150, &fMagneto[0], &fMagneto[1], &fMagneto[2]);
i32IntegerPart = (int32_t) fMagneto[0];
i32FractionPart =(int32_t) (fMagneto[0] * 1000.0f);
i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
if(i32FractionPart < 0)
{
i32FractionPart *= -1;
}
fAltitude = 44330.0f * (1.0f - powf(fPressure / 101325.0f,
1.0f / 5.255f));
i32IntegerPart = (int32_t) fAltitude;
i32FractionPart =(int32_t) (fAltitude * 1000.0f);
i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
if(i32FractionPart < 0)
{
i32FractionPart *= -1;
}
UARTprintf("\n");
ROM_SysCtlDelay(ROM_SysCtlClockGet() / (10 * 3));
}
}
You are "free" of course to use/avoid comments. Comment method passed has, "Passed the test of time" - is "not my invention" - and is generally recognized and supported.
Some may be curious as to the, "50-120 value restriction" of the servos. Might you explain how those values were chosen - and then test/verified? (i.e. is that the value presented to the PWM Pulse Width function or is it "representative" of the "angular span of the servo" ... or something else?
Appreciate your time & effort - likely that you've aided others - that's always good! Bon chance, mon ami...
OK, a couple of problems.
You haven't learned to use paste code yet. That makes it unnecessarily difficult for readers to follow your code. Among other faults the indentation is lost.
Beatrice Balaceanu said:void mapping(float *num){
*num=(*num *0.3888)+50;
}
but it shows me an error:"invalid type conversion" when i try to use it: ui8Adjust = (int32_t)(mapping(&d1));
Questions:
Robert
There is, BTW, an exceedingly good chance that static analyzer like PC-Lint would have already told you what the error was in more detail.
Greetings Robert,
I too saw the (unwise pointer use) - yet "Float usage" - over so limited a signal range (which could never benefit from such) demands address.
As to "d1" - it IS there - yet lurks (very well) hidden w/in the code bloat.
Below is just "one such capture" - when my eyes "uncross" (if ever they do) and still required - more can be supplied.
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, ui8Adjust * ui32Load / 1000);
ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0);
char g_cInput[16];
float d1, d2;
ROM_FPUEnable();
ROM_FPUStackingEnable();
UARTprintf("TEST");
while(1)
{
if(UARTPeek('\r') !=-1)
{
///
///
UARTgets(g_cInput,sizeof(g_cInput));
UARTprintf("Ce s-a printat: %s\n",g_cInput);
comenzi(g_cInput, &d1, &d2);
UARTprintf("%d, %d\n", (int32_t)d1, (int32_t)d2);
}
Squint on - should more illustration be required... This project SO Violates KISS - what could the creators have been thinking?
Thanks cb1
Unless the code is reasonably short I seldom try hard to decipher it if paste code is not used. That helps and leads to the next observation
Beatrice Balaceanu said:void mapping(float *num)
Beatrice Balaceanu said:(int32_t)(mapping(&d1));
Beatrice, do you see the contradiction in the returns between the two quoted fragments?
This rather emphasizes my question about using pointers.
Robert
Neither of us use CCS,
While it's possible it has such a function I'd be a little surprised if it did. And it's not as if it is hard to write (even with integers).
Robert