⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ti_cc_spi.lst

📁 8051f340实现cc1100软件SPI的正常数据收发
💻 LST
📖 第 1 页 / 共 5 页
字号:
C51 COMPILER V7.06   TI_CC_SPI                                                             02/03/2009 16:53:58 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE TI_CC_SPI
OBJECT MODULE PLACED IN TI_CC_spi.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE TI_CC_spi.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          //----------------------------------------------------------------------------
   2          //  Description:  This file contains functions that allow the MSP430 device to 
   3          //  access the SPI interface of the CC1100/CC2500.  There are multiple 
   4          //  instances of each function; the one to be compiled is selected by the 
   5          //  system variable TI_CC_RF_SER_INTF, defined in "TI_CC_hardware_board.h".
   6          //
   7          //  MSP430/CC1100-2500 Interface Code Library v1.0
   8          //
   9          //  K. Quiring
  10          //  Texas Instruments, Inc.
  11          //  July 2006
  12          //  IAR Embedded Workbench v3.41
  13          //----------------------------------------------------------------------------
  14          
  15          
  16          #include "include.h"
  17          #include "TI_CC_spi.h"
  18          
  19          
  20          //----------------------------------------------------------------------------
  21          //  void TI_CC_SPISetup(void)
  22          //
  23          //  DESCRIPTION:
  24          //  Configures the assigned interface to function as a SPI port and
  25          //  initializes it.
  26          //----------------------------------------------------------------------------
  27          //  void TI_CC_SPIWriteReg(char addr, char value)
  28          //
  29          //  DESCRIPTION:
  30          //  Writes "value" to a single configuration register at address "addr".
  31          //----------------------------------------------------------------------------
  32          //  void TI_CC_SPIWriteBurstReg(char addr, char *buffer, char count)
  33          //
  34          //  DESCRIPTION:
  35          //  Writes values to multiple configuration registers, the first register being
  36          //  at address "addr".  First data byte is at "buffer", and both addr and
  37          //  buffer are incremented sequentially (within the CCxxxx and MSP430,
  38          //  respectively) until "count" writes have been performed.
  39          //----------------------------------------------------------------------------
  40          //  char TI_CC_SPIReadReg(char addr)
  41          //
  42          //  DESCRIPTION:
  43          //  Reads a single configuration register at address "addr" and returns the
  44          //  value read.
  45          //----------------------------------------------------------------------------
  46          //  void TI_CC_SPIReadBurstReg(char addr, char *buffer, char count)
  47          //
  48          //  DESCRIPTION:
  49          //  Reads multiple configuration registers, the first register being at address
  50          //  "addr".  Values read are deposited sequentially starting at address
  51          //  "buffer", until "count" registers have been read.
  52          //----------------------------------------------------------------------------
  53          //  char TI_CC_SPIReadStatus(char addr)
  54          //
  55          //  DESCRIPTION:
C51 COMPILER V7.06   TI_CC_SPI                                                             02/03/2009 16:53:58 PAGE 2   

  56          //  Special read function for reading status registers.  Reads status register
  57          //  at register "addr" and returns the value read.
  58          //----------------------------------------------------------------------------
  59          //  void TI_CC_SPIStrobe(char strobe)
  60          //
  61          //  DESCRIPTION:
  62          //  Special write function for writing to command strobe registers.  Writes
  63          //  to the strobe at address "addr".
  64          //----------------------------------------------------------------------------
  65          
  66          
  67          // Delay function. # of CPU cycles delayed is similar to "cycles". Specifically,
  68          // it's ((cycles-15) % 6) + 15.  Not exact, but gives a sense of the real-time
  69          // delay.  Also, if MCLK ~1MHz, "cycles" is similar to # of useconds delayed.
  70          void TI_CC_Wait(unsigned int cycles)
  71          {
  72   1        while(cycles>15)                          // 15 cycles consumed by overhead
  73   1          cycles = cycles - 6;                    // 6 cycles consumed each iteration
  74   1      }
  75          
  76          
  77          // SPI port functions
  78          #if TI_CC_RF_SER_INTF == TI_CC_SER_INTF_USART0
              
              
              void TI_CC_SPISetup(void)
              {
                TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;
                TI_CC_CSn_PxDIR |= TI_CC_CSn_PIN;         // /CS disable
              
                ME1 |= USPIE0;                            // Enable USART0 SPI mode
                UCTL0 |= CHAR + SYNC + MM;                // 8-bit SPI Master **SWRST**
                UTCTL0 |= CKPH + SSEL1 + SSEL0 + STC;     // SMCLK, 3-pin mode
                UBR00 = 0x02;                             // UCLK/2
                UBR10 = 0x00;                             // 0
                UMCTL0 = 0x00;                            // No modulation
                TI_CC_SPI_USART0_PxSEL |= TI_CC_SPI_USART0_SIMO | TI_CC_SPI_USART0_SOMI | TI_CC_SPI_USART0_UCLK;
                                                          // SPI option select
                TI_CC_SPI_USART0_PxDIR |= TI_CC_SPI_USART0_SIMO + TI_CC_SPI_USART0_UCLK;
                                                          // SPI TX out direction
                UCTL0 &= ~SWRST;                          // Initialize USART state machine
              }
              
              void TI_CC_SPIWriteReg(char addr, char value)
              {
                  TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN;      // /CS enable
                  while (TI_CC_SPI_USART0_PxIN&TI_CC_SPI_USART0_SOMI);// Wait for CCxxxx ready
                  IFG1 &= ~URXIFG0;                       // Clear flag from first dummy byte
                  U0TXBUF = addr;                         // Send address
                  while (!(IFG1&URXIFG0));                // Wait for TX to finish
                  IFG1 &= ~URXIFG0;                       // Clear flag from first dummy byte
                  U0TXBUF = value;                        // Send value
                  while (!(IFG1&URXIFG0));                // Wait for end of data TX
                  TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;       // /CS disable
              }
              
              void TI_CC_SPIWriteBurstReg(char addr, char *buffer, char count)
              {
                  char i;
              
                  TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN;      // /CS enable
                  while (TI_CC_SPI_USART0_PxIN&TI_CC_SPI_USART0_SOMI);// Wait for CCxxxx ready
C51 COMPILER V7.06   TI_CC_SPI                                                             02/03/2009 16:53:58 PAGE 3   

                  U0TXBUF = addr | TI_CCxxx0_WRITE_BURST; // Send address
                  while (!(IFG1&UTXIFG0));                // Wait for TX to finish
                  for (i = 0; i < count; i++)
                  {
                    U0TXBUF = buffer[i];                  // Send data
                    while (!(IFG1&UTXIFG0));              // Wait for TX to finish
                  }
                  IFG1 &= ~URXIFG0;
                  while(!(IFG1&URXIFG0));
                  TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;       // /CS disable
              }
              
              char TI_CC_SPIReadReg(char addr)
              {
                char x;
              
                TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN;        // /CS enable
                while (TI_CC_SPI_USART0_PxIN&TI_CC_SPI_USART0_SOMI);// Wait for CCxxxx ready
                U0TXBUF = (addr | TI_CCxxx0_READ_SINGLE); // Send address
                while (!(IFG1&URXIFG0));                  // Wait for TX to finish
                IFG1 &= ~URXIFG0;                         // Clear flag set during last write
                U0TXBUF = 0;                              // Dummy write so we can read data
                while (!(IFG1&URXIFG0));                  // Wait for RX to finish
                x = U0RXBUF;                              // Read data
                TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;         // /CS disable
              
                return x;
              }
              
              void TI_CC_SPIReadBurstReg(char addr, char *buffer, char count)
              {
                unsigned int i;
              
                TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN;        // /CS enable
                while (TI_CC_SPI_USART0_PxIN&TI_CC_SPI_USART0_SOMI);// Wait for CCxxxx ready
                IFG1 &= ~URXIFG0;                         // Clear flag
                U0TXBUF = (addr | TI_CCxxx0_READ_BURST);  // Send address
                while (!(IFG1&UTXIFG0));                  // Wait for TXBUF ready
                U0TXBUF = 0;                              // Dummy write to read 1st data byte
                // Addr byte is now being TX'ed, with dummy byte to follow immediately after
                while (!(IFG1&URXIFG0));                  // Wait for end of addr byte TX
                IFG1 &= ~URXIFG0;                         // Clear flag
                while (!(IFG1&URXIFG0));                  // Wait for end of 1st data byte TX
                // First data byte now in RXBUF
                for (i = 0; i < (count-1); i++)
                {
                  U0TXBUF = 0;                            //Initiate next data RX, meanwhile..
                  buffer[i] = U0RXBUF;                    // Store data from last data RX
                  while (!(IFG1&URXIFG0));                // Wait for end of data RX
                }
                buffer[count-1] = U0RXBUF;                // Store last RX byte in buffer
                TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;         // /CS disable
              }
              
              // For status/strobe addresses, the BURST bit selects between status registers
              // and command strobes.
              char TI_CC_SPIReadStatus(char addr)
              {
                char x;
              
                TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN;        // /CS enable
                while (TI_CC_SPI_USART0_PxIN & TI_CC_SPI_USART0_SOMI);// Wait for CCxxxx ready
C51 COMPILER V7.06   TI_CC_SPI                                                             02/03/2009 16:53:58 PAGE 4   

                IFG1 &= ~URXIFG0;                         // Clear flag set during last write
                U0TXBUF = (addr | TI_CCxxx0_READ_BURST);  // Send address
                while (!(IFG1&URXIFG0));                  // Wait for TX to finish
                IFG1 &= ~URXIFG0;                         // Clear flag set during last write
                U0TXBUF = 0;                              // Dummy write so we can read data
                while (!(IFG1&URXIFG0));                  // Wait for RX to finish
                x = U0RXBUF;                              // Read data
                TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;         // /CS disable
              
                return x;
              }
              
              void TI_CC_SPIStrobe(char strobe)
              {
                TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN;        // /CS enable
                while (TI_CC_SPI_USART0_PxIN&TI_CC_SPI_USART0_SOMI);// Wait for CCxxxx ready
                U0TXBUF = strobe;                         // Send strobe
                // Strobe addr is now being TX'ed
                IFG1 &= ~URXIFG0;                         // Clear flag
                while (!(IFG1&URXIFG0));                  // Wait for end of addr TX
                TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;         // /CS disable
              }
              
              void TI_CC_PowerupResetCCxxxx(void)
              {
                TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;
                TI_CC_Wait(30);
                TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN;
                TI_CC_Wait(30);
                TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;
                TI_CC_Wait(45);
              
                TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN;        // /CS enable
                while (TI_CC_SPI_USART0_PxIN&TI_CC_SPI_USART0_SOMI);// Wait for CCxxxx ready
                U0TXBUF = TI_CCxxx0_SRES;                 // Send strobe
                // Strobe addr is now being TX'ed
                IFG1 &= ~URXIFG0;                         // Clear flag
                while (!(IFG1&URXIFG0));                  // Wait for end of addr TX
                while (TI_CC_SPI_USART0_PxIN&TI_CC_SPI_USART0_SOMI);
                TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;         // /CS disable
              }
              
              

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -