Jump to content
43oh

TLC5940 with MSP430G2553 wiring schematic


Recommended Posts

so I tried to connect the TLC5940 to the MSP430G2553 like this and I used this code:

 
#include <msp430g2553.h>
 
#define SCLK_PIN BIT5
#define MOSI_PIN BIT7
#define GSCLK_PIN BIT4
#define BLANK_PIN BITC
#define XLAT_PIN BITB
 
typedef unsigned char u_char;
 
u_char leds[16] = { 0, };
 
void updateTLC();
 
void main(void) {
 
    WDTCTL = WDTPW + WDTHOLD; // disable WDT
    BCSCTL1 = CALBC1_16MHZ; // 16MHz clock
    DCOCTL = CALDCO_16MHZ;
 
    P1OUT &= ~(BLANK_PIN + XLAT_PIN);
    P1DIR |= BLANK_PIN + XLAT_PIN;
 
    P1DIR |= GSCLK_PIN; // port 1.4 configured as SMCLK out
    P1SEL |= GSCLK_PIN;
 
    // setup timer
    CCR0 = 0xFFF;
    TACTL = TASSEL_2 + MC_1 + ID_0; // SMCLK, up mode, 1:1
    CCTL0 = CCIE; // CCR0 interrupt enabled
 
    // setup UCB0
    P1SEL |= SCLK_PIN + MOSI_PIN;
    P1SEL2 |= SCLK_PIN + MOSI_PIN;
 
    UCB0CTL0 = UCCKPH + UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
    UCB0CTL1 |= UCSSEL_2; // SMCLK
    UCB0BR0 |= 0x01; // 1:1
    UCB0BR1 = 0;
    UCB0CTL1 &= ~UCSWRST; // clear SW
 
    updateTLC();
    P1OUT |= XLAT_PIN;
    P1OUT &= ~XLAT_PIN;
 
    _bis_SR_register(GIE);
 
    leds[0] = 0x0F;
    u_char counter = 0;
    u_char direction = 0;
    while (1) {
        _delay_cycles(500000);
        if (direction) {
            counter--;
            leds[counter] = 0x0F;
            leds[counter + 1] = 0;
            if (counter == 0)
                direction = 0;
        } else {
            counter++;
            leds[counter] = 0x0F;
            leds[counter - 1] = 0;
            if (counter == 15)
                direction = 1;
        }
    }
}
 
void updateTLC() {
 
    u_char ledCounter = 8;
 
    while (ledCounter-- > 0) {
 
        UCB0TXBUF = leds[(ledCounter << 1) + 1] << 4;
        while (!(IFG2 & UCB0TXIFG))
            ; // TX buffer ready?
 
        UCB0TXBUF = leds[ledCounter << 1];
        while (!(IFG2 & UCB0TXIFG))
            ; // TX buffer ready?
 
        UCB0TXBUF = 0;
        while (!(IFG2 & UCB0TXIFG))
            ; // TX buffer ready?
    }
}
 
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A0(void) {
    P1OUT |= BLANK_PIN;
    P1OUT |= XLAT_PIN;
    P1OUT &= ~XLAT_PIN;
    P1OUT &= ~BLANK_PIN;
    updateTLC();
}
 
The LEDS are all flickering, what am I doing wrong?

 

 

post-38286-0-12111700-1409994108_thumb.png

Link to post
Share on other sites

@@EddieM, try this.

 

C1 & C2 should be as close as possible to Vcc pins.

C3 is not necessary if you don't do in circuit programming.

R2 value is for 10mA current.

DCPRG & VPRG is grounded, so if you want to do more with TLC, you will have to connect them to P1.0 & P2.0

 

If you connect your TLC to LaunchPad, do not use C2, C3, & R3.

#include
 
#define SCLK_PIN BIT5
#define MOSI_PIN BIT7
 
#define GSCLK_PIN BIT4
#define BLANK_PIN BIT2
#define XLAT_PIN BIT1
 
typedef unsigned char u_char;
 
u_char leds[16] = { 0, };
 
void updateTLC();
 
void main(void) {
 
    WDTCTL = WDTPW + WDTHOLD; // disable WDT
    BCSCTL1 = CALBC1_16MHZ; // 16MHz clock
    DCOCTL = CALDCO_16MHZ;
 
    P2OUT &= ~(BLANK_PIN + XLAT_PIN);
    P2DIR |= BLANK_PIN + XLAT_PIN;
 
    P1DIR |= GSCLK_PIN; // port 1.4 configured as SMCLK out
    P1SEL |= GSCLK_PIN;
 
    // setup timer
    CCR0 = 0xFFF;
    TACTL = TASSEL_2 + MC_1 + ID_0; // SMCLK, up mode, 1:1
    CCTL0 = CCIE; // CCR0 interrupt enabled
 
    // setup UCB0
    P1SEL |= SCLK_PIN + MOSI_PIN;
    P1SEL2 |= SCLK_PIN + MOSI_PIN;
 
    UCB0CTL0 = UCCKPH + UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
    UCB0CTL1 |= UCSSEL_2; // SMCLK
    UCB0BR0 |= 0x01; // 1:1
    UCB0BR1 = 0;
    UCB0CTL1 &= ~UCSWRST; // clear SW
 
    updateTLC();
    P2OUT |= XLAT_PIN;
    P2OUT &= ~XLAT_PIN;
 
    _bis_SR_register(GIE);
 
    leds[0] = 0x0F;
    u_char counter = 0;
    u_char direction = 0;
    while (1) {
        _delay_cycles(500000);
        if (direction) {
            counter--;
            leds[counter] = 0x0F;
            leds[counter + 1] = 0;
            if (counter == 0)
                direction = 0;
        } else {
            counter++;
            leds[counter] = 0x0F;
            leds[counter - 1] = 0;
            if (counter == 15)
                direction = 1;
        }
    }
}
 
void updateTLC() {
 
    u_char ledCounter = 8;
 
    while (ledCounter-- > 0) {
 
        UCB0TXBUF = leds[(ledCounter << 1) + 1] << 4;
        while (!(IFG2 & UCB0TXIFG))
            ; // TX buffer ready?
 
        UCB0TXBUF = leds[ledCounter << 1];
        while (!(IFG2 & UCB0TXIFG))
            ; // TX buffer ready?
 
        UCB0TXBUF = 0;
        while (!(IFG2 & UCB0TXIFG))
            ; // TX buffer ready?
    }
}
 
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A0(void) {
    P2OUT |= BLANK_PIN;
    P2OUT |= XLAT_PIN;
    P2OUT &= ~XLAT_PIN;
    P2OUT &= ~BLANK_PIN;
    updateTLC();
}

post-73-0-68450600-1410002247_thumb.png

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...