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.

LM3S6965 EVAL BOARD and TLC5940

Other Parts Discussed in Thread: TLC5940


Hello.

I`m start to create a driver to TLC5940 chip!

I did some code but I have some problems!

I don't no what is the correct time to GSCLK and the timer that Will send the data!

Here is my code

Plz is some one can help me to solve or send me some part of code for me look?

Thanks For All



#include "inc/hw_ints.h"

#include "inc/hw_memmap.h"

#include "inc/hw_types.h"

#include "driverlib/debug.h"

#include "driverlib/gpio.h"

#include "driverlib/interrupt.h"

#include "driverlib/sysctl.h"

#include "driverlib/timer.h"

#include "drivers/rit128x96x4.h"

#include "io.h"

#include "driverlib/ssi.h"


#define XLAT      GPIO_PIN_0

#define GSCLK     GPIO_PIN_1

#define BLANK     GPIO_PIN_2

#define FREE      GPIO_PIN_3



char PORTB = 0x00; 


//*****************************************************************************

//

// Initialize the IO used in this demo

// 1. STATUS LED on Port F pin 0

// 2. PWM on Port D Pin 1 (PWM1)

//

//*****************************************************************************

void

io_init(void)

{

    //

    // Enable GPIO bank F to allow control of the LED.

    //


    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);    

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); 

    //

    // Configure Port F0 for as an output for the status LED.

    //

    

    

    GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,GPIO_PIN_0 |GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);

    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_0);

}


//*****************************************************************************

//

// Turn PIN on

//

//*****************************************************************************

void

io_set_PORTB(char pin)

{

    //

    // SET PIN

    //

    GPIOPinWrite(GPIO_PORTB_BASE, pin, (PORTB |=  pin));

}



//*****************************************************************************

//

// Turn PIN off

//

//*****************************************************************************

void

io_clear_PORTB(char pin)

{

    //

    // SET PIN

    //

        GPIOPinWrite(GPIO_PORTB_BASE, pin, (PORTB &= ~pin));

}


//*****************************************************************************

//

// Turn PIN toggle

//

//*****************************************************************************

void

io_pulse_PORTB(char pin)

{


    //

    // SET PIN

    //

    GPIOPinWrite(GPIO_PORTB_BASE, pin, (PORTB &= ~pin));

    for(int w = 0 ; w < 100000; w++)

    {}

    GPIOPinWrite(GPIO_PORTB_BASE, pin, (PORTB |=  pin));

}



//*****************************************************************************

//

// Set the status LED on or off.

//

//*****************************************************************************

void

io_set_led(tBoolean bOn)

{

    //

    // Turn the LED on or off as requested.

    //

    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, bOn ? GPIO_PIN_0 : 0);

}



//*****************************************************************************

//

//! \addtogroup example_list

//! <h1>Timer (timers)</h1>

//!

//! This example application demonstrates the use of the timers to generate

//! periodic interrupts.  One timer is set up to interrupt once per second and

//! the other to interrupt twice per second; each interrupt handler will toggle

//! its own indicator on the display.

//

//*****************************************************************************


//*****************************************************************************

//

// Flags that contain the current value of the interrupt indicator as displayed

// on the OLED display.

//

//*****************************************************************************

unsigned long g_ulFlags;

char DC_mode = 0x3F ;

int GS_mode = 0x0FFF ;

char datadc_send [12] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

char datags_send [24] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

char time_DC1 = 0x00;

char time_DC2 = 0x00;

short int time_GS1 = 0x00;

short int time_GS2 = 0x00;

short int time_GS22 = 0x00;

char teste = 0x00;

int dc_index = 0x00;

int dc_index2 = 0x00; 

int dc_index3 = 0x00;

int gs_index = 0x00;

int gs_index2 = 0x00; 

int gs_index3 = 0x00;

char dcsent = 0x00;

int Counter = 0x00;


char s_DC_mode[16] = {0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F};

short int s_GS_mode[16] = {0x0040,0x0000,0x0040,0x0000,0x0040,0x0000,0x0040,0x0000,0x0040,0x0000,0x0040,0x0000,0x0040,0x0000,0x0040,0x0000};

//*****************************************************************************

//

// The error routine that is called if the driver library encounters an error.

//

//*****************************************************************************

#ifdef DEBUG

void

__error__(char *pcFilename, unsigned long ulLine)

{

}

#endif



//*****************************************************************************

//

// The interrupt handler for the first timer interrupt.

//

//*****************************************************************************

void

Timer0IntHandler(void)

{


    //

    // Clear the timer interrupt.

    //

    TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);


    

    //

    // Start to Send data

    //


    if(Counter>1060)

    {

      Counter = 0;

      dc_index = 0x00;

      dc_index2 = 0x00; 

      dc_index3 = 0x00;

      gs_index = 0x00;

      gs_index2 = 0x00; 

      gs_index3 = 0x00;

      if(!dcsent)

      {

        io_clear_PORTB(BLANK);

      }

      else

      {

        io_set_PORTB(BLANK);

      }

       //pulse XLAT

      io_pulse_PORTB(XLAT);

   }

    if(!dcsent)

    {

      if(dc_index2 < 16)

      {

        for (dc_index = 0; dc_index<12 ; dc_index++)

        {

          dc_index3 = dc_index2 + 1;

          time_DC1 = s_DC_mode[dc_index2];

           time_DC2 = s_DC_mode[dc_index3];

          if((dc_index == 0) | (dc_index ==3) | (dc_index ==6) |(dc_index == 9))

          {

            datadc_send[dc_index] = (time_DC1 << 2) | (time_DC2 >> 4);

            SSIDataPut(SSI_BASE, datadc_send[dc_index]);

          }

          if((dc_index == 1) | (dc_index ==4) | (dc_index ==7) | (dc_index ==10))

          {

            datadc_send[dc_index] = (time_DC1 << 4) | (time_DC2 >> 2);

            SSIDataPut(SSI_BASE, datadc_send[dc_index]);

          }

          if((dc_index == 2) | (dc_index ==5) |(dc_index == 8) | (dc_index ==11))

          {

            datadc_send[dc_index] = (time_DC1 << 6) | (time_DC2 & 0x3F);

            SSIDataPut(SSI_BASE, datadc_send[dc_index]);

            dc_index2 = dc_index2 + 1;

          }

          dc_index2 = dc_index2 + 1;

          if(dc_index2 == 16)

          {

            io_pulse_PORTB(XLAT);

            dc_index2 = 0;

            dc_index3 = 0;

            dcsent = 1;          

          }

        }

      }

    }

    else

    {

      if(gs_index2 < 16)

      {

        for (gs_index = 0; gs_index<24 ; gs_index++)

        {

          gs_index3 = gs_index2 + 1;

          if(gs_index2 == 16)

          {

            gs_index2 = 0;

            gs_index3 = 0;

          }

          time_GS1 = s_GS_mode[gs_index2];

          time_GS2 = s_GS_mode[gs_index3];

          if((gs_index == 0) | (gs_index ==3) | (gs_index ==6) |(gs_index == 9)|

             (gs_index == 12)|(gs_index == 15)|(gs_index == 18)|(gs_index == 21))

          {

            datags_send[gs_index] = (time_GS1 >> 4);

            SSIDataPut(SSI_BASE, datags_send[gs_index]);

          }

          if((gs_index == 1) | (gs_index ==4) | (gs_index ==7) | (gs_index ==10)|

             (gs_index == 13)|(gs_index == 16)|(gs_index == 19)|(gs_index == 22))      

          {

            datags_send[gs_index] = (time_GS1 << 4) | (time_GS2 >> 8);

            SSIDataPut(SSI_BASE, datags_send[gs_index]);

          }

          if((gs_index == 2) | (gs_index ==5) |(gs_index == 8) | (gs_index ==11)|

             (gs_index == 14)|(gs_index == 17)|(gs_index == 20)|(gs_index == 23))   

          {

            datags_send[gs_index] = (time_GS2 & 0xFF);

           SSIDataPut(SSI_BASE, datags_send[gs_index]);

            gs_index2 = gs_index2 + 2;

          }

          if(gs_index2 == 16)

          {

  

            gs_index2 = 0;

            gs_index3 = 0;

            //pulse XLAT

            io_pulse_PORTB(XLAT);

            //LOW BLANK      

            io_clear_PORTB(BLANK); 

            gs_index2 = 17;

          }

          

        }

      }

    }


        

    //

    // Update the interrupt status on the display.

    //

    IntMasterDisable();

    IntMasterEnable();

}


//*****************************************************************************

//

// The interrupt handler for the second timer interrupt.

//

//*****************************************************************************

void

Timer1IntHandler(void)

{

    //

    // Clear the timer interrupt.

    //

    TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);


    //

    // Toggle the flag for the second timer.

    //

    HWREGBITW(&g_ulFlags, 1) ^= 1;

        

    if(gs_index2==17)

    {

      Counter++;

      io_pulse_PORTB(GSCLK);

    }

    //

    // Update the interrupt status on the display.

    //

    IntMasterDisable();

    RIT128x96x4StringDraw(HWREGBITW(&g_ulFlags, 1) ? "1" : "0", 90, 32, 15);

    IntMasterEnable();

}


//*****************************************************************************

//

// This example application demonstrates the use of the timers to generate

// periodic interrupts.

//

//*****************************************************************************

int

main(void)

{

    //

    // Set the clocking to run directly from the crystal.

    //

    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |

                   SYSCTL_XTAL_8MHZ);


    //

    // Initialize the OLED display and write status.

    //

    RIT128x96x4Init(1000000);

    RIT128x96x4StringDraw("ANDRE", 18, 24, 15);



    //

    // Enable the peripherals used by this example.

    //

    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    //

    // Enable the peripherals used by this example.

    //

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);

    

        

    io_init();

    

    io_clear_PORTB(XLAT);

    io_clear_PORTB(GSCLK);

    io_clear_PORTB(BLANK);

    io_clear_PORTB(FREE);


    io_set_PORTB(XLAT);

    io_set_PORTB(GSCLK);

    io_set_PORTB(BLANK);

    io_set_PORTB(FREE);    

    

    io_clear_PORTB(XLAT);

    io_clear_PORTB(GSCLK);

    io_clear_PORTB(BLANK);

    io_clear_PORTB(FREE);


      

    //

    // Enable processor interrupts.

    //

    IntMasterEnable();

    

    //

    // Configure the SSI.

    //

    SSIConfigSetExpClk(SSI_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 4000, 8);

    //

    // Enable the SSI module.

    //

    SSIEnable(SSI_BASE);

        

    //

    // Configure the two 32-bit periodic timers.

    //

    TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER);

    TimerConfigure(TIMER1_BASE, TIMER_CFG_32_BIT_PER);

    TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()/5000);

    TimerLoadSet(TIMER1_BASE, TIMER_A, SysCtlClockGet()/5000);


    //

    // 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);


    //

    // Loop forever while the timers run.

    //

    while(1)

    {


    }

}