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.

Port mapping on MSP430F6736

Other Parts Discussed in Thread: EVM430-F6736, MSP430F6736

Hello Everybody

I would appreciate it very much if someone could help me with the following problem:

My task is to incorporate an SD card (SPI mode) to the EVM430-F6736 Single-Phase Watt-Hour Meter (Application Report SLAA517) using software described in Application Report SLAA281.

After going through the labyrinth of #defines and #includes of the Application Reports, I concluded that I do not know how to enable the 3-pin SPI secondary function that is available in pins P1.7, P2.0 and P2.1 (PM_UCB0CLK, PM_UCB0SOMI and PM_UCB0SIMO respectively) of the MSP430F6736.

To simplify the description of the problem, the code I am using to enable the SPI function in the F6736 is equivalent to the one listed bellow.
I am monitoring pins PM_UCB0CLK and PM_UCB0SIMO with an oscilloscope, and there is simply NO ACTIVITY at all. What is wrong?

Thanks

Claudio R. Sonnenburg


#include <stdio.h>
#include <msp430f6736.h>

int main( void )
{
WDTCTL = WDTPW + WDTHOLD;

// CLOCK and SIMO (P1.7, P2.1) are outputs
P2OUT |= BIT1;
P2DIR |= BIT1; // SIMO
P1OUT |= BIT7;
P1DIR |= BIT7; // CLOCK

// Enable secondary functions of pins P1.7, P2.0 and P2.1
P1SEL |= BIT7; // SPI CLOCK
P2SEL |= BIT0 + BIT1; // SOMI and SIMO

// enable port mapping
PMAPPWD = 0x02D52;
PMAPCTL |= PMAPRECFG;

// port mapping for eUSCI_B0 SPI default secondary function
P2MAP0 = PM_UCB0SOMI;
P2MAP1 = PM_UCB0SIMO;
P1MAP7 = PM_UCB0CLK;

// Enable secondary functions of pins P1.7, P2.0 and P2.1
//P1SEL |= BIT7; // SPI CLOCK
//P2SEL |= BIT0 + BIT1; // SOMI and SIMO

// Init SPI Module
UCB0CTL1 = UCSWRST;
UCB0CTL1 |= UCSSEL_2; // SMCLK
UCB0CTL0 = UCMST+UCCKPL+UCMSB+UCSYNC; // 3-pin, 8-bit SPI master
UCB0BR1 = 0;
UCB0BR0 |= 0x40; // UCLK/64
UCB0CTL1 &= ~UCSWRST;

for(int z=0;z<=9;z++)
{
while((UCB0IFG & UCTXIFG) == 0); // hold till TX gets empty
UCB0TXBUF = 0xff; // send byte
}
}

  • The port pins you want to have SPI are default mapped for it, which means you only have to SEL them. This you can remove;

    Claudio Sonnenburg said:
    // CLOCK and SIMO (P1.7, P2.1) are outputs
    P2OUT |= BIT1;
    P2DIR |= BIT1; // SIMO
    P1OUT |= BIT7;
    P1DIR |= BIT7; // CLOCK

    Claudio Sonnenburg said:
    // enable port mapping
    PMAPPWD = 0x02D52;
    PMAPCTL |= PMAPRECFG;

    // port mapping for eUSCI_B0 SPI default secondary function
    P2MAP0 = PM_UCB0SOMI;
    P2MAP1 = PM_UCB0SIMO;
    P1MAP7 = PM_UCB0CLK;

  • Hi Leo

    Thanks for your advice.
    Sorry to say that the behavior of my setup is still not OK.
    With the following code, I still do not see any activity on pins
    P1.7 (clock) or P2.1 (simo).

    #include <stdio.h>
    #include <msp430f6736.h>

    int main( void )
    {
    WDTCTL = WDTPW + WDTHOLD;

    P1SEL |= BIT7; //SPI CLOCK
    P2SEL |= BIT0 + BIT1; // SOMI and SIMO

    // Init SPI Module
    UCB0CTL1 = UCSWRST;
    UCB0CTL1 |= UCSSEL_2; // SMCLK
    UCB0CTL0 = UCMST+UCCKPL+UCMSB+UCSYNC; // 3-pin, 8-bit SPI master
    UCB0BR1 = 0;
    UCB0BR0 = 0x40; // UCLK/64
    UCB0CTL1 &= ~UCSWRST;

    for(int z=0;z<=9;z++)
    {
    while((UCB0IFG & UCTXIFG) == 0); // hold till TX gets empty
    UCB0TXBUF = 0xff; // send byte
    }
    }

    Would you have any additional advice?

    Regards

    Claudio R. Sonnenburg

  • Claudio,

    I took the USCI_A0 SPI example and modified it for USCI_B0, and the following code works for me:

    #include <msp430.h>
    
    int main(void)
    {
    	unsigned char data;
    
        WDTCTL = WDTPW | WDTHOLD;                     // Stop WDT
    
        // Setup P2.0 UCB0SOMI, P2.1 UCB0SIMO, P1.7 UCB0CLK
        P1SEL |= BIT7;
        P2SEL |= BIT0 + BIT1;
    
        // Setup USCI_B0
        UCB0CTLW0 |= UCSWRST;                         // **Put state machine in reset**
        UCB0CTLW0 |= UCMST | UCSYNC | UCCKPL | UCMSB; // 3-pin, 8-bit SPI master
                                                      // Clock polarity high, MSB
        UCB0CTLW0 |= UCSSEL_2;                        // SMCLK
        UCB0BRW_L = 0x02;                             // /2
        UCB0BRW_H = 0;                                //
        UCB0CTLW0 &= ~UCSWRST;                        // **Initialize USCI state machine**
    
        __delay_cycles(100);                          // Wait for slave to initialize
    
        for(;;)
        {
    		while (!(UCB0IFG & UCTXIFG)) ;            // USCI_A0 TX buffer ready?
    		UCB0TXBUF = 0xA5;                         // Transmit first character
    
    		while (!(UCB0IFG & UCRXIFG)) ;            // USCI_A0 RX buffer full?
    		data = UCB0RXBUF;
    
    		__delay_cycles(1000);
        }
    }
    

    Could you give it a try?

  • Hi Leo

    Thanks for your advice.

    Now my software is working OK.

    The error was that I refered to the USCI_B0 control registers as UCB0CTL0 and UCB0CTL1,

    which I took from reference SLAU208N (pg's 939-940),

    and the correct form is just UCB0CTLW0.

    Thanks again.

    Claudio

  • Claudio Sonnenburg said:
    The error was that I refered to the USCI_B0 control registers as UCB0CTL0 and UCB0CTL1, [...]and the correct form is just UCB0CTLW0.

    You can use both ways. However, when accessing them as single word, you need of course to use other bit definitions for the high-byte then when using them as separate byte registers. (and I think there are different definitions available).
    On other modules, there are _L and _H register names.
    I fear that someone has messed-up the header files (in Germany, we say ‘verschlimmbessern’: improving it into something worse), so that the previous definitions for two 8 bit registers have silently changed into 16 bit definitions for the combined register.
    I just checked my headers for MSPGCC and there the defines are for using UCB0CRL0/1 and not for W0.

  • Hi Jens-Michael

    Thanks for the information.

    Regards

    Claudio

**Attention** This is a public forum