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.

MSP430FR6043: Unable to get SOMI data

Part Number: MSP430FR6043
Other Parts Discussed in Thread: EVM430-FR6043

Hello all,

I'm working on SPI protocol in msp430fr6043. I'm tried to interface with EEPROM 25lc040. 

I selected SCLK frequency is 800KHz and MOSI, CS is also working fine those signals are observed in the oscilloscope. But i'm unable to get SOMI data in the oscilloscope.

Please find the code below.

#include <msp430.h> 
#include "msp430fr6043.h"

void clock_init();
void gpio_init();
void spi_a1_init();
void uart_a1_init();
void write_enable();
unsigned char E_write(unsigned char ch);
unsigned char E_read();
void WR_data(unsigned char addr, unsigned char data);
unsigned char RD_data(unsigned char addr);


void clock_init()
{
    // Clock System Setup

    // Startup clock system with max DCO setting ~8MHz
        CSCTL0_H = CSKEY_H;                     // Unlock CS registers
        CSCTL1 = DCOFSEL_3 | DCORSEL;           // Set DCO to 1MHz
        CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK;
        CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1;   // Set all dividers
        CSCTL0_H = 0;                           // Lock CS registers

}

void gpio_init()
{
    // Configure GPIO

        //SCLK = 01 + ScLK set as output

        PJSEL1 &=~ BIT0;
        PJSEL0 |= BIT0;

        PJDIR |= BIT0;

        //MOSI = 01
        PJSEL1 &=~ BIT2;
        PJSEL0 |=  BIT2;

        //MISO = 01
        PJSEL1 &=~ BIT3;
        PJSEL0 |=  BIT3;

        // CS = P1.3        -----------------------------------------------------------------------
        P1OUT |= BIT3;          //P1.3 =1
        P1DIR |= BIT3;          //OUTPUT MODE
          //------------------------------------------------------------------------

       // Disable the GPIO power-on default high-impedance mode to activate
       // previously configured port settings
       PM5CTL0 &= ~LOCKLPM5;
}

void spi_a2_init()
{

        // Software reset
        UCA2CTLW0 = UCSWRST;                    // **Put state machine in reset**


        // CONFIGURE CTLWO
        UCA2CTLW0 |= UCSSEL__SMCLK;                         // Source for sclk is SMCLK
        UCA2BRW = 10;                                       // sclk = SMCLK/10 = 100 KHz

        // 3-PIN AND MASTER MODE
        UCA2CTLW0 |= UCSYNC;                                // Synchronous mode (i.e. SPI)
        UCA2CTLW0 |= UCMST;

        // CLOCK PHASE IS 1 (DATA CAPTURED FIRST )
        UCA2CTLW0 |= UCCKPH;

        //MSB FIRST
        UCA2CTLW0 |= UCMSB;

        // clear reset
        UCA2CTLW0 &=~ UCSWRST;


}

void uart_a1_init()
{
    // Software reset
    UCA1CTLW0 |= UCSWRST;

    //Source clock is SMCLK
    UCA1CTLW0 |= UCSSEL__SMCLK;

    // Baud rate calculated value
    UCA1BRW = 52;

    //Configure MCTLW
    UCA1MCTLW |= UCOS16 | UCBRF1 | 0X4900;

    //software reset clear
    UCA1CTLW0 &=~ UCSWRST;
}

unsigned char E_write(unsigned char ch)
{
    unsigned char rcv=0;

    UCA2TXBUF = ch;                                 // Send data in Txbuffer
    
    / This is added because suggestion from forum
    while(!(UCA2IFG & UCRXIFG));

    rcv=UCA2RXBUF;                                  // receive data
    return rcv;
}

void write_enable()
{
    P1OUT &=~ BIT3;                                // cs as gpio (p1.3) is clear

    E_write(0x06);                                  // To enable write latch

    P1OUT |= BIT3;                                  // cs as gpio (p1.3) is set
}

unsigned char E_read()
{
    unsigned char rcv2=0;

    UCA2TXBUF = 0XFF;                                 // Send dummy data
    while(!(UCA2IFG & UCTXIFG));                    // Wait until transmission is complete

    while(!(UCA2IFG & UCRXIFG));                    //wait until rxbuffer is filled with data
    rcv2 = UCA2RXBUF;                                // Store in a variable

    return rcv2;
}

void WR_data(unsigned char addr, unsigned char data)   // No need to return anything...
{
    unsigned char rcv=0;

    write_enable();                                 // Enable write latch

    P1OUT &=~ BIT3;                                // cs=0

    E_write(0x02);                                  // write instruction

    E_write(addr);                                  // send address byte

    E_write(data);                                  // send data byte

    P1OUT |= BIT3;                                  // cs=1

}

unsigned char RD_data(unsigned char addr)
{
    unsigned char rcv=0;

    write_enable();                                 // Enable write latch

    P1OUT &=~ BIT3;                               // cs=0

    E_write(0x03);                                  // Read instruction

    E_write(addr);                                  // send address byte

    rcv = E_read();                                 // store the received data

    P1OUT |= BIT3;

    return rcv;
}

void uart_char(unsigned char ch)
{
    while(!(UCA1IFG & UCTXIFG));
    UCA1TXBUF = ch;
}

void uart_string(unsigned char *data)
{
    unsigned char i=0;
    while(data[i])
    {
        uart_char(data[i]);
        i++;
    }
}

unsigned char msg = 0x5a;
unsigned char msg2=0;
unsigned char rcv_eeprom[4] = {0};


int main(void)
{
    unsigned int addr=0,i=0,k=0,j=0;

    // stop watchdog timer
	WDTCTL = WDTPW | WDTHOLD;
	
	// Initialize clock
	clock_init();

	// Initialize GPIO
	gpio_init();

	//Initialize SPI
	spi_a2_init();

    WR_data(addr, msg);

    __delay_cycles(1000);

        while(1)
        {
            msg2=RD_data(0);
            __delay_cycles(1000);
        }


    return 0;
}

 

I'm using 

1. MSP430-FR6043 microcontroller

2. MSP430 USB-Debug - Interface (MSP-FET430UIF) for programming.

Please guide me where I'm doing mistake.

Thanks,

Ashok.  

  • How do you tell that there's no SOMI data in the scope trace? Is it all-0? All-1?

    ----------------

    > __delay_cycles(1000);

    It looks like you're running at 8MHz (DCOFSEL=3,DCORSEL=1), so this is about 0.125msec, much less than tWC=5ms. I'm not sure what you get back if the data is in the midst of being written inside the EEPROM. Try:

    >  __delay_cycles(5*8000); // 5ms for tWC

    ----------------

    Are you debugging using SBW (2-wire) or JTAG (4-wire)? I expect the latter would conflict with using PJ for UCA2. (Can you use P5.0-2 instead?)

  • Hello Bruce,

    Thanks for the reply. 

    How do you tell that there's no SOMI data in the scope trace? Is it all-0? All-1?

    I'm not got the desired output.

    In the oscilloscope i got SOMI  data for first 8 clock pulses is 0x06, second eight clock pulses is 0x03, third eight clock pulses is 0x00 and forth eight clock pulses is 0xff is similar to MOSI data but compared to less amplitude than MOSI data around 0.8V.  But the excepted output is 0x5a.

    __delay_cycles(5*8000); // 5ms for tWC

    I tried but still i got same result

    Are you debugging using SBW (2-wire) or JTAG (4-wire)? I expect the latter would conflict with using PJ for UCA2. (Can you use P5.0-2 instead?)

    In EVM430-FR6043 have only single SPI supporrted pins (i.e. PORT J pins) and no other ports to test.

    Port J pins is also multipled with JTAG signals like TDO, TDI,TMS, TCK. while debugging I got some undesired MOSI output . So i test SPI signals without debugging mode then i got desired MOSI data. 

    I observed that the chip select in microcontroller is works good when i tested in oscilloscope but when i connected to eeprom the amplitude is in millli volts. So i replaced with another female to female jumper wire to connect the both microcontroller and eeprom still the result. whether it is related to hardware issue?

    Thanks,

    Ashok. 

  • This really sounds electrical, like a bus conflict. Things I would check for:

    1) SIMO and SOMI are crossed/shorted somehow, and when the EEPROM starts to drive the bus you see a "middle-sized" voltage result.

    2) The EEPROM isn't properly powered, so you're (inadvertently) powering that chip with the SPI wires.

**Attention** This is a public forum