Quantcast
Viewing all articles
Browse latest Browse all 116964

Forum Post: cc2540 keyfob as spi slave

Hi, I have been trying to connect my cc2540 keyfob to a microcontroller and read data using spi. The microcontroller is the master and the keyfob is the slave. Whenever I send data, the keyfob receives nothing over Btool. I used the keyfob demo as a base. Here is my code:

#define MISO             P0_2
#define MOSI             P0_3
#define SCK              P0_5
#define CS               P0_4

void accInit(void)
{
    //*** Setup USART 0 SPI at alternate location 2 ***

    // USART 0 at alternate location 2
    PERCFG &= ~0x01;
    //PERCFG |= 0x00;
    
    // Peripheral function on SCK, MISO and MOSI (P1_3-5)
    P0SEL |= 0x3C;
    // Configure CS (P1_7/P1_2) as output
    P0DIR &= ~0x38;
    P0DIR |= 0x04;
    /*
#ifdef REV_1_0
    P1DIR |= 0x04;
#elif (defined REV_0_6)
    P1DIR |= 0x80;
#endif
    */
    
    //CS = CS_DISABLED;

    //*** Setup the SPI interface ***
    // SPI slave mode
    U0CSR = 0x20;
    
    // Negative clock polarity, Phase: data out on CPOL -> CPOL-inv
    //                                 data in on CPOL-inv -> CPOL
    // MSB first
    U0GCR = 0x20;
    // SCK frequency = 480.5kHz (max 500kHz)
    U0GCR |= 0x0D;
    U0BAUD = 0xEC;

    /*uint8 readValue;
    accWriteReg(CTRL, RANGE_2G | MODE_100HZ_MEAS);
    WAIT_1_3US(80);
    do{
        accReadReg(STATUS, &readValue);
        WAIT_1_3US(80);
    }while(readValue & 0x08);
    */
}

void spiReadByte(uint8 *read, uint8 write)
{
        //CS=CS_ENABLED;
        //U0CSR &= ~0x04;                 // Clear TX_BYTE
        U0DBUF = write;
        while (!(U0CSR & 0x04));        // Wait for TX_BYTE to be set
        *read = U0DBUF;
        //CS=CS_DISABLED;
}

that is the cma3000d modified file. here is the keyfobdemo code

static void accelRead( void )
{

int8 x;
  spiReadByte(&x,0xFF);
  //spiWriteByte(0xFF);
  Accel_SetParameter(ACCEL_X_ATTR, sizeof(int8), &x);

}

i tried to change as little as possible from the original keyfob demo. Any help is appreciated


Viewing all articles
Browse latest Browse all 116964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>