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通讯问题



,我用两个,一个用master,初始化为用的USART 0  alternate location  1

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

PERCFG |= 0x00

  //  P1SEL |= 0x38;    
P0SEL |= 0x2C;    
// Configure CS (P05) as output  
P0DIR |= 0x10;    
CS = CS_DISABLED;

    //*** Setup the SPI interface ***     // SPI master mode    
U0CSR = 0x00;    // 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;

 

slave端为

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

PERCFG |= 0x00

  //  P1SEL |= 0x38;    
P0SEL |= 0x2C;     // Configure CS (P05) as output  
P0DIR |= 0x10;    
CS = CS_DISABLED;

    //*** Setup the SPI interface ***    
// SPI master mode    
U0CSR=0x20;  这个变化了一下   // Negative clock polarity, Phase: data out on CPOL -> CPOL-inv     //                                  
U0GCR = 0x20;     // SCK frequency = 480.5kHz (max 500kHz)    
U0GCR |= 0x0D;    
U0BAUD = 0xEC;

//写函数

void spiWriteByte(uint8 write) {   
   CS = CS_ENABLED;    
WAIT_1_3US(2);  
U0CSR &= ~0x02;                 // Clear TX_BYTE        
U0DBUF = write;        
while (!(U0CSR & 0x02));        // Wait for TX_BYTE to be set
CS = CS_DISABLED;
}

 

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

  这样传输数据时不正常,,这个代码是cma3000.c里改了一下,