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.

CC2540 SPI Communication configuration help request

Other Parts Discussed in Thread: CC2540

Hi. I am trying to get the CC2540 able to communicate with an arduino, and for that I need SPI communication.

I have looked at various posts on this forum, but they didn't really help me much. The biggest breadcrumb was this thread

http://e2e.ti.com/support/low_power_rf/f/538/t/105727.aspx

It seems fairly straightforward the way the code works, but I can't figure out how to find the right pins. I am currently using the CC2540 on an OLP425 breakout board from ConnectBlue. The relevant pin layout is here:

http://support.connectblue.com/display/PRODBTSPA/cB-OLx425+Electrical+Mechanical+Data+Sheet#cB-OLx425ElectricalMechanicalDataSheet-PinDescription

To save you some reading, here it states that the uart pins I aim to use are:

CC2540 pin 14 / Port name P0_5 = SPI-CLK
CC2540 pin 15 / Port name P0_4 = SPI-CS

CC2540 pin 16 / Port name P0_3 = SPI-MOSI
CC2540 pin 17 / Port name P0_2 = SPI-MISO 

So the way I figure, I need to configure my modified version of the cma3000d.c file, to use other registers. I spent some time reading about SPI on wikipedia, so i know the purpose of those 4 wire types.

I tried looking in the CC2540 Users guide, section 7.11 to try and understand this, but it didn't help me much unfortunately.

So my question is: how do i modify for example accInit to fit my pin selection? Furthermore to understand that, how do I know what values to set in PERCFG, P1SEL, etc. ?

Best Regards

Jesper Hoff

  • Hi,

    First of all, the DN112 is what you need to read right now (this document is valid for CC2540 devices too).

    If you still having problems to configure and make the SPI work, please let me know.

    There's also peripherals software examples for C2541, there's an example for SPI, you might

    try it too (though DN112 should be enough to get you through).

  • Hi Igor,

    I am using a CC2540EM to connect to an external MCU with my own modified SimpleBLECentral coding. However I keep on getting the same error: PERCFG, P0SEL, etc. are undefined. If I use them in SimpleBLEPeripheral I do not get this error. I really need to get this code going but I seem to be missing an include file or library or something. If possible can anyone please assist me in this matter it would be much appreciated.

    Regards Ruart

  • Hi Ruart,

    This is very odd. The definition of PERCFG and P0SEL can be found in ioCC2540.h

  • Hi Igor,

    Thanks for your quick response. I thought as much...still very weird though. Hours of fun.

    Regards

    Ruart

    Edit 1: Just started working...and I have no idea why.

  • I'm working on a spi issue also.  My spi application works correctly, made sure to set and clear each bit even to default values.  When putting my function in OSAL it stops working.  I think something in the closed source bluetooth stack is messing it up.

  • Hi,

    What you mean by saying "in OSAL"?

    Just a known fact, while cc254x chip is in PM2/PM3, the configuration of SPI isn't retained.

    Therefore, it should be reconfigured each and every time your chip is "awake" and you want to

    send/receive something via SPI

  • I narrowed the problem down to the 32k osc- it was put in backwards!

  • HI  ,

    i'm having some problems with spi configuration on cc2540 too. 

    I just want configure spi at usart1, alt.2 (such as DN113) and testing write operation. The problem is that U1DBUF is not filled :\ 

    My code is:

    //--------------------------------------------------------------------------------------------

    void configSPI(){

    // *  de I/O -- USART1, Alt.2 *
    //----------------------------------------------------

    // Modo "Master"
    PERCFG |= 0x02; // PERCFG.U0CFG = 1
    P1SEL |= 0xE0; // P1_7, P1_6, e P1_5 são perifericos
    P1SEL &= ~0x10; // P1_4 é GPIO (SSN)
    P1DIR |= 0x10; // SSN é o output

    // *  interface SPI *
    //--------------------------------

    // Set baud rate (32MHz/8 = 4)
    U1BAUD = 0x00; // BAUD_M = 0
    U1GCR |= 0x0F; // BAUD_E = 15 -> for fSCK = 1MHz

    // Configure  USART1  SPI and Master mode
    U1CSR &= ~0xA0;

    // Configure phase, polarity, and bit order
    U1GCR &= ~0xC0; // CPOL = CPHA = 0 (negative polarity)
    U1GCR |= 0x20; // ORDER = 1 (MSB first)

    }

    void sendBufferSPI(uint8* buffer, uint8 bufferSize){

    uint8 i = 0;

    for(i =0; i < bufferSize; i++){
    SSN = LOW;
    U1DBUF = buffer[i];
    while (!(U1CSR & 0x02)); // U1TX_BYTE
    U1CSR &= ~0x02; // U1TX_BYTE = 0
    SSN = HIGH;
    }

    }

    Can you tell me what i'm doing wrong ?? Regards