Other Parts Discussed in Thread: EK-TM4C123GXL
Hi,
I am using EK-TM4C123GXL LaunchPad and i try to use your sensorlibrary. I have done some labs from "Getting Started with the Tiva™ TM4C123G LaunchPad Workshop" in Code Composer Studio 5.4.0.00091.I have finished lab 12 properly and was able to communicate with Putty and to send some data. I use itoa function for sending integers. Everything was working and i could see what i expected on Putty
Now i am trying to use your sensorlib (l3gd20h) to communicate with my sensor "Pololu MinIMU-9 v2 Gyro, Accelerometer, and Compass (L3GD20 and LSM303DLHC Carrier)". ( http://www.pololu.com/product/1268 ).
Unfortunately it is not working at all. Sensor is good and checked ( i can communicate with it using AVR launchpad with atmega32). Propably i am not able to use sesnorlib properly. When run my program in debbuger and play it step by step. It goes to the first step in main loop which is:
SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
and then i can only press suspend and it jumps to infinite loop in FaultISR. No source available for "0xfffffff8".
As i comment everything connected to sensorlib it is working good. Can anybody help me with this problem, and explain how to properly use your sensorlib. I linked it to my project.
Project was created according to your launchpad workshop lab 12.
Before initialization there is something like this in your example in sensorlib user guide
// Initialize the L3GD20H. This code assumes that the I2C master instance has already been initialized.
Maybe i don't know how to do this initialization. I tried to do it and below is my C code.
Here is my C code:
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
//for i2a_my(i)
#include <stdlib.h>
#include <stdio.h>
#include <cstdio>
//for sensorlib
#include "sensorlib/hw_l3gd20h.h"
#include "sensorlib/i2cm_drv.h"
#include "sensorlib/l3gd20h.h"
//for i2c
#include "inc/hw_i2c.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/i2c.h"
#include "driverlib/interrupt.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "utils/uartstdio.h"
//
// A boolean that is set when a L3GD20H command has completed.
//
volatile bool g_bl3gd20hDone;
void
l3gd20hCallback(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 L3GD20H transaction has completed.
//
g_bl3gd20hDone = true;
}
//***************itoa_my(i)*****************88
int a=-3;
char str[25];
#define INT_DIGITS 19 /* enough for 64 bit integer */
char *itoa_my(i)
int i;
{
/* Room for INT_DIGITS digits, - and '\0' */
static char buf[INT_DIGITS + 2];
char *p = buf + INT_DIGITS + 1; /* points to terminating '\0' */
if (i >= 0) {
do {
*--p = '0' + (i % 10);
i /= 10;
} while (i != 0);
return p;
}
else { /* i < 0 */
do {
*--p = '0' - (i % 10);
i /= 10;
} while (i != 0);
*--p = '-';
}
return p;
}
//*************************************************************************************
//***********UART for sending integer as ASCII **************
void USART_vSendBuffer(char *dane)
{
int i = 0;
while(dane[i]!=0) { UARTCharPut(UART0_BASE, dane[i]); //SysCtlDelay((SysCtlClockGet() / (1000 * 3))*15);
i++; }
}
//***********************************************************
//UART interrupt handler
void UARTIntHandler(void)
{
uint32_t ui32Status;
ui32Status = UARTIntStatus(UART0_BASE, true); //get interrupt status
UARTIntClear(UART0_BASE, ui32Status); //clear the asserted interrupts
while(UARTCharsAvail(UART0_BASE)) //loop while there are chars
{
UARTCharPutNonBlocking(UART0_BASE, UARTCharGetNonBlocking(UART0_BASE)); //echo character
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //blink LED
SysCtlDelay(SysCtlClockGet() / (1000 * 3)); //delay ~1 msec
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); //turn off LED
}
}
int main(void) {
//Set up the system clock
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
//Enable the UART0 and GPIOA peripherals (the UART pins are on GPIO Port A)
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//Configure the pins for the receiver and transmitter using GPIOPinConfigure
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //enable GPIO port for LED
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); //enable pin for LED PF2
//Initialize the parameters for the UART: 115200, 8-1-N
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
IntMasterEnable(); //enable processor interrupts
IntEnable(INT_UART0); //enable the UART interrupt
UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); //only enable RX and TX interrupts
//*********************************************************88
//I2c initialization - probably WRONG :(
//
//
// The I2C0 peripheral must be enabled before use.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
//
// For this example I2C0 is used with PortB[3:2]. The actual port and
// pins used may be different on your part, consult the data sheet for
// more information. GPIO port B needs to be enabled so these pins can
// be used.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//
// Configure the pin muxing for I2C0 functions on port B2 and B3.
// This step is not necessary if your part does not support pin muxing.
//
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
//
// 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_PORTB_BASE, GPIO_PIN_2);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
//
// Enable and initialize the I2C0 master module. Use the system clock for
// the I2C0 module. The last parameter sets the I2C data transfer rate.
// If false the data rate is set to 100kbps and if true the data rate will
// be set to 400kbps. For this example we will use a data rate of 100kbps.
//
I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);
//**************************************************************
//********************* SENSOR *********************
float fGyro[3];
tI2CMInstance sI2CInst;
tL3GD20H sl3gd20h;
//
// Initialize the L3GD20H. This code assumes that the I2C master instance
// has already been initialized.
//
g_bl3gd20hDone = false;
L3GD20HInit(&sl3gd20h, &sI2CInst, 0x68, l3gd20hCallback, 0);
while(!g_bl3gd20hDone)
{
}
//
// Configure the L3GD20H for 500 deg/sec sensitivity
//
g_bl3gd20hDone = false;
L3GD20HReadModifyWrite(&sl3gd20h, L3GD20H_O_CTRL4,
~L3GD20H_CTRL4_FS_M,
L3GD20H_CTRL4_FS_500DPS, l3gd20hCallback,
0);
while(!g_bl3gd20hDone)
{
}
//
// Loop forever reading data from the L3GD20H. Typically, this process
// would be done in the background, but for the purposes of this example,
// it is shown in an infinite loop.
//
while(1)
{
//
// Request another reading from the L3GD20H.
//
g_bl3gd20hDone = false;
L3GD20HDataRead(&sl3gd20h, l3gd20hCallback, 0);
while(!g_bl3gd20hDone)
{
}
//
// Get the new gyroscope readings.
//
L3GD20HDataGyroGetFloat(&sl3gd20h, &fGyro[0], &fGyro[1], &fGyro[2]);
//
// Do something with the new gyroscope readings.
//
USART_vSendBuffer("\n\r");
USART_vSendBuffer("Anything; ");
//USART_vSendBuffer(itoa_my(fGyro[0]));
}
//Use simple “UARTCharPut()” calls to create a prompt.
/* UARTCharPut(UART0_BASE, 'E');
UARTCharPut(UART0_BASE, 'n');
UARTCharPut(UART0_BASE, 't');
UARTCharPut(UART0_BASE, 'e');
UARTCharPut(UART0_BASE, 'r');
UARTCharPut(UART0_BASE, ' ');
UARTCharPut(UART0_BASE, 'T');
UARTCharPut(UART0_BASE, 'e');
UARTCharPut(UART0_BASE, 'x');
UARTCharPut(UART0_BASE, 't');
UARTCharPut(UART0_BASE, ':');
UARTCharPut(UART0_BASE, ' ');
*/
//USART_vSendBuffer("\n\r");
//USART_vSendBuffer(itoa_my(a));
//USART_vSendBuffer("kk123 ; ");
//An infinite loop. In this loop, if there is a character in the receiver, it is read, and then written to
//the transmitter. This echos what you type in the terminal window.
//while (1)
//{
//if (UARTCharsAvail(UART0_BASE)) UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));
//}
}