Hi!
I am new to embedded programming, so please, forgive me possibly idiotic question.
I need a simple application that will read several ADC channels each 100usec, perform some simplest calculation and send the output to the display. So i am trying to combine several examples to do this.
Now i am stuck, as since some point, whatever i do, the controller gets fault an different lines. it may be the GrStringDraw, or ROM_IntMasterDisable, or anything. I just cannot continue...
In the code below, the fault comes in timer handler, on the first GrStringDraw line.
Please, help!
upd:
the specific assembly line that throws me to fault is BLX r12... Is it helpful?
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/fpu.h"
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"
#include "driverlib/pin_map.h"
#include "grlib/grlib.h"
#include "drivers/cfal96x64x16.h"
#include "utils/uartstdio.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/adc.h"
#include "driverlib/interrupt.h"
#include "inc/hw_ints.h"
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
static float PMotor;
static float PTotal;
static tContext sContext;
static char TextOut[10];
static unsigned long ulADC0_Value[3];
void NumToString (char *str, float num)
{
char digit;
float factor=1;
if (num>1)
{
while (factor<num)
{
factor=factor * 10;
}
}
else
{
*str='0';
str++;
}
if (num==0)
{
*str=48;
str++;
*str=0;
return;
}
else
{
while ((factor>num) && (factor>0.0001))
{
if (factor==1)
{
*str='.';
str++;
}
factor=factor/10;
digit=(char)(num/factor);
*str=(char) (digit+'0');
str++;
num=num-digit*factor;
}
*str=' ';
str++;
*str=0;
}
return;
}
void
Timer0IntHandler(void)
{
float Efficiency;
char efficiency_string[20];
//
// Clear the timer interrupt.
//
ROM_IntMasterDisable();
ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// ADCProcessorTrigger(ADC0_BASE, 0);
// while(!ADCIntStatus(ADC0_BASE, 0, false))
// {
// }
// ADCSequenceDataGet(ADC0_BASE, 0, ulADC0_Value);
PMotor=PMotor+1;
PTotal=PTotal+1;
Efficiency=(float) (PMotor/PTotal);
NumToString(efficiency_string, (float)PMotor);
GrStringDraw(&sContext, efficiency_string, -1, 50,
26, 1);
NumToString(efficiency_string, (float)PTotal);
GrStringDraw(&sContext, efficiency_string, -1, 50,
36, 1);
NumToString(efficiency_string, (float)Efficiency);
GrStringDraw(&sContext, efficiency_string, -1, 50,
46, 1);
// UARTprintf("Motor %f, Total %f, n %f", PMotor, PTotal, efficiency);
ROM_IntMasterEnable();
SysCtlDelay(1000);
}
void
InitADC(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6);
ROM_ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
HWREG(GPIO_PORTB_BASE + 0x00000528) |= GPIO_PIN_6;
ROM_ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH21 | ADC_CTL_IE | ADC_CTL_END);
// ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH21 | ADC_CTL_IE | ADC_CTL_END);
// ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END);
// ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH9 | ADC_CTL_IE | ADC_CTL_END);
ROM_ADCSequenceEnable(ADC0_BASE, 0);
ROM_ADCSequenceDataGet(ADC0_BASE, 0, ulADC0_Value);
ADCIntClear(ADC0_BASE, 0);
ROM_ADCIntClear(ADC0_BASE, 0);
ROM_ADCIntEnable(ADC0_BASE, 0);
SysCtlDelay(1000);
return;
}
void
InitTimer(void)
{
//
// Enable the peripherals used by this example.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
//
// Enable processor interrupts.
//
//
// Configure the two 32-bit periodic timers.
//
ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()/10);
//
// Setup the interrupts for the timer timeouts.
//
ROM_IntEnable(INT_TIMER0A);
ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
//
// Enable the timers.
//
ROM_TimerEnable(TIMER0_BASE, TIMER_A);
SysCtlDelay(1000);
return;
}
int
main(void)
{
tContext sContext;
tRectangle sRect;
FPUEnable();
FPULazyStackingEnable();
//
// Set the clocking to run directly from the crystal.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);
//
// Initialize the UART.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioInit(0);
UARTprintf("Hello, world!\n");
//
// Initialize the display driver.
//
CFAL96x64x16Init();
//
// Initialize the graphics context.
//
GrContextInit(&sContext, &g_sCFAL96x64x16);
//
// Fill the top 24 rows of the screen with blue to create the banner.
//
sRect.sXMin = 0;
sRect.sYMin = 0;
sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1;
sRect.sYMax = 23;
GrContextForegroundSet(&sContext, ClrDarkBlue);
GrRectFill(&sContext, &sRect);
//
// Put a white box around the banner.
//
GrContextForegroundSet(&sContext, ClrWhite);
GrRectDraw(&sContext, &sRect);
//
// Put the application name in the middle of the banner.
//
GrContextFontSet(&sContext, g_pFontCm12);
GrStringDrawCentered(&sContext, "hello", -1,
GrContextDpyWidthGet(&sContext) / 2, 10, 0);
//
// Say hello using the Computer Modern 40 point font.
//
GrStringDraw(&sContext, "PMotor: ", -1, 3,
26, 1);
GrStringDraw(&sContext, "PTotal: ", -1, 3,
36, 1);
GrStringDraw(&sContext, "n : ", -1, 3,
46, 1);
//
// Flush any cached drawing operations.
//
GrFlush(&sContext);
InitTimer();
// InitADC();
ROM_IntMasterEnable();
//
// We are finished. Hang around doing nothing.
//
while(1)
{
}
}


