TI中文支持网
TI专业的中文技术问题搜集分享网站

MSP430F5510的硬件SPI问题,连续读会出现丢失第一个数据的情况

//                   MSP430F550x
//                 —————–
//             /|\|                 |
//              | |                 |
//              –|RST          P4.7|-> LED
//                |                 |
//                |             P3.2|-> Serial Clock Out (UCB0SCK)
//                |             P3.1|<- Data In  (UCB0SOMI)
//                |             P3.0|-> Data Out (UCB0SIMO)
//                |             P3.0|-> Data Out (UCB0STE)

参考的例程为 slac129a.zip (MSP430FG4618/F2013 Experimenter’s Board Software),使用到的2个功能为:

char TI_CC_SPIReadReg(char addr)
{
  char x;

  TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN;        // /CS enable
  while (!(UCB0IFG &= ~UCRXIFG));                // Wait for TX to finish
  UCB0TXBUF = (addr | TI_CCxxx0_READ_SINGLE);// Send address
  while (!(UCB0IFG &= ~UCRXIFG));                // Wait for TX to finish
  UCB0TXBUF = 0;                            // Dummy write so we can read data
  // Address is now being TX'ed, with dummy byte waiting in TXBUF…
  while (!(UCB0IFG &= ~UCRXIFG));                // Wait for RX to finish
  // Dummy byte RX'ed during addr TX now in RXBUF
  UCB0IFG &= ~UCRXIFG;                       // Clear flag set during addr write
  while (!(UCB0IFG &= ~UCRXIFG));                // Wait for end of dummy byte TX
  // Data byte RX'ed during dummy byte write is now in RXBUF
  x = UCB0RXBUF;                            // Read data
  TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;         // /CS disable

  return x;
}

 

void TI_CC_SPIReadBurstReg(char addr, char *buffer, char count)
{
  char i;

  TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN;        // /CS enable
  while (TI_CC_SPI_USCIB0_PxIN&TI_CC_SPI_USCIB0_SOMI);// Wait for CCxxxx ready
  UCB0IFG &= ~UCRXIFG;                       // Clear flag
  UCB0TXBUF = (addr | TI_CCxxx0_READ_BURST);   // Send address
  while (!(UCB0IFG &= ~UCRXIFG));                // Wait for TXBUF ready
  UCB0TXBUF = 0;                            // Dummy write to read 1st data byte
  // Addr byte is now being TX'ed, with dummy byte to follow immediately after
  while (!(UCB0IFG &= ~UCRXIFG));                // Wait for end of addr byte TX
  UCB0IFG &= ~UCRXIFG;                       // Clear flag
  while (!(UCB0IFG &= ~UCRXIFG));                // Wait for end of 1st data byte TX
  // First data byte now in RXBUF
  for (i = 0; i < (count-1); i++)
  {
    UCB0TXBUF = 0;                          //Initiate next data RX, meanwhile..
    buffer[i] = UCB0RXBUF;                  // Store data from last data RX
    while (!(UCB0IFG &= ~UCRXIFG));              // Wait for RX to finish
  }
  buffer[count-1] = UCB0RXBUF;              // Store last RX byte in buffer
  TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;         // /CS disable
}

现在的问题是,时钟系统采用ACLK=32.768、SMCK=24.576MHz,当启动F5510的硬件SPI并配置端口后,CC1101模块上电,设置相关参数。为验证SPI,采用了以下2种方式对CC1101的寄存器进行读写:

方法1、连续方式的单个读寄存器,即循环使用  TI_CC_SPIReadReg() 读一批寄存器的值,结果为正确。

  for (i=0; i<32; i++) RxBuf[i] = TI_CC_SPIReadReg(i);

方法2、使用例程的 TI_CC_SPIReadBurstReg(0, RxBuf, 32)  读同一批寄存器的值,结果出现第一个结果丢失的现象、其余全部正确。即期望的第1个数据不见了,第2个数据被保存在了RxBuf[0],第3个数据被保存在了RxBuf[1],第4个数据被保存在了RxBuf[2],…,第32个数据被保存在了RxBuf[30](正确位置应该是保存在RxBuf[31])。

补充:方法2如果用于MSP430F2132+CC1101、DCO_1MHz则不会发生这种数据丢失的现象。

请求帮助分析原因并解决这个BUG,谢谢。

 

 

Young Hu:

您好,

给您提供一个文档,看看是不是有用

www.ti.com/…/swra141.pdf

赞(0)
未经允许不得转载:TI中文支持网 » MSP430F5510的硬件SPI问题,连续读会出现丢失第一个数据的情况
分享到: 更多 (0)