Jump to content
43oh

MSP430 + 74HC595 trouble


Recommended Posts

Hi everyone,

I'm using msp430g2553 to interface with 74hc595.

Below is config and flash bit function

void SPI_CFG(){
	UCB0CTL1 |= UCSWRST;
	// setup UCB0
	P1SEL |= SCLK_PIN + MOSI_PIN; // pins 5 + 7
	P1SEL2 |= SCLK_PIN + MOSI_PIN; // UCB0CLK + UCB0SIMO
	UCB0CTL0 = UCCKPL+UCMST + UCSYNC; // data captured on 1st UCLK edge/changed on follwing edge, MSB first, master, 3-pin SPI,synchronous
	UCB0CTL0 &= ~(UCCKPH);

	UCB0CTL1 |= UCSSEL_2; // SMCLK
	UCB0BR0 |= 0x01; // 1:1
	UCB0BR1 = 0;
	UCB0CTL1 &= ~UCSWRST; // clear SW
}
void WriteData(unsigned char data) //SPI
{
    P2OUT |= LATCH_BIT;
    while(UCB0STAT & UCBUSY);             // wait for all to finish
    UCB0TXBUF = data; // Transmit first character
    P2OUT &= ~LATCH_BIT;
}

After debugged, I realized that the slave (74hc595) can not receive data at the first time.

From the second time is fine.

It's took me a lot of time, but I can not figure out my mistake.

Can anyone help to explain and fix my bug?.

 

Thanks in advanced!

 

Link to post
Share on other sites

Wait for transmission of all bits to complete before latching the outputs

 

void WriteData(unsigned char data) //SPI
{
    UCB0TXBUF = data;                // Transmit character
    while(UCB0STAT & UCBUSY);        // Wait for all bits to finish
    P2OUT |= LATCH_BIT;              // Pulse latch
    P2OUT &= ~LATCH_BIT;
}

 

 

You're solution should work. But less about waiting for the transmission to finish (while still important). The 74xx595 will latch it's outputs on the RISING edge. The original code assumes it is latching on the FALLING edge.

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...