微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI无线射频设计 > cc2540 SPI通讯问题

cc2540 SPI通讯问题

时间:12-22 整理:3721RD 点击:

,我用两个,一个用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里改了一下,

  

我在slave端不写入数据不能到master端

两个蓝牙做SPI测试,,slave读或写时,是不是要跟据master的信号来读写,不能随时读或写(比如我在key1里加入spiWriteByte('a'))这样,这样的话slave是不能主动写,只能读,而读的时候,怎么知道master写入了,一定要IRQ吗,查询方式行不行

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top