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.

Programming Launchxl - F28377s in energia

Other Parts Discussed in Thread: ENERGIA

I had installed Energia 0101E0017 but in tools---> board, the board name (Launchxl - F28377s)  doesnt appear. what should i do to fix it.

//###########################################################################//// FILE: Example_F28377xLaunchPadDemo.c//// TITLE: F28377S LaunchPad Out of Box Demo//// DESCRIPTION://! \addtogroup f28377xX_example_list//! <h1>Out of Box Demo (LaunchPadDemo)</h1>//!//!  This program is the demo program that comes pre-loaded on the F28377S//!  LaunchPad development kit.  The program starts by flashing the two user//!  LEDs. After a few seconds the LEDs stop flashing and the device starts //!  sampling ADCIN14 once a second.  If the sample is greater than midscale//!  the red LED on the board is lit, while if it is lower a blue LED is lit.  //!  Sample data is also display in a serial terminal via the boards back //!  channel UART.  You may view this data by configuring a serial termainal //!  to the correct COM port at 115200 Baud 8-N-1.//!////###########################################################################// $TI Release: 2837xS C/C++ Header Files V1.00 $// $Release Date: July 15, 2015 $//###########################################################################

#include <stdint.h>#include <stdbool.h>#include <stdio.h>#include <file.h>
#include "F28x_Project.h"     // DSP28x Headerfile#include "ti_ascii.h"#include "sci_io.h"

#define CONV_WAIT 1L //Micro-seconds to wait for ADC conversion. Longer than necessary.
extern void DSP28x_usDelay(Uint32 Count);
//static unsigned short indexX=0;//static unsigned short indexY=0;
const unsigned char escRed[] = {0x1B, 0x5B, '3','1', 'm'};const unsigned char escWhite[] = {0x1B, 0x5B, '3','7', 'm'};const unsigned char escLeft[] = {0x1B, 0x5B, '3','7', 'm'};const unsigned char pucTempString[] = "ADCINA0 Sample:     ";


///////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ConfigureADC(void);void SetupADCSoftware(void);
//variables to store conversion resultsUint16 AdcaResult0;Uint16 AdcaResult1;Uint16 AdcbResult0;Uint16 AdcbResult1;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
















int16 currentSample_a0;
int16 currentSample_a1;
int16 currentSample_b0;
int16 currentSample_b1;
int16 counter;
Uint16 t_count;
Uint16 spi_data_send;Uint16 spi_data_receive;

/*
int16_t sampleADC_A(void){ int16_t temp; //int16_t temp_b;

    //Force start of conversion on SOC0    AdcaRegs.ADCSOCFRC1.all = 0x03;
//start conversions immediately via software, ADCB    // AdcbRegs.ADCSOCFRC1.all = 0x03; //SOC0 and SOC1
    //Wait for end of conversion.    while(AdcaRegs.ADCINTFLG.bit.ADCINT1 == 0){}  //Wait for ADCINT1    AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;        //Clear ADCINT1
//wait for ADCB to complete, then acknowledge flag    // while(AdcbRegs.ADCINTFLG.bit.ADCINT1 == 0);    // AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
    //Get temp sensor sample result from SOC0    temp = AdcaResultRegs.ADCRESULT1;  //  temp_b = AdcbResultRegs.ADCRESULT1;
    //Return the raw temperature because the devices don't have slope/offset values    return(temp);
}*//*int16_t sampleADC_B(void){ //int16_t temp; int16_t temp_b;

    //Force start of conversion on SOC0    //AdcaRegs.ADCSOCFRC1.all = 0x03;
//start conversions immediately via software, ADCB    AdcbRegs.ADCSOCFRC1.all = 0x03; //SOC0 and SOC1
    //Wait for end of conversion.   // while(AdcaRegs.ADCINTFLG.bit.ADCINT1 == 0){}  //Wait for ADCINT1   // AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;        //Clear ADCINT1
//wait for ADCB to complete, then acknowledge flag    while(AdcbRegs.ADCINTFLG.bit.ADCINT1 == 0);    AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
    //Get temp sensor sample result from SOC0  //  temp = AdcaResultRegs.ADCRESULT1;  temp_b = AdcbResultRegs.ADCRESULT1;
    //Return the raw temperature because the devices don't have slope/offset values    return(temp_b);
}*//*void drawTILogo(void){    unsigned char ucChar, lastChar;        putchar('\n');    while(indexY<45)    {        if(indexY<45){            if(indexX<77){                ucChar = ti_ascii[indexY][indexX++] ;                                //We are in the TI logo make it red                if(ucChar != '7' && lastChar=='7'){                    putchar(escRed[0]);                    putchar(escRed[1]);                    putchar(escRed[2]);                    putchar(escRed[3]);                    putchar(escRed[4]);                }                                    //We are in the TI logo make it red                if(ucChar == '7' && lastChar!='7'){                    putchar(escWhite[0]);                    putchar(escWhite[1]);                    putchar(escWhite[2]);                    putchar(escWhite[3]);                    putchar(escWhite[4]);                }                                    putchar(ucChar);                lastChar = ucChar;            }else{                ucChar = 10;                putchar(ucChar);                ucChar = 13;                putchar(ucChar);                indexX=0;                indexY++;            }        }    }}*/void clearTextBox(void){    
    //Change to Red text    //putchar(escRed[0]);    //putchar(escRed[1]);   // putchar(escRed[2]);   // putchar(escRed[3]);   // putchar(escRed[4]);        printf((char*)pucTempString);    
    }
void updateDisplay(void){    // Restore cursor position    printf("\n pin A0 %d \t pin A1 %d \t pin B0 %d\t pin B1 %d \t counter %u \t SPI SENT %u \t SPI RECEIVE %u  ",currentSample_a0, currentSample_a1, currentSample_b0, currentSample_b1, t_count, spi_data_send, spi_data_receive);  // printf(" \n ADC Sample pin B0 _ 4 %d ", currentSample_b);    //printf(" \n ADC Sample pin A1 %d ", 24035);    //printf(" \n ADC Sample pin B1 %d ", 14065);}
// SCIA  8-bit word, baud rate 0x000F, default, 1 STOP bit, no parityvoid scia_init(){
    // Note: Clocks were turned on to the SCIA peripheral    // in the InitSysCtrl() function
  SciaRegs.SCICCR.all =0x0007;   // 1 stop bit,  No loopback                                   // No parity,8 char bits,                                   // async mode, idle-line protocol SciaRegs.SCICTL1.all =0x0003;  // enable TX, RX, internal SCICLK,                                   // Disable RX ERR, SLEEP, TXWAKE
SciaRegs.SCICTL2.bit.TXINTENA =1; SciaRegs.SCICTL2.bit.RXBKINTENA =1;
SciaRegs.SCIHBAUD.all    =0x0000;  // 115200 baud @LSPCLK = 22.5MHz (90 MHz SYSCLK).    SciaRegs.SCILBAUD.all    =53;
SciaRegs.SCICTL1.all =0x0023;  // Relinquish SCI from Reset      return;}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////void delay_loop(){    long      i;    for (i = 0; i < 1000000; i++) {}}
void error(void){    asm("     ESTOP0"); // Test failed!! Stop!    for (;;);}
void spi_init(){ SpiaRegs.SPICCR.all =0x000F;             // Reset on, rising edge, 16-bit char bits SpiaRegs.SPICTL.all =0x0006;         // Enable master mode, normal phase,                                                 // enable talk, and SPI int disabled. SpiaRegs.SPIBRR.all =0x007F;    SpiaRegs.SPICCR.all =0x009F;         // Relinquish SPI from Reset    SpiaRegs.SPIPRI.bit.FREE = 1;                // Set so breakpoints don't disturb xmission}
void spi_xmit(Uint16 a){    SpiaRegs.SPITXBUF=a;}
void spi_fifo_init(){// Initialize SPI FIFO registers    SpiaRegs.SPIFFTX.all=0xE040;    SpiaRegs.SPIFFRX.all=0x2044;    SpiaRegs.SPIFFCT.all=0x0;}
//===========================================================================// No more.//===========================================================================///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void main(){    volatile int status = 0;    uint16_t i;    volatile FILE *fid;        //////////////////////////////////////////////////////    Uint16 sdata;  // send data    Uint16 rdata;  // received data
    //////////////////////////////////////////////////////
    // If running from flash copy RAM only functions to RAM   #ifdef _FLASH    memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);#endif      
    // Initialize System Control:    // PLL, WatchDog, enable Peripheral Clocks    // This example function is found in the F2806x_SysCtrl.c file.       InitSysCtrl();


    // For this example, only init the pins for the SCI-A port.    EALLOW;    GpioCtrlRegs.GPCMUX2.bit.GPIO84 = 1;    GpioCtrlRegs.GPCMUX2.bit.GPIO85 = 1;    GpioCtrlRegs.GPCGMUX2.bit.GPIO84 = 1;    GpioCtrlRegs.GPCGMUX2.bit.GPIO85 = 1;    EDIS;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////    // This example function is found in the F2837xS_Gpio.c file and    // illustrates how to set the GPIO to it's default state.    // InitGpio();  // Skipped for this example    // Setup only the GP I/O only for SPI-A functionality    // This function is found in F2837xS_Spi.c       InitSpiaGpio();
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////



    //  Clear all interrupts and initialize PIE vector table:    // Disable CPU interrupts       DINT;
    // Initialize PIE control registers to their default state.    // The default state is all PIE interrupts disabled and flags    // are cleared.    // This function is found in the F2806x_PieCtrl.c file.       InitPieCtrl();
    // Disable CPU interrupts and clear all CPU interrupt flags:       IER = 0x0000;       IFR = 0x0000;
    // Initialize the PIE vector table with pointers to the shell Interrupt    // Service Routines (ISR).    // This will populate the entire table, even if the interrupt    // is not used in this example.  This is useful for debug purposes.    // The shell ISR routines are found in F2806x_DefaultIsr.c.    // This function is found in F2806x_PieVect.c.       InitPieVectTable();

    // Initialize SCIA    scia_init();
    //Initialize GPIOs for the LEDs and turn them off    EALLOW;    GpioCtrlRegs.GPADIR.bit.GPIO12 = 1;    GpioCtrlRegs.GPADIR.bit.GPIO13 = 1;    GpioDataRegs.GPADAT.bit.GPIO12 = 1;    GpioDataRegs.GPADAT.bit.GPIO13 = 1;    EDIS;

    // Enable global Interrupts and higher priority real-time debug events:    EINT;   // Enable Global interrupt INTM    ERTM;   // Enable Global realtime interrupt DBGM

    //Redirect STDOUT to SCI    status = add_device("scia", _SSA, SCI_open, SCI_close, SCI_read, SCI_write, SCI_lseek, SCI_unlink, SCI_rename);    fid = fopen("scia","w");    freopen("scia:", "w", stdout);    setvbuf(stdout, NULL, _IONBF, 0);    ///////////////////////////////////////////////////////////////////////////////////////////////////
    //spi device peripherals initialisation    //Initialize the Device Peripherals:       spi_fifo_init();  // Initialize the Spi FIFO       spi_init();  // init SPI


    ///////////////////////////////////////////////////////////////////////////////////////////////////


    /*    // Configure the ADC:    // Initialize the ADC EALLOW;
//write configurations AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4 AdcbRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4    AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);    AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
//Set pulse positions to late AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1; AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1;
//power up the ADCs AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1; AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1;
//delay for 1ms to allow ADC time to power up DELAY_US(1000);*/
/*   //ADCA   EALLOW;   AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0;  //SOC0 will convert pin ADCINA0   AdcaRegs.ADCSOC0CTL.bit.ACQPS = 25; //sample window is acqps + 1 SYSCLK cycles   AdcaRegs.ADCSOC1CTL.bit.CHSEL = 0;  //SOC1 will convert pin ADCINA0   AdcaRegs.ADCSOC1CTL.bit.ACQPS = 25; //sample window is acqps + 1 SYSCLK cycles   AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 1; //end of SOC1 will set INT1 flag   AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1;   //enable INT1 flag   AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared  */
   /* //ADCB    AdcbRegs.ADCSOC0CTL.bit.CHSEL = 0;  //SOC0 will convert pin B0    AdcbRegs.ADCSOC0CTL.bit.ACQPS = 25; //sample window is acqps + 1 SYSCLK cycles    AdcbRegs.ADCSOC1CTL.bit.CHSEL = 1;  //SOC1 will convert pin B1    AdcbRegs.ADCSOC1CTL.bit.ACQPS = 25; //sample window is acqps + 1 SYSCLK cycles    AdcbRegs.ADCINTSEL1N2.bit.INT1SEL = 1; //end of SOC1 will set INT1 flag    AdcbRegs.ADCINTSEL1N2.bit.INT1E = 1;   //enable INT1 flag    AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared*/




        //Print a TI Logo to STDOUT    //drawTILogo();
    //Twiddle LEDs    GpioDataRegs.GPADAT.bit.GPIO12 = 0;    GpioDataRegs.GPADAT.bit.GPIO13 = 1;

    for(i = 0; i < 50; i++){
        GpioDataRegs.GPATOGGLE.bit.GPIO12 = 1;        GpioDataRegs.GPATOGGLE.bit.GPIO13 = 1;        DELAY_US(50000);

    }
    //LEDs off    GpioDataRegs.GPADAT.bit.GPIO12 = 1;    GpioDataRegs.GPADAT.bit.GPIO13 = 1;                //Clear out one of the text boxes so we can write more info to it    clearTextBox();        //currentSample = 2041;   // currentSample_b = sampleADC_B();    //Configure the ADCs and power them up           /* ConfigureADC();
        //Setup the ADCs for software conversions            SetupADCSoftware();
            //take conversions indefinitely in loop                do                {                //convert, wait for completion, and store results                //start conversions immediately via software, ADCA                AdcaRegs.ADCSOCFRC1.all = 0x0003; //SOC0 and SOC1                //start conversions immediately via software, ADCB                AdcbRegs.ADCSOCFRC1.all = 0x0003; //SOC0 and SOC1                //wait for ADCA to complete, then acknowledge flag                while(AdcaRegs.ADCINTFLG.bit.ADCINT1 == 0);                AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;                //wait for ADCB to complete, then acknowledge flag                while(AdcbRegs.ADCINTFLG.bit.ADCINT1 == 0);                AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;                //store results                AdcaResult0 = AdcaResultRegs.ADCRESULT0;                AdcaResult1 = AdcaResultRegs.ADCRESULT1;                AdcbResult0 = AdcbResultRegs.ADCRESULT0;                AdcbResult1 = AdcbResultRegs.ADCRESULT1;
                //at this point, conversion results are stored in                //AdcaResult0, AdcaResult1, AdcbResult0, and AdcbResult1
                //software breakpoint, hit run again to get updated conversions                asm("   ESTOP0");
                }while(1);  */

    //Main program loop - continually sample temperature
    counter = 0;    t_count = 0;
    sdata = 0x0000;




    for(;;) {    ConfigureADC();     //Setup the ADCs for software conversions
               SetupADCSoftware();
               //take conversions indefinitely in loop                                     //convert, wait for completion, and store results                    //start conversions immediately via software, ADCA                    AdcaRegs.ADCSOCFRC1.all = 0x0003; //SOC0 and SOC1                    //start conversions immediately via software, ADCB                    AdcbRegs.ADCSOCFRC1.all = 0x0003; //SOC0 and SOC1                    //wait for ADCA to complete, then acknowledge flag                    while(AdcaRegs.ADCINTFLG.bit.ADCINT1 == 0);                    AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;                    //wait for ADCB to complete, then acknowledge flag                    while(AdcbRegs.ADCINTFLG.bit.ADCINT1 == 0);                    AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;                    //store results                    AdcaResult0 = AdcaResultRegs.ADCRESULT0;                    AdcaResult1 = AdcaResultRegs.ADCRESULT1;                    AdcbResult0 = AdcbResultRegs.ADCRESULT0;                    AdcbResult1 = AdcbResultRegs.ADCRESULT1;
                    //at this point, conversion results are stored in                    //AdcaResult0, AdcaResult1, AdcbResult0, and AdcbResult1
                    //software breakpoint, hit run again to get updated conversions                   //asm("   ESTOP0");
        //Sample ADC    currentSample_a0 = (AdcaResult0*8)/10;    currentSample_a1 = (AdcaResult1*8)/10;    currentSample_b0 = (AdcbResult0*8)/10;    currentSample_b1 = (AdcbResult1*8)/10;    counter = counter + 1;    t_count = t_count + 1;
        //Update the serial terminal output        updateDisplay();                //If the sample is above midscale light one LED        if(currentSample_a0 > 2048){       GpioDataRegs.GPADAT.all = 0x2000;        }else{            //Otherwise light the other GpioDataRegs.GPADAT.all = 0x1000;        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////        //spi communication        spi_xmit(currentSample_a0);        // Wait until data is received        while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { }        // Check against sent data        rdata = SpiaRegs.SPIRXBUF;
        spi_data_send = currentSample_a0;        spi_data_receive = rdata;
       // if(rdata != currentSample_a0) error();
        sdata++;


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //DELAY_US(1);            }}
//Write ADC configurations and power up the ADC for both ADC A and ADC Bvoid ConfigureADC(void){ EALLOW;
//write configurations AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4 AdcbRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4    AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);    AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
//Set pulse positions to late AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1; AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1;
//power up the ADCs AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1; AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1;
//delay for 0.5ms to allow ADC time to power up DELAY_US(500);
EDIS;}
void SetupADCSoftware(void){ //Uint16 acqps;
//determine minimum acquisition window (in SYSCLKS) based on resolution /*if(ADC_RESOLUTION_12BIT == AdcaRegs.ADCCTL2.bit.RESOLUTION){ acqps = 14; //75ns } else { //resolution is 16-bit acqps = 63; //320ns }*/
//Select the channels to convert and end of conversion flag    //ADCA    EALLOW;    AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0;  //SOC0 will convert pin A0    AdcaRegs.ADCSOC0CTL.bit.ACQPS = 25; //sample window is acqps + 1 SYSCLK cycles    AdcaRegs.ADCSOC1CTL.bit.CHSEL = 1;  //SOC1 will convert pin A1    AdcaRegs.ADCSOC1CTL.bit.ACQPS = 25; //sample window is acqps + 1 SYSCLK cycles    AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 1; //end of SOC1 will set INT1 flag    AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1;   //enable INT1 flag    AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared    //ADCB    AdcbRegs.ADCSOC0CTL.bit.CHSEL = 0;  //SOC0 will convert pin B0    AdcbRegs.ADCSOC0CTL.bit.ACQPS = 25; //sample window is acqps + 1 SYSCLK cycles    AdcbRegs.ADCSOC1CTL.bit.CHSEL = 1;  //SOC1 will convert pin B1    AdcbRegs.ADCSOC1CTL.bit.ACQPS = 25; //sample window is acqps + 1 SYSCLK cycles    AdcbRegs.ADCINTSEL1N2.bit.INT1SEL = 1; //end of SOC1 will set INT1 flag    AdcbRegs.ADCINTSEL1N2.bit.INT1E = 1;   //enable INT1 flag    AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared}