Hi!
I need some help, I'm trying to do an application where the Stellaris LaunchPad reads an analog signal with a frequency of 2kHz, after the value is read this will be sent from the UART to a Matlab application, now I'm putting a Sin signal in the stellaris and I want to see the same signal in matlab but the plot in matlab is not even close to the signal in the Stellaris, so I was wondering if the problem is in the code of the Stellaris
Here the code that I did, I hope someone can help me:
//Function libraries related with the project have to be declared
#include "SAMP.h"
#include "inc/hw_memmap.h"
#include "inc/hw_ssi.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_timer.h"
#include "driverlib/ssi.h"
#include "driverlib/uart.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/adc.h"
#include "drivers/buttons.h"
#include "driverlib/rom.h"
//****************************************************************
//
//Error Routine
//
//****************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
//****************************************************************
//
//Global Variables
//
//****************************************************************
int LED = 2;
unsigned long ulDataRx; // SPI receiving variable (16 bits)
//***************************************************************
//
//Interrupts initialization
//
//***************************************************************
static volatile unsigned long ulHibModeEntryCount;
//*********************Timer 0************************************
void
Timer0IntHandler(void)
{
// Clear the timer interrupt.
ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// ROM_UARTCharPut(UART1_BASE,'S');
// SysCtlDelay(100);
ROM_UARTCharPut(UART1_BASE,ulDataRx >> 8);
// SysCtlDelay(100);
ROM_UARTCharPut(UART1_BASE,ulDataRx & 0x00FF);
// SysCtlDelay(100);
// ROM_UARTCharPut(UART1_BASE,'E');
// Cycle through 1000 values
if (ulDataRx == 10000) {ulDataRx = 0;} else {ulDataRx++;}
}
// Show that the interrupts are working by flashing the led
void
Timer1IntHandler(void)
{
// Clear the timer interrupt.
ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
// Turn on the LED
//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, LED);
// Cycle through Red, Green and Blue LEDs
//if (LED == 8) {LED = 2;} else {LED = LED*2;}
}
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
// Communication through the virtual port
void
UART0IntHandler(void)
{
unsigned long ulStatus;
//
// Get the interrupt status.
//
ulStatus = ROM_UARTIntStatus(UART0_BASE, true);
//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART0_BASE, ulStatus);
//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART0_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
ROM_UARTCharPutNonBlocking(UART0_BASE,
ROM_UARTCharGetNonBlocking(UART0_BASE));
}
}
//*****************************************************************************
//
// Send a string to the UART.
//
//*****************************************************************************
void
UART0Send(const unsigned char *pucBuffer, unsigned long ulCount)
{
//
// Loop while there are more characters to send.
//
while(ulCount--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART0_BASE, *pucBuffer++);
}
}
//Main function
int main(void)
{
// Variables for the ADC
unsigned char ulADC0_Value[3]; // array of chars to send for the UART
unsigned long ulADC0Value [1] ; // ADC Variable
//Variables for the button
unsigned char ucButtons, ucChanged, ucRepeat;
//initialize button dir/drivers/buttons.c it is possible to see the initialization ob the button
ButtonsInit();
// Initialize device
DeviceInit();
// While function, here it is possible to see the program and the tasks that the micro-controller has to do
//
while(1)
{
//function ButtonsPoll() to see when the button has been pushed
ucButtons=ButtonsPoll(&ucChanged, &ucRepeat);
//when the button is pushed the LED Activates, the value from the ADC is obtained
//the value of the temperature is converted to char then is sent to the UART
//it is possible to see the data sent with the PUTTY application
while (BUTTON_PRESSED(0X01, ucButtons, ucChanged))
{
//SysCtlDelay(1000);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, LED);
// Cycle through Red, Green and Blue LEDs
if (LED == 8) {LED = 2;} else {LED = LED*2;}
ROM_ADCIntClear(ADC0_BASE, 1);
ROM_ADCProcessorTrigger(ADC0_BASE, 1);
//
// Wait for conversion to be completed.
//
while(!ROM_ADCIntStatus(ADC0_BASE, 1, false))
{
}
//
// Clear the ADC interrupt flag.
//
// Value of ADC when it is ready
ROM_ADCSequenceDataGet(ADC0_BASE, 1, ulADC0Value);
// Read ADC Value.
ulADC0_Value[0] = ( ulADC0Value[0] / 100 ) + 48 ;
ulADC0_Value[1] = ((ulADC0Value[0] % 100) / 10) + 48;
ulADC0_Value[2] = ((ulADC0Value[0] % 100) % 10)+ 48 ;
UART0Send((unsigned char*) ulADC0_Value, 3);
// converting value to char
}
}
}
void DeviceInit(void)
{
// Init Clock
// Set the to 80MHz
ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
// -------------- INIT UART ----------------
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
// Set GPIO A0 AS UART pins.
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
// Init pin function
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
// Configure the UART for 115,200, 8-N-1 operation.
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
// Enable the UART interrupt.
IntEnable(INT_UART0);
UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
// -------------- INIT TIMERS -------------------------------------------------------------------
// Enable peripherals
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
// Enable processor interrupts.
IntMasterEnable();
// Configure 32-bit periodic timers.
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet());
TimerLoadSet(TIMER1_BASE, TIMER_A, SysCtlClockGet());
// Setup the interrupts for the timer timeouts.
IntEnable(INT_TIMER0A);
IntEnable(INT_TIMER1A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
// Enable the timers.
// TimerEnable(TIMER0_BASE, TIMER_A);
TimerEnable(TIMER1_BASE, TIMER_A);
//-----------------INIT ADC-------------------------------------------------
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);
ROM_SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS);
ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 16);
//INIT PIN FUNCTION
ROM_ADCSequenceDisable(ADC0_BASE, 1);
ROM_ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0 | ADC_CTL_IE |ADC_CTL_END);
ROM_ADCSequenceEnable(ADC0_BASE, 1);
ROM_ADCIntClear(ADC0_BASE, 1);
// -------------- GPIO ---------------
// LEDs
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
//**************************************************************************
}
