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

📄 msp430f2274-tusb3410_demo_cce.c

📁 MSP430操作TUSB3410,USB接口芯片的源代码
💻 C
字号:
//------------------------------------------------------------------------------
// MSP430F2274-TUSB3410 Reference Design Demo Code V1.00
//
// This demo software interfaces the MSP430 to the TUSB3410 USB-to-serial
// bridge controller. The program is part of the "MSP430 USB Connectivity
// using TUSB3410" application note (SLAA276). It is demonstrated how the
// MSP430 is used to emulate the external TUSB3410 USB configuration EEPROM.
// Furthermore, the 12MHz XTAL attached to the MSP430 is also used to supply
// the clock to the TUSB3410 via ACLK output. After this, a demo application
// is started. The demo receives characters from the TUSB3410 virtual COM port
// (VCP) with a baud rate of 460,800. The lower nibble of a received character
// is output to the LEDs 1...4 on the demo board. Also, on press or release of
// any push-button SW1...SW4, a byte is transmitted back to the PC containing
// the updated button state.
//
// MSP430 ressources used:
//   o USCI_A0 in UART mode for serial comm with TUSB3410
//   o USCI_B0 in I2C slave mode for I2C EEPROM emulation
//   o Timer_A3 for push-button query
//
// Andreas Dannenberg
// MSP430/TMS470 Applications
// Texas Instruments Inc.
// October 2006
//
// Built with Code Composer Essentials V2.00
//------------------------------------------------------------------------------
#include "msp430x22x4.h"
//------------------------------------------------------------------------------
// I2C communication related definitions
//------------------------------------------------------------------------------
#define EEPROM_ADDRESS           0x50           // Address for EEPROM emulation
//------------------------------------------------------------------------------
// Operate TUSB3410 RESET signal as open-drain output
//------------------------------------------------------------------------------
#define TUSB3410_RESET_LOW       P3DIR |= 0x01
#define TUSB3410_RESET_HIGHZ     P3DIR &= ~0x01
//------------------------------------------------------------------------------
// Misc definitions
//------------------------------------------------------------------------------
enum { false, true };
//------------------------------------------------------------------------------
// Globals used by I2C routines
//------------------------------------------------------------------------------
unsigned int EE_AddrPtr;                        // EEPROM Address Pointer
//------------------------------------------------------------------------------
// Globals used by main() and ISRs
//------------------------------------------------------------------------------
static unsigned char ButtonState = 0;
static unsigned char ButtonSet = 0;
static unsigned char ButtonReleased = 0;
static unsigned char RxData;
static unsigned char DataReceived = 0;
//------------------------------------------------------------------------------
// The constant EEPROMImage[] contains the data to be loaded into the TUSB3410
// USB configuration EEPROM. It was generated using the tools provided in
// SLLC251 and then converted into a C constant. Note that the USB descriptor
// blocks contain checksums, therefore manual modification of the below EEPROM
// image is not recommended.
//
// USB vendor ID: 0x0451 (TI's VID)
// USB product ID: 0xbeef (This application's PID)
// USB product descriptor: "MSP430-TUSB3410 Reference Design"
//------------------------------------------------------------------------------
const unsigned char EEPROMImage[] =
{
  0x10, 0x34, 0x03, 0x12, 0x00, 0x33, 0x12, 0x01,
  0x10, 0x01, 0xff, 0x00, 0x00, 0x08, 0x51, 0x04,
  0xef, 0xbe, 0x01, 0x01, 0x01, 0x02, 0x00, 0x01,
  0x05, 0x6c, 0x00, 0x34, 0x04, 0x03, 0x09, 0x04,
  0x24, 0x03, 0x54, 0x00, 0x65, 0x00, 0x78, 0x00,
  0x61, 0x00, 0x73, 0x00, 0x20, 0x00, 0x49, 0x00,
  0x6e, 0x00, 0x73, 0x00, 0x74, 0x00, 0x72, 0x00,
  0x75, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x6e, 0x00,
  0x74, 0x00, 0x73, 0x00, 0x42, 0x03, 0x4d, 0x00,
  0x53, 0x00, 0x50, 0x00, 0x34, 0x00, 0x33, 0x00,
  0x30, 0x00, 0x2d, 0x00, 0x54, 0x00, 0x55, 0x00,
  0x53, 0x00, 0x42, 0x00, 0x33, 0x00, 0x34, 0x00,
  0x31, 0x00, 0x30, 0x00, 0x20, 0x00, 0x52, 0x00,
  0x65, 0x00, 0x66, 0x00, 0x65, 0x00, 0x72, 0x00,
  0x65, 0x00, 0x6e, 0x00, 0x63, 0x00, 0x65, 0x00,
  0x20, 0x00, 0x44, 0x00, 0x65, 0x00, 0x73, 0x00,
  0x69, 0x00, 0x67, 0x00, 0x6e, 0x00, 0x00, 0x00,
  0x00
};
//------------------------------------------------------------------------------
// Function prototypes
//------------------------------------------------------------------------------
void InitSystem(void);
void Delay100(void);
void InitI2C(void);
void InitUART(void);
//------------------------------------------------------------------------------
// void main(void)
//
// The main application code first initializes the MSP430 peripherals. Then,
// an event-processing loop is entered. While no event is pending, the MSP430
// rests in LPM0 with interrupts enabled.
//
// IN:  ButtonState
//      ButtonSet
//      ButtonReleased
//      DataReceived
//      RxData
// OUT: ButtonState
//      ButtonSet
//      ButtonReleased
//      DataReceived
//------------------------------------------------------------------------------
void main(void)
{
  InitSystem();

  while (1)                                     // Main event processing loop
  {
    __disable_interrupt();                      // Protect the following code
    if (!ButtonSet && !ButtonReleased && !DataReceived)
    {
      __bis_SR_register(LPM0_bits + GIE);       // Wait in LPM0 for event, int
      __no_operation();
    }
    else
      __enable_interrupt();                     // Allow interrupts again

    if (ButtonSet || ButtonReleased)            // Button event pending?
    {
      while (!(IFG2 & UCA0TXIFG));              // Ensure USCI_A0 is ready
      __disable_interrupt();                    // Protect the following code
      UCA0TXBUF = ButtonState;                  // TX current button state
      ButtonSet = 0;                            // Clear flags
      ButtonReleased = 0;
      __enable_interrupt();                     // Allow interrupts again
    }

    if (DataReceived)                           // UART RX revent pending?
    {
      __disable_interrupt();                    // Protect the following code

      if (RxData & 0x01)                        // Check bit 0 of RX'd char...
        P1OUT |= 0x01;                          // ...and set LED1 accordingly
      else
        P1OUT &= ~0x01;

      if (RxData & 0x02)                        // Check bit 1 of RX'd char...
        P1OUT |= 0x04;                          // ...and set LED2 accordingly
      else
        P1OUT &= ~0x04;

      if (RxData & 0x04)                        // Check bit 2 of RX'd char...
        P1OUT |= 0x10;                          // ...and set LED3 accordingly
      else
        P1OUT &= ~0x10;

      if (RxData & 0x08)                        // Check bit 3 of RX'd char...
        P1OUT |= 0x40;                          // ...and set LED4 accordingly
      else
        P1OUT &= ~0x40;

      DataReceived = false;                     // Event was handled
      __enable_interrupt();                     // Allow interrupts again
    }
  }
}
//------------------------------------------------------------------------------
// void InitSystem(void)
//
// This function configures the MSP430. Peripherals are initialized, the
// external 12MHz crystal on LFXT1 is activated and used for ACLK and MCLK,
// the USCI is initialized, and the TUSB3410 released to operation.
//
// IN:  -
// OUT: -
//------------------------------------------------------------------------------
void InitSystem(void)
{
  WDTCTL = WDTPW + WDTHOLD;                     // Stop Watchdog timer

  // Port setup
  P1OUT = 0x00;                                 // Clear output latch
  P1DIR = 0x55;                                 // P1.0/2/4/6 out, others inp
  P1IES = 0x00;                                 // Detect rising edge
  P1IE  = 0xaa;                                 // Enable int for P1.1/3/5/7
  P2OUT = 0x00;                                 // Clear output latch
  P2DIR = 0xff;                                 // All output
  P2SEL = 0xc1;                                 // XTAL on P2.7/6, ACLK on P2.0
  P3OUT = 0x00;                                 // Clear output latch
  P3DIR = 0xff;                                 // All output
  P3SEL = 0x36;                                 // Select USCI I2C / UART pins
  P4OUT = 0x00;                                 // Clear output latch
  P4DIR = 0xff;                                 // All output

  TUSB3410_RESET_LOW;                           // Hold TUSB3410 in reset

  // Clock system setup
  BCSCTL1 |= XTS;                               // ACLK = LFXT1 = HF XTAL
  BCSCTL3 |= LFXT1S1;                           // 3 

⌨️ 快捷键说明

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