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.

MSP430F67791: SPI not working.

Part Number: MSP430F67791
Other Parts Discussed in Thread: MSP430WARE

Hi everyone,

          Now i have MSP430F67791 interface the W25q64 winbond chip.But communication is not working.what happened?

This is my following code details,

interface pin details for your reference,

SCLK  P3.3   SCK 
SOMI  P3.4    DO
SIMO  P3.5    DI
CS      P3.6    CS

void spi_init(void)
{
UCA1CTL1 = UCSWRST;

P3OUT &= ~BIT6;                      // Clear P1.0
P3DIR |= BIT6;                           // Set P1.0 to output direction
P3SEL0 = BIT3| BIT4 | BIT5 ;    // Set P3.0,P3.1,P3.2 to non-IO


UCA1CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC; 
UCA1CTL1 |= UCSSEL_2; // SMCLK

UCA1BR0 |= 0x02;
UCA1BR1 = 0x00;
UCA1MCTLW = 0;


UCA1CTL1 &= ~UCSWRST;

}

void spi_chipHigh(void)
{
P3OUT |= CS;
}

void spi_chipLow(void)
{
P3OUT &= ~CS;
}

int datacount=0;

unsigned char data=0;

unsigned char GCu_Tx_Data[10];
unsigned char GCu_Recieved_Data[10];

uint8_t sFLASH_SendByte(unsigned char *uData,unsigned char count)
{
while(!(UCA1IFG &= UCTXIFG));

for(datacount=0;datacount<count;datacount++)

UCA1TXBUF = uData[datacount];


while (!(UCA1IFG & UCRXIFG));

uData[0] = UCA1RXBUF;

return *uData;

}

unsigned char Read_SingleBytes(unsigned int LIu_Flash_Add){
unsigned char LCu_Read_Data=0;
spi_chipLow(); 
GCu_Tx_Data[0] = 0x03;                                           //read 
GCu_Tx_Data[1] = (LIu_Flash_Add >> 16) & 0xFF;
GCu_Tx_Data[2] = (LIu_Flash_Add >> 8) & 0xFF;
GCu_Tx_Data[3] = (LIu_Flash_Add >> 0) & 0xFF; 
LCu_Read_Data=sFLASH_SendByte(&GCu_Tx_Data[0],4);
spi_chipHigh();

return(LCu_Read_Data);
}

while(1)

{

Read_SingleBytes(0x000000);

}

If any coding issue pls tell me the exact reason and how to work properly guide me as soon as possible.Pls check the SPI init function this init register deatils are correct or not.And also check the whole program details and guide me the issue as soon as possible.

  • Part Number: MSP430F67791

    Hi Everyone,

                    Now i have MSP430F67791 interface with W25Q64FV winbond flash memory.Now i have read data from memory 10 bytes.

    But Now i have read only one byte using this UCA1RXBUF.How to read 10 bytes from memory using this register UCA1RXBUF.

    Pls give me some example for this issue.

  • Hi Ashokkumar,

    I recommend looking into the code examples provided in MSP430Ware. More specifically, the code example linked below should be a good starting place:

    http://dev.ti.com/tirex/#/?link=Software%2FMSP430Ware%2FDevices%2FMSP430F5XX_6XX%2FMSP430F67791A%2FPeripheral%20Examples%2FRegister%20Level%2Fmsp430f677xA_uscia0_spi_09.c

    Additionally, I recommend reading through the General and SPI sections of Solutions to Common eUSCI and USCI Serial Communication Issues on MSP430 MCUs. After reviewing these, please let me know if you need any further assistance.

    Best regards, 
    Caleb Overbay

  • I think you're mostly there. Just fetch RXBUF inside the loop, something like:

    for(datacount=0;datacount<count;datacount++) {
       UCA1TXBUF = uData[datacount];
       while (!(UCA1IFG & UCRXIFG));
       uData[datacount] = UCA1RXBUF;
    }

    Then, in the caller, just extend the buffer to the length (+4) you want. This will overwrite the Tx buffer, but you're already doing that at least partially.
    ----------------------------------------------------------
    Also, I don't recommend this:
    > while(!(UCA1IFG &= UCTXIFG));
    Try instead:
    > while(!(UCA1IFG & UCTXIFG));

  • uint8_t sFLASH_SendByte(unsigned char *uData,unsigned char count)
    {

    while(!(UCA1IFG & UCTXIFG));
    UCA1IFG &=~UCRXIFG;                  // Clear Rx interrupt flag
    for(datacount=0;datacount<count;datacount++)
    UCA1TXBUF = uData[datacount];    // Transmit data
    // Wait for transfer to complete
    while (!(UCA1IFG & UCRXIFG));
    *uData = UCA1RXBUF;
    return *uData;
    }

    In this case most time UCA1RXBUF dont read the data what happened?As soon as possible.But UCA1IFG=0x000002 and UCRXIFG=0x000001 shows that values.pls do the needful.

  • uint8_t sFLASH_SendByte(unsigned char *uData,unsigned char count)
    {

    while(!(UCA1IFG & UCTXIFG));
    UCA1IFG &=~UCRXIFG; // Clear Rx interrupt flag
    for(datacount=0;datacount<count;datacount++)
    UCA1TXBUF = uData[datacount]; // Transmit data
    // Wait for transfer to complete
    while (!(UCA1IFG & UCRXIFG));
    *uData = UCA1RXBUF;
    return *uData;
    }

    In this case most time UCA1RXBUF dont read the data what happened?As soon as possible.But UCA1IFG=0x000002 and UCRXIFG=0x000001 shows that values.pls do the needful.
  • Part Number: MSP430F67791

    Hi Everyone,

                   Now i have read two byte data from WINBOND Flash via MSP430F67791.In MSP430F67791 SPI mode use for Communication purpose read and write.Now read data from flash,Data is available in UCA1RXBUF.In this only one data is available.So how to read another one data from UCA1RXBUF.

    uint8_t sFLASH_SendByte(unsigned char *uData,unsigned char count)
    {

    // Clear Rx interrupt flag
    while(!(UCA1IFG & UCTXIFG));
    UCA1IFG &=~UCRXIFG;
    for(datacount=0;datacount<count;datacount++)
    // Transmit data
    UCA1TXBUF = uData[datacount];
    // Wait for transfer to complete
    while ((UCRXIFG==0));
    // Receive data
    *uData = UCA1RXBUF;

    return *uData;
    }  How to read one more data.As soon as possible.

  • Hi ashok,
    msp430 RX buffer is of 1 byte so whenever a new byte is received it will over right the previous byte.

    and SPI is BI directional means . when you send something you will also receive something and in order to receive something you have to send some dummy byte.

    suppose your command is of 1 byte and expected response is of 2 byte so your flow should be like below.

    SENDING
    >> Send one byte command
    >> you will receive a dummy byte.

    RECEIVING
    now in order to read the 2 byte response of command you have to send two dummy bytes.
    >> send first dummy byte
    >> you will receive your first byte of response

    >> send second dummy byte
    >> you will receive your second byte of response.
  • RXIFG is set after every byte you send, so the one you are testing is (almost) always stale.

    The code I suggested does not have this flaw, since it clears RXIFG after each byte.
  • Hi,

    Lot of thanks code is now working fine.

  • Part Number: MSP430F67791

    Hi Everyone,

                        Now i have working MSP430F67791 interface with W25Q64FV winbond flash.Winbond Flash operating range is 108MHz.Now Flash memory is working fine.My question is how to calaculate SPI speed configuartion for MSP430F67791 with W25Q64FV.

    My SPI Init Function is below for your reference,

    /*
    SCLK  P3.3     SCK
    SOMI  P3.4     MO
    SIMO  P3.5     MI
    CS      P3.6      CS
    */

    MSP430 crystal frq:32.768KHz

    void SPI_Init(void){

    UCA1CTLW0 |= UCSWRST;


    P3OUT &= ~BIT6;                    // Clear 
    P3DIR |= BIT6;                         // Set 

    P3SEL0 = BIT3| BIT4 | BIT5 ;  // Set 



    UCA1CTLW0 |= UCSWRST;                                                   // **Put state machine in reset**
    UCA1CTLW0 |= UCMST | UCSYNC | UCCKPL | UCMSB;    // 3-pin, 8-bit SPI master,Clock polarity high, MSB

    UCA1CTLW0 |= UCSSEL_2;                                                  // SMCLK
    UCA1BRW_L = 0x02;                                                             // 2
    UCA1BRW_H = 0;                                                                  //
    UCA1MCTLW = 0;                                                                  // No modulation
    UCA1CTLW0 &= ~UCSWRST;                                              // **Initialize USCI state machine**

    }

    How to calculate SPI speed for MSP430F67791 and Q25W64FV flash.Pls explain and tell me the exact calculation details as soon as possible.

  • Hi Ashokkumar,

    I've been merging all you're new SPI posts back to this thread so all your questions related to this topic are in one post. If you continue to have questions regarding this issue, please post in this thread.

    I recommend looking at section 40.3.6 of the MSP430x5xx and MSP430x6xx Family User's Guide for a description of how to set the USCI SPI clk to your desired frequency. Then please look into section 4.2 "Calculating the Maximum SPI Communication Speed" of Solutions to Common eUSCI and USCI Serial Communication Issues on MSP430 MCUs for an explanation of how to calculate the max speed you can run SPI at between these two devices.

    Best regards,
    Caleb Overbay

**Attention** This is a public forum