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.

MSP430F6638: Port mappping(UCB0 I2C/SPI) during runtime on MSP430f6638

Part Number: MSP430F6638

Hi

I've been trying set-up and use I2C and SPI using UCB0 on Port2. The intention is to switch between the two of them during runtime.

The issue I'm facing is that I cannot get the SPI to work after I have enabled I2C(SPI works if do not map the I2C to Port2.) - it seem like the port mapping is creating the issue but I not entirely sure(I've looked in errate and couldn't find any known related issue). 

What I do: I reset the module and clear the state of the port pins, in between, before switching to SPI. 

First I set up ports directions, state and so and then i do port mapping. When that is done I initialize the UCB0 for either SPI or I2C including relevant settings and enable the module(UCB0CTL1 &= ~UCSWRST)

I'm wondering if its something with UCBOCLK and UCB0SCL as they are essential the same?

Below is a snippet of how the mapping is done? Is there something I misunderstand in regards to mapping during runtime??

*////////////////////// Mapping SPI to PORT2.x*/////////////
__disable_interrupt();
PMAPPWD = 0x02D52; // Mapping SPI to PORT2.x
P2MAP0 = PM_UCB0CLK;
P2MAP1 = PM_UCB0SOMI;
P2MAP2 = PM_UCB0SIMO;
P2MAP3 = PM_NONE;
P2MAP4 = PM_NONE;
PMAPPWD = 0;
__enable_interrupt();


*////////////////////// Mapping I2C to PORT2.x*/////////////
__disable_interrupt();
PMAPPWD = 0x02D52; // Mapping I2C to PORT2.x
P2MAP0 = PM_NONE;
P2MAP1 = PM_NONE;
P2MAP2 = PM_NONE;
P2MAP3 = PM_UCB0SDA;
P2MAP4 = PM_UCB0SCL;
PMAPPWD = 0;
__enable_interrupt();

Br MM

  • HI again

    I was missing PMAPRECFG from intial post.

    I will check tonight but It might be that I somehow corrupt the setting of this only allowing to map once.

    __disable_interrupt();
    PMAPPWD = 0x02D52; // Mapping I2C to PORT2.x

    PMAPCTL = PMAPRECFG;

    P2MAP0 = PM_NONE;
    P2MAP1 = PM_NONE;
    P2MAP2 = PM_NONE;
    P2MAP3 = PM_UCB0SDA;
    P2MAP4 = PM_UCB0SCL;
    PMAPPWD = 0;
    __enable_interrupt();

  • Yes, forgetting to set PMAPRECFG was my first guess as well. 

    It might be judicious to do the re-maps in an order which first removes the current mappings, and only then sets the new mappings.

    Let us know how it turns out.

  • Thanks for your feedback. Sadly it didn't change the behaviour and it was actually already implemented. I do reset the bit so it should be configurable during runtime? but seems not. I will try to see if clk actually hangs on the port defined for scl.

    I agree with you but I use both SPI and I2C on port2 but using different portpins. I think as a bare min. I have to reconfigure SCL and CLK when shifting between SPI and I2C comm. on UCB0.

    As a next step I will take a look at the Psel definies in my code once more.

  • What I was suggesting was re-ordering the statements such that all the PM_NONE settings come first. The idea is to avoid having the USCI see both sets of pins simultaneously.

    It also might be "cheap insurance" to set PMAPRECFG on every transition. Yes, the verbiage in the UG says only the first time is required; I believe (almost) everything I read in The Book.

  • Hmm, I figured out what going on with the mapping.

    I didn't define PORT_MAP_RECFG!!! I figured it out as the PMAPRECFG bit in PMAPCTL reg was never set.

    I'm still having issues with the SPI module not working after I2C has been init the first time. At least now the first problem has been solved. The second problem might be related to the I2C/USB0 changing port settings when it enabled. Tonight I hopefully solve that matter so I can get going. I'll get back when solved.

  • Solved!! The issue was much easier to locate than the mapping part. I forgot to change(clear) UCB0BR0/1 - dohh.

    Was previously set for I2C and didn't match with SPI setup.

    For other. I had the following in my portmapping which orginates from TI examples.

    As i didn't define PORT_MAP_RECFG the preprocessor excludes the "PMAPCTL = PMAPRECFG" and therefore not compiled!!  

    #ifdef PORT_MAP_RECFG
    // Allow reconfiguration during runtime
    PMAPCTL = PMAPRECFG;
    #endif

  • I'm glad you got it working.

    I'm not familiar with the symbol PORT_MAP_RECFG. What code uses this?

  • I didn't knew either. I thought it was somehow defined in msp430io.h header files but I was wrong and the compiler does not complain due to the #Ifdef statement.

    I snatch the piece of code from an TI example and I should have investigate the meaning of each line in depth; shame on me!!

    Two thing that I could do to make it work. 1) either define PORT_MAP_RECFG in my header file or 2)Delete those lines.

    I really do not know what the intention is with that piece of code/ statement

    I'm running IAR but I'm not sure how the CCS preprocessor/compiler behaves in respect to this statement.

**Attention** This is a public forum