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.

Educational Booster Pack MKII

Other Parts Discussed in Thread: EK-TM4C123GXL, TM4C123GH6PM

I am using the EK-TM4C123GXL LaunchPad, and the MKII Educational Booster Pack, When I run the code, it gives me the accelerometer data instead of the joystick data. I edited a code I have from earlier which would read the voltage on a potentiometer which is connected between 3.3v and ground. That code works,  However when I try the same code, edited to target the Booster pack Joystick pins, J3.26, I get the accelerometer data. I even tried it with the horizontal axis of the joystick, but I get the same pin (J1.2). I am just mapping the launchpad pins which have different names, but they are in the same position. Am I just missing something? Are the pins of the TM4C which match the sockets of the booster pack not connected to an ADC?

  • Using CCS 6.1.2.00015 
  • Using UART to display output
  • Moving the joystick has no change in output
  • Changing orientation of the booster pack changes the output from 0.99 to 2.33
  • Original working code with potentiometer (original code)
  • New code which gets me the accelerometer data is below is targeting the horizontal axis of the joystick (J1.2)

Here is the original code:

#include <stdint.h> // Variable definitions for the C99 standard.
#include <stdio.h> // Input and output facilities for the C99 standard.
#include <stdbool.h> // Boolean definitions for the C99 standard.

#include "inc/tm4c123gh6pm.h" // Definitions for the interrupt and register assignments.
#include "inc/hw_memmap.h" // Memory map definitions of the Tiva C Series device.
#include "inc/hw_types.h" // Definitions of common types and macros.
#include "inc/hw_gpio.h" // Defines and Macros for GPIO hardware.

#include "driverlib/sysctl.h" // Definitions and macros for System Control API of DriverLib.
#include "driverlib/interrupt.h" // Defines and macros for NVIC Controller API of DriverLib.
#include "driverlib/gpio.h" // Definitions and macros for GPIO API of DriverLib.
#include "driverlib/timer.h" // Defines and macros for Timer API of DriverLib.
#include "driverlib/pin_map.h" //Mapping of peripherals to pins for all parts.
#include "driverlib/uart.h" // Definitions and macros for UART API of DriverLib.
#include "driverlib/adc.h" // Definitions for ADC API of DriverLib.
#include "driverlib/fpu.h" // Prototypes for the FPU manipulation routines.

#include "utils/uartstdio.h" // Prototypes for the UART console functions.
// Needs to add "utils/uartstdio.c" through a relative link.

#define TIMER0_FREQ 2 // Freqency in Hz, for blinking LED.
#define TIMER1_FREQ 1 // Frequency in Hz, for ADC.
#define UART0_BAUDRATE 115200 // UART baudrate in bps.

#define ADC0_SEQ_NUM 0 // ADC Sample Sequence Number
#define MAX_ADC_SAMP_VAL 0x0FFF // max value for 12-bit ADC

#define RED_LED GPIO_PIN_1
#define BLUE_LED GPIO_PIN_2
#define GREEN_LED GPIO_PIN_3

#define DISP_TEXT_LINE_NUM 4
#define DISP_DATA_STR_LEN 20


// function prototypes
void init_LEDs(void);
void init_GPIO(void);
void init_timer(void);
void init_UART(void);
void init_ADC(void);
void Timer0_ISR(void);
void Timer1_ISR(void);

extern void UARTStdioIntHandler(void);


// global variables
uint32_t sys_clock;
uint8_t cur_LED = RED_LED;

const char *disp_text[DISP_TEXT_LINE_NUM] = {
"\n",
"UART and LED Demo\n",
"H: help, R: red, G: green, B: blue, S: Sample Data.\n",
"> " };


uint32_t sig_data=0, sig_data_d;
float sig_data_f;

char disp_data_str[DISP_DATA_STR_LEN];


int main(void)
{
uint32_t i;
unsigned char user_cmd;

// Configure system clock at 40 MHz.
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
sys_clock = SysCtlClockGet();

// Enable the floating-point unit (FPU).
FPUEnable();
// Configure FPU to perform lazy stacking of the floating-point state.
FPULazyStackingEnable();

init_LEDs();
init_GPIO();
init_ADC();
init_UART();
init_timer();

// Enable the processor to respond to interrupts.
IntMasterEnable();

// Start the timer by enabling operation of the timer module.
TimerEnable(TIMER0_BASE, TIMER_A);
TimerEnable(TIMER1_BASE, TIMER_A);
// Initial display on terminal.
for(i=0; i<DISP_TEXT_LINE_NUM; i++)
UARTprintf(disp_text[i]);

while(1) {
// Read user inputs from UART if available.
if(UARTRxBytesAvail())
user_cmd = UARTgetc();
else
user_cmd = 0;

switch(user_cmd){
case '\r':
case ' ':
case 'H':
case 'h':
for(i=0; i<DISP_TEXT_LINE_NUM; i++)
UARTprintf(disp_text[i]);
break;
case 'R':
case 'r':
cur_LED = RED_LED;
UARTprintf("\n> ");
break;
case 'B':
case 'b':
cur_LED = BLUE_LED;
UARTprintf("\n> ");
break;
case 'G':
case 'g':
cur_LED = GREEN_LED;
UARTprintf("\n> ");
break;
case 'S':
case 's':
ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM);

while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) {
}
ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM);

ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &sig_data);

sig_data_f = 3.3*sig_data/MAX_ADC_SAMP_VAL;

if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_4))
sig_data_d = 1;
else
sig_data_d = 0;

// Print data to UART0
snprintf(disp_data_str, DISP_DATA_STR_LEN, "v=%.2f, d=%d", sig_data_f, sig_data_d);
UARTprintf("\n%s\n> ", disp_data_str);

break;
}
}
}


void init_LEDs(void)
{
// Enable and configure LED peripheral.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable GPIO Port F.
// Three onboard LEDs, R:PF1, B:PF2, G:PF3.
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
}

void init_timer(void)
{
// Enable and configure timer peripheral.
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

// Configure Timer0 as a 32-bit timer in periodic mode.
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
// Initialize timer load register.
TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1);

// Configure Timer1 as a 32-bit timer in periodic mode.
TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
// Initialize timer load register.
TimerLoadSet(TIMER1_BASE, TIMER_A, sys_clock/TIMER1_FREQ -1);


// Registers a function to be called when the interrupt occurs.
IntRegister(INT_TIMER0A, Timer0_ISR);
// The specified interrupt is enabled in the interrupt controller.
IntEnable(INT_TIMER0A);
// Enable the indicated timer interrupt source.
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

// Registers a function to be called when the interrupt occurs.
IntRegister(INT_TIMER1A, Timer1_ISR);
// The specified interrupt is enabled in the interrupt controller.
IntEnable(INT_TIMER1A);
// Enable the indicated timer interrupt source.
TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
}


void init_UART(void)
{
// Enable and configure UART0 for debugging printouts.
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

// Registers a function to be called when the interrupt occurs.
IntRegister(INT_UART0, UARTStdioIntHandler);
UARTStdioConfig(0, UART0_BAUDRATE, sys_clock);
}


void init_ADC(void)
{
// Enable and configure ADC0. Sample from PD0/AIN7/BY
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0);

ADCSequenceConfigure(ADC0_BASE, ADC0_SEQ_NUM, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, ADC0_SEQ_NUM, 0, ADC_CTL_IE|ADC_CTL_CH7|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, ADC0_SEQ_NUM);
}


void init_GPIO(void)
{
// Enable and configure PE4 as digital input
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_4);
}


// Timer0 interrupt service routine
void Timer0_ISR(void)
{
// Clear the timer interrupt.
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

// Blink LED. Read the current state of GPIO pins and write back the opposite state.
if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3)) {
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
}
else {
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, cur_LED);
}
}

void Timer1_ISR(void)
{
// Clear the timer interrupt.
TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);


ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM);

while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) {
}
ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM);

ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &sig_data);

sig_data_f = 3.3*sig_data/MAX_ADC_SAMP_VAL;

if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_4))
sig_data_d = 1;
else
sig_data_d = 0;

// Print data to UART0
snprintf(disp_data_str, DISP_DATA_STR_LEN, "v=%.2f, d=%d", sig_data_f, sig_data_d);
UARTprintf("\n%s\n> ", disp_data_str);


}

New non working code:

#include <stdint.h> // Variable definitions for the C99 standard.
#include <stdio.h> // Input and output facilities for the C99 standard.
#include <stdbool.h> // Boolean definitions for the C99 standard.

#include "inc/tm4c123gh6pm.h" // Definitions for the interrupt and register assignments.
#include "inc/hw_memmap.h" // Memory map definitions of the Tiva C Series device.
#include "inc/hw_types.h" // Definitions of common types and macros.
#include "inc/hw_gpio.h" // Defines and Macros for GPIO hardware.

#include "driverlib/sysctl.h" // Definitions and macros for System Control API of DriverLib.
#include "driverlib/interrupt.h" // Defines and macros for NVIC Controller API of DriverLib.
#include "driverlib/gpio.h" // Definitions and macros for GPIO API of DriverLib.
#include "driverlib/timer.h" // Defines and macros for Timer API of DriverLib.
#include "driverlib/pin_map.h" //Mapping of peripherals to pins for all parts.
#include "driverlib/uart.h" // Definitions and macros for UART API of DriverLib.
#include "driverlib/adc.h" // Definitions for ADC API of DriverLib.
#include "driverlib/fpu.h" // Prototypes for the FPU manipulation routines.

#include "utils/uartstdio.h" // Prototypes for the UART console functions.
// Needs to add "utils/uartstdio.c" through a relative link.

#define TIMER0_FREQ 2 // Freqency in Hz, for blinking LED.
#define TIMER1_FREQ 1 // Frequency in Hz, for ADC.
#define UART0_BAUDRATE 115200 // UART baudrate in bps.

#define ADC0_SEQ_NUM 0 // ADC Sample Sequence Number
#define MAX_ADC_SAMP_VAL 0x0FFF // max value for 12-bit ADC

#define RED_LED GPIO_PIN_1
#define BLUE_LED GPIO_PIN_2
#define GREEN_LED GPIO_PIN_3

#define DISP_TEXT_LINE_NUM 4
#define DISP_DATA_STR_LEN 20


// function prototypes
void init_LEDs(void);
void init_GPIO(void);
void init_timer(void);
void init_UART(void);
void init_ADC(void);
void Timer0_ISR(void);
void Timer1_ISR(void);

extern void UARTStdioIntHandler(void);


// global variables
uint32_t sys_clock;
uint8_t cur_LED = RED_LED;

const char *disp_text[DISP_TEXT_LINE_NUM] = {
"\n",
"UART and LED Demo\n",
"H: help, R: red, G: green, B: blue, S: Sample Data.\n",
"> " };


uint32_t sig_data=0, sig_data_d;
float sig_data_f;

char disp_data_str[DISP_DATA_STR_LEN];


int main(void)
{
uint32_t i;
unsigned char user_cmd;

// Configure system clock at 40 MHz.
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
sys_clock = SysCtlClockGet();

// Enable the floating-point unit (FPU).
FPUEnable();
// Configure FPU to perform lazy stacking of the floating-point state.
FPULazyStackingEnable();

init_LEDs();
init_GPIO();
init_ADC();
init_UART();
init_timer();

// Enable the processor to respond to interrupts.
IntMasterEnable();

// Start the timer by enabling operation of the timer module.
TimerEnable(TIMER0_BASE, TIMER_A);
TimerEnable(TIMER1_BASE, TIMER_A);
// Initial display on terminal.
for(i=0; i<DISP_TEXT_LINE_NUM; i++)
UARTprintf(disp_text[i]);

while(1) {
// Read user inputs from UART if available.
if(UARTRxBytesAvail())
user_cmd = UARTgetc();
else
user_cmd = 0;

switch(user_cmd){
case '\r':
case ' ':
case 'H':
case 'h':
for(i=0; i<DISP_TEXT_LINE_NUM; i++)
UARTprintf(disp_text[i]);
break;
case 'R':
case 'r':
cur_LED = RED_LED;
UARTprintf("\n> ");
break;
case 'B':
case 'b':
cur_LED = BLUE_LED;
UARTprintf("\n> ");
break;
case 'G':
case 'g':
cur_LED = GREEN_LED;
UARTprintf("\n> ");
break;
case 'S':
case 's':
ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM);

while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) {
}
ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM);

ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &sig_data);

sig_data_f = 3.3*sig_data/MAX_ADC_SAMP_VAL;

if(GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_5))
sig_data_d = 1;
else
sig_data_d = 0;

// Print data to UART0
snprintf(disp_data_str, DISP_DATA_STR_LEN, "v=%.2f, d=%d", sig_data_f, sig_data_d);
UARTprintf("\n%s\n> ", disp_data_str);

break;
}
}
}


void init_LEDs(void)
{
// Enable and configure LED peripheral.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable GPIO Port F.
// Three onboard LEDs, R:PF1, B:PF2, G:PF3.
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
}

void init_timer(void)
{
// Enable and configure timer peripheral.
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

// Configure Timer0 as a 32-bit timer in periodic mode.
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
// Initialize timer load register.
TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1);

// Configure Timer1 as a 32-bit timer in periodic mode.
TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
// Initialize timer load register.
TimerLoadSet(TIMER1_BASE, TIMER_A, sys_clock/TIMER1_FREQ -1);


// Registers a function to be called when the interrupt occurs.
IntRegister(INT_TIMER0A, Timer0_ISR);
// The specified interrupt is enabled in the interrupt controller.
IntEnable(INT_TIMER0A);
// Enable the indicated timer interrupt source.
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

// Registers a function to be called when the interrupt occurs.
IntRegister(INT_TIMER1A, Timer1_ISR);
// The specified interrupt is enabled in the interrupt controller.
IntEnable(INT_TIMER1A);
// Enable the indicated timer interrupt source.
TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
}


void init_UART(void)
{
// Enable and configure UART0 for debugging printouts.
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

// Registers a function to be called when the interrupt occurs.
IntRegister(INT_UART0, UARTStdioIntHandler);
UARTStdioConfig(0, UART0_BAUDRATE, sys_clock);
}


void init_ADC(void)
{
// Enable and configure ADC0. Sample from PD0/AIN7/BY
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_5);

ADCSequenceConfigure(ADC0_BASE, ADC0_SEQ_NUM, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, ADC0_SEQ_NUM, 0, ADC_CTL_IE|ADC_CTL_CH7|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, ADC0_SEQ_NUM);
}


void init_GPIO(void)
{
// Enable and configure PE4 as digital input
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_5);
}


// Timer0 interrupt service routine
void Timer0_ISR(void)
{
// Clear the timer interrupt.
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

// Blink LED. Read the current state of GPIO pins and write back the opposite state.
if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3)) {
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
}
else {
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, cur_LED);
}
}

void Timer1_ISR(void)
{
// Clear the timer interrupt.
TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);


ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM);

while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) {
}
ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM);

ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &sig_data);

sig_data_f =3.3*sig_data/MAX_ADC_SAMP_VAL;

if(GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_5))
sig_data_d = 1;
else
sig_data_d = 0;

// Print data to UART0
snprintf(disp_data_str, DISP_DATA_STR_LEN, "v=%.2f, d=%d", sig_data_f, sig_data_d);
UARTprintf("\n%s\n> ", disp_data_str);


}

  • Hello Jonathan,

    For future reference, please use "Syntaxhighlighter" while posting code to make it easy to read/understand the code.

    Are you sure you are seeing the Accelerometer data and not some random data?

    Did you ensure that there is no hardware configuration on the boosterpack that somehow multiplexes the IOs of Accelerometer and the Joystick?

    I looked at your code and it looks like you are using the correct peripheral pins on the MCU - PB5 for Horizontal axis of the Joystick. But the "init_GPIO" function is also using PB5 as a GPIO. This could be a conflict as PB5 is configured as ADC and GPIO.

    Thanks,
    Sai
  • Thank you Sai,

    I had the GPIO set as both a digital pin and ADC. I also Changed the channel to channel 4 on:

    ADCSequenceStepConfigure(ADC0_BASE, ADC0_SEQ_NUM, 0, ADC_CTL_IE|ADC_CTL_CH7|ADC_CTL_END);

    is changed to:

    ADCSequenceStepConfigure(ADC0_BASE, ADC0_SEQ_NUM, 0, ADC_CTL_IE|ADC_CTL_CH4|ADC_CTL_END);

    and now it works for the Vertical axis.

    Thanks,

    -Jonathan