MSPLife 2 Posted November 21, 2015 Share Posted November 21, 2015 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! Quote Link to post Share on other sites
oPossum 1,083 Posted November 22, 2015 Share Posted November 22, 2015 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; } MSPLife 1 Quote Link to post Share on other sites
greeeg 460 Posted November 22, 2015 Share Posted November 22, 2015 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. MSPLife 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.