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.

TLC5917 or TCA6507 Led drivers msp430f2272 C implementation

Other Parts Discussed in Thread: TLC5927, TLC5917, MSP430WARE

Does anyone have source code on following led drivers? 

  • Aly Aytok,

    We have an Evaluation Module in development for the TLC5927 that is based on the MSP430 Launch Pad (http://e2e.ti.com/group/msp430launchpad/w/default.aspx).  We have developed an application board for the MSP430 Launch Pad.  Attached is some code that was developed for this module.  The application board is based on driving 16 RGB LEDs with three TLC5927 devices (one for each color).

    This code is not finalized, but has been effectively demonstrated.

    Does this help?

    Regards,

    Dick

  • Hello,

    The RTF file in this link does not work anymore showing example MSP430 code.

    Would you have example code for the TLC5917 following the datasheet timing and signal sequence correctly? 
    Or a MSP430Ware examples for this driver or a similar one?

    Thank you, Keith

  • Keith,

    I will contact you offline to discuss this request.

    Regards,

    Dick

  • Hello,

    I was having trouble with getting the TLC5917 to operate based on the timing diagrams in the datasheet, but after some more testing, I was successful with getting the code shown below to work. Although it works, it is inconsistent with the diagrams in the datasheet, especially when it comes to the LE signal on pages 11 and 17. I'm not sure if this means that the datasheet is incorrect or if I just got lucky with getting it to work.

    Hope this helps.

    Michael

    OE_HIGH;
    DelayUs(1);
    LE_HIGH;
    DelayUs(1);

    SPI_Send_Byte(Data);

    LE_LOW;
    DelayUs(1);

    OE_LOW;
    DelayUs(1);
    OE_HIGH;
    DelayUs(1);
    OE_LOW;
  • Hi Folks,

    I'm also trying to decipher the timing diagrams of the TLC591X data sheet, Rev D.  The RTF link to the example code no longer works.

    Can someone please send me example code to communicate with this device?  I'm interested in both "Normal" and "Special" mode operation, since we may need to program the configuration register to get the desired constant current we need for the LEDs.

    Code that makes use of DriverLib would be especially helpful, but is not essential.  My target processor is an MSP432P401R.  I could use SPI, or we could do bit-banging of the various clock, data, and control lines.

    Thanks for your help,

    Scott

  • Hi, Scott,

    I've contact with proper engineer to get the code and will reply you later.

    Thanks.

    Regards,
    Kenneth
  • Thank you for the help, Kenneth!

    Scott

  • Hi, Scott,

    I get the code for TLC5927 using MSP430.

    1643.main.c
    //******************************************************************************
    //
    //   Description: The MSP430G2553 acts as the SPI master to three 
    //	 TLC5927/TLC5926 LED drivers sinking current from 16 channels each.
    //	 The drivers sink current from 16 RGB LEDs with each driver sinking 
    //	 current from a particular color node (Red, Green, or Blue).  The SPI
    //	 SCLK is sourced by the SMCLK = DCO ~16MHZ.  The SPI module used by the 
    //	 SPI master is USCI_B0 in SPI mode.
    //
    //	 Timer1_A3 is used to provide PWM outputs in order to dim LEDS.  This is
    //	 done through the OE' pin on the drivers.  The timer is also sourced by
    //	 the SMCLK.
    //
    //	 This file is an edited version of D. Dang's source code, titled:
    //   MSP430G2xx3 Demo - USCI_A0, SPI 3-Wire Master Incremented Data. 
    //
    //                    MSP430G2553
    //                 -----------------
    //          LED <-|P1.0             |
    //                |                 |
    //          TXD <-|P1.1          RST|-> Reset Button
    //                |                 |
    //          RXD <-|P1.2         P1.7|-> SIMO (UCB0SIMO)
    //                |                 |
    //    Button S2 <-|P1.3				|
    //				  |
    //  		 LE <-|P1.4         P1.6|<- SOMI (UCB0SOMI)
    //                |                 |
    //  		OE' <-|P2.1         P1.5|-> SCLK (UCB0CLK)
    //
    //
    //	 Roberto Mancera Jr
    //   Texas Instruments Inc.
    //   June 2011
    //   Built with CCS Version 4.2.3 
    //******************************************************************************
    #include "msp430g2553.h"
    #include "uart.h"
    
    #define SCLK		BIT5
    #define LE 			BIT4
    #define OE 			BIT1
    
    void initialize_clk();
    void initialize_SPI();
    void global_blink(char duty, char period, unsigned int seq_R, unsigned int seq_G,
    	unsigned int seq_B, char blink_period);
    void latch_out(unsigned int seq_R, unsigned int seq_G, unsigned int seq_B);
    void pwm_config( unsigned char half_duty, unsigned char half_period);
    void special_conf(unsigned int config_code_R, unsigned int config_code_G,
    	unsigned int config_code_B);
    unsigned int special_err();
    void switch_mode(unsigned char mode);
    void default_prog();
    void prog_1();
    void prog_2();
    
    unsigned char b_state;						// Stores button press state
    
    void main()
    { 
      initialize_clk();							// Set up basic clk module
      WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
      P1OUT = 0x00;
      P2OUT = BIT1;								// Initialize OE' (LEDs off)
      P1DIR = BIT0 + BIT4;
      
      initialize_SPI();
      
      P1IE |= BIT3;								// Initialize P1.3(button) interrupt
      __bis_SR_register(GIE);
     
      __delay_cycles(75);                 		// Wait for LED driver to initialize
    
      default_prog();
    }
    
    /*
     * 	Function: PORT1_ISR
     *  Description: Interupts the processor to change the
     * 		the button press state. This changes the current
     * 		LED sequence program.
     *  Parameters: none
     *  Return: none
     */
    #pragma vector=PORT1_VECTOR
    __interrupt void PORT1_ISR(void)
    {
    	
    }
    
    unsigned char send_receive_pc(unsigned char send)
    {
      unsigned char receive;
      	
      TimerA_UART_init();
      receive = TimerA_UART_rx_tx(send);
      TimerA_UART_shutdown(); 
        
      return receive; 
    }
    
    void initialize_clk()
    {
      if (CALBC1_16MHZ == 0xFF || CALDCO_16MHZ == 0XFF) // Calibrate DCO at 16 MHz
      	while(1);										// 		DCO=MCLK=SMCLK
      BCSCTL1 = CALBC1_16MHZ;
      BCSCTL2 = DIVS_1;
      DCOCTL = CALDCO_16MHZ;  	
    }
    
    /*
     *  Function: initialize_SPI
     *  Description: Initializes module USCI_B0 in SPI 3 wire mode.  This
     * 		module is to be used to communicate with the TLC5927 LED drivers.
     * 		the module is set up to output to the SDI by send the LSB of a 16 
     * 		bit word first.
     *  Parameters: none
     *  Return: none
     */
     void initialize_SPI()
     {
      P1SEL = BIT5 + BIT6 + BIT7;				// setup SCLK = p1.5, SOMI = p1.6,  
      P1SEL2 = BIT5 + BIT6 + BIT7;				//		SIMO = P1.7
      UCB0CTL0 |= UCMST + UCSYNC;  				// 3-pin, 8-bit SPI master
      UCB0CTL1 |= UCSSEL_2;                     // SMCLK
      UCB0BR0 |= 0x01;                          // SMCLK/1
      UCB0BR1 = 0;
      UCB0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
     } 
     
     /*
     *  Function: global_blink
     *  Description: Execute rx/tx communication via SPI to force LED drivers
     * 		to blink particular channels.  The channels are on for half a 
     * 		periode with their specified PWM cycle, and off for the other half.
     *  Paramters: Pulse Width Modulation duty cycle in percent, and period
     * 		length. These paramters determine the dimming of the LEDs by 
     * 		providing The OE' pin on the TLC5927 with a dimming frequency.
     * 		d_num describes the driver on the EVM that will execute this mode.  
     * 		each driver also recieves a 16 bit sequence outlining the channels
     * 		that will be on/off.  The global blinking periode that will enable 
     * 		the device to switch between PWM and off.
     *  Return: 
     */
     void global_blink(char duty, char period, unsigned int seq_R, unsigned int seq_G,
     				  unsigned int seq_B, char blink_period)
     {
     	
     }
     
    /*
     *  Function: latch_out
     *  Description: This function latches on/off sequence to the output register, but
     * 		does not modify the OE' pin on the LED drivers, it also latches configuration 
     * 		code to the configuration code register.  Function should be executed
     * 		in normal mode or special mode to write 16 bit configuration code.
     *  Paramters: Each driver recieves a 16 bit sequence outlining the channels
     * 		that will be on/off.
     *  Return: 
     */
     void latch_out(unsigned int seq_R, unsigned int seq_G, unsigned int seq_B)
     {
     	 while (!(IFG2 & UCB0TXIFG));              // USCI_B0 TX buffer ready
     	 UCB0TXBUF = (char)seq_G;				   // TX OUT15 - OUT8 intructions for
     	 while (!(IFG2 & UCB0TXIFG)); 			   //	Green LED driver.  Lsb first.          
     	 UCB0TXBUF = (char)(seq_G >> 8);		   // Transmit OUT7-OUT0
     	 
     	 while (!(IFG2 & UCB0TXIFG));             
     	 UCB0TXBUF = (char)seq_R;
     	 while (!(IFG2 & UCB0TXIFG));             
     	 UCB0TXBUF = (char)(seq_R >> 8);
     	 
     	 while (!(IFG2 & UCB0TXIFG));              
     	 UCB0TXBUF = (char)seq_G;
     	 while (!(IFG2 & UCB0TXIFG));            
     	 UCB0TXBUF = (char)(seq_B >> 8);
     	 while (!(IFG2 & UCB0TXIFG)); 
     	 
     	 P1OUT |= BIT4;								// Pulse LE to store to output 
     	 _delay_cycles(1);							//	register.
     	 P1OUT &= ~BIT4;
     }
     
     /*
     *  Function: pwm_config
     *  Description: Utilizes timerA to produce a pwm output on the OE' pin
     * 		of the LED driver.  To be utilized in normal mode to choose dimm on
     * 		LEDs and to turn them on.
     *  Paramters: User provided 1/2 duty cycle and 1/2 period that the 
     * 		LEDs are to be turned off. 1/2 period must be less than 0xFFFF clock
     * 		cycles.  
     *  Return: none
     */
     void pwm_config( unsigned char half_duty, unsigned char half_period)
     {
      P2DIR |= BIT1;							//configure p1.2 for pwm out to OE'                            
      P2SEL |= BIT1;
    
      TA1CCR0 = half_period;        
      TA1CCTL1 = OUTMOD_6;                      // CCR1 toggle/set
      TA1CCR1 = half_period - half_duty;        // CCR1 PWM duty cycle
      TA1CTL = TASSEL_2 + MC_3;                 // SMCLK, up-down mode
     }
     
      /* NOTE: I may not need this function since latch_out does everything this does
     *  Function: special_mode
     *  Description: Execute rx/tx communication via SPI with TLC5927 to command the devices
     * 		to store a new current configuration code. See TLC5927 datasheet for 
     * 		switch description and protocol.
     *  Parameters: 16 bit current configuration code to be written to the current 
     * 		configuration latch.  Each driver on the EVM must be given a code even if no
     * 		change in current is desired.
     *  Return: none
     * */
    void special_conf(unsigned int config_code_R, unsigned int config_code_G,
     					unsigned int config_code_B)
    {
     	
    } 
    
    unsigned int special_err()
    {
    	/* period 0 */
     	P1OUT = OE;							  	 // Set OE' as high and set
     	P1SEL &= ~SCLK;						  	 // SCLK as regular output
     	P1SEL2 &= ~SCLK;						 // low slave clock
     	_delay_cycles(6);						 
     	
     	P1OUT |= SCLK;							 // high slave clock
     	_delay_cycles(6);
     	
     	/* period 1 */
     	P1OUT &= ~SCLK;  						 // low slave clock
     	_delay_cycles(3);
     	P1OUT &= ~OE;
     	_delay_cycles(3);
     	
     	P1OUT |= SCLK;							 // high slave clock
     	_delay_cycles(6);
     	
     	/* period 2 */
     	P1OUT &= ~SCLK;
     	_delay_cycles(6);
     	
     	P1OUT |= SCLK;
     	_delay_cycles(6);
     	
     	/* period 3 */
     	P1OUT &= ~SCLK;
     	_delay_cycles(6);
     	
     	P1OUT |= SCLK;
     	_delay_cycles(6);
     	
     	_delay_cycles(38);						  // delay > 2us for error code
     											  // 	to be written
     	/* Read Error Detection Code */
     	/* THIS MAY NOT WORK!!! */
     	P1OUT |= OE;	
     	UCB0TXBUF = 0x0000;
     	
     	return UCB0RXBUF;						
    }
     
      /*
     *  Function: switch_mode
     *  Description: MCU communication via LE and OE' pins of TLC5927 to command the devices
     * 		to engage in mode switching between special mode and normal mode.
     *  Parameters: mode = 0 to switch from normal to special mode, and mode = 1 to switch
     * 		from special mode to normal mode.
     *  Return: none
     */
     void switch_mode(unsigned char mode)
     {
     	/* period 1 */
     	P1OUT = OE;							  	 // Set OE' as high and set
     	P1SEL &= ~SCLK;						  	 // SCLK as regular output
     	P1SEL2 &= ~SCLK;						 // low slave clock
     	_delay_cycles(6);						 
     	
     	P1OUT |= SCLK;							 // high slave clock
     	_delay_cycles(6);
     	
     	/* period 2 */
     	P1OUT &= ~SCLK;  						 // low slave clock
     	_delay_cycles(3);
     	P1OUT &= ~OE;
     	_delay_cycles(3);
     	
     	P1OUT |= SCLK;							 // high slave clock
     	_delay_cycles(3);
     	P1OUT |= OE;
     	_delay_cycles(3);
     	
     	/* period 3 */
     	P1OUT &= ~SCLK;
     	_delay_cycles(6);
     	
     	P1OUT |= SCLK;
     	_delay_cycles(6);
     	
     	/* period 4 */
     	P1OUT &= ~SCLK;  						
     	_delay_cycles(3);
     	if (mode == 0)
     		P1OUT &= LE;
     	_delay_cycles(3);
     	
     	P1OUT |= SCLK;							
     	_delay_cycles(3);
     	if (mode == 0)							  // switch to special/normal
     		P1OUT |= ~LE;
     	_delay_cycles(3);
     	
     	/* period 5 */
     	P1OUT &= ~SCLK;
     	_delay_cycles(6);
     	
     	P1OUT |= SCLK;
     	_delay_cycles(6);
     	
     	P1OUT &= ~SCLK;							  // reset slave clk
     	_delay_cycles(6);		
     }
    
    /*
     *  Function: default_prog
     *  Description: run default led sequence out of the box
     *  Parameters: none
     *  Return: none
     */
    void default_prog()
    {
    	
    }
     
    /*
     *  Function: prog_1
     *  Description: Run LED sequence number 1
     *  Parameters: none
     *  Return: none
     */
    void prog_1()
    {
    	
    }
    
    /*
     *  Function: prog_2
     *  Discription: Run LED sequence number 2
     *  Return: none
     *  Parameters: none
     */
    void prog_2()
    {
    	
    }
    

    Please take it for reference.

    Regards,

    Kenneth

  • Hi Kenneth,

    Thank you very much for tracking down this example.  Not quite for the same part, but the concepts should help.

    I appreciate the effort!

    Scott