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.

SPI "Dual" MODE in the same bus.

Hi Forum! I've a problem with two spi devices.

I need connect both devices in the same spi bus (USART1 alt 1, so i had to move USART0 to alt2 to avoid conflicts).

The problem is that both devices have different spi modes to work. The polarity and clock phase of the serial clock SCK is selected
by UxGCR.CPOL and UxGCR.CPHA. So i need to switch between SPI MODE 0 (where CPOL and CPHA are zeros) and SPI MODE 3
(where CPOL and CPHA are ones) alternating modes of the spi.

So i did the following:

SPI_SET_M0();
rtcInit(); // initializes RTC (SPI MODE 0)
SPI_SET_M3();
expanderInit(); // initializes the another device (SPI MODE 3)

------
Macros

#define SPI_SET_M0() st(U1CSR &= 0xBF; U1GCR &= 0x3F; U1CSR |= 0x40;)
#define SPI_SET_M3() st(U1CSR &= 0xBF; U1GCR |= 0xC0; U1CSR |= 0x40;)
-----

#define SPI_INIT() \
st( \
/* Mode select UART1 SPI Mode as master. */\
U1CSR = 0; \
\
/* Setup for 480.5kHz (max 500kHz). */\
U1GCR = 0x0D; \
U1BAUD = 0xEC; \
\
/* Set U1GCR SPI Mode3 and bit order to MSB */\
/*U1GCR |= 0xE0; \*/\
U1GCR |= 0xE0; \
\
/* Set UART0 I/O to alternate 2 location on P1 pins.
Set UART1 I/O to alternate 1 location on P0 pins */\
PERCFG &= 0xFD;\
PERCFG |= 0x01;\
\
/* Select peripheral function on I/O pins but SS is left as GPIO for separate control. */\
P0SEL |= 0x38; \
P0DIR = 0xDD;\
P0 |= 0xFF;\
/* When SPI config is complete, enable it. */\
U1CSR |= 0x40; \
)

This last macro is called at first of all...

This does not work well. Is it possible to switch modes in runtime execution spi?

I clarify that the spi devices are accessed through polling, do not use SPI interrupts.

Is it possible switch spi modes in runtime execution? 

Thanks!

  • Hi Martin,

    I believe you may have posted your query in the wrong forum.  I'll move it over to the Low Power RF team for you.

  • Hi,

    martinromero said:
    Is it possible switch spi modes in runtime execution? 

    Read the CC253x/4x User's Guide, it's all written there. I see no reason why it should be

    impossible to reconfigure SPI, however I think it should be done only when SPI is idle.
     

    From my own experience the problem is wrong configuration of register/s

  • Did you get this figured out?  I am having an issue even getting a single device to work correctly over SPI.  Mostly, I need SPI Mode 3 as well, but not clear if setting CPOL and CPHA bits to 1 are the same as CPOL=1 and CPHA=1.  The user guide specifies CPOL as negative or positive polarity but not sure if that means the clock idles low or idles high respectively.