?? msp430fg4619 eeprom emulation_cce.c
字號:
//******************************************************************************
// MSP430xG461x Demo - 24xx EEPROM Emulation using USCI_B0 and DMA
//
// Description: This code uses the USCI_B0 module in conjunction with
// one DMA channel to emulate a 24xx-type EEPROM. It implements address
// selection, current address read, random read, and sequential read
// operations. The code is optimized for maximum efficiency to enable
// zero-latency I2C communication in I2C fast mode as required by some
// master devices such as the TUSB3410.
//
// An application example, the EEPROM contents as used in the app note
// SLAA276 is used and provided to the TUSB3410.
//
// ACLK = 32kHz, MCLK = SMCLK = 8MHz
//
// /|\ /|\
// TUSB3410 1k 1k MSP430xG461x
// ------------ | | -------------------
// | SDA|<-|---+->|P3.1/UCB0SDA XIN|-
// | | | | | 32kHz
// | | | | XOUT|-
// | | | | |
// | SCL|--+----->|P3.2/UCB0SCL |
// | | | |
// | | | |
// | | | P1.4|--> SMCLK
//
// Andreas Dannenberg
// Texas Instruments Inc.
// October 2006
// Built with Code Composer Essentials V2.00
//******************************************************************************
#include "msp430xG46x.h"
#define EEPROM_ADDRESS 0x50 // Address for EEPROM emulation
//------------------------------------------------------------------------------
// 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"
//------------------------------------------------------------------------------
static 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);
// Implementation
void main(void)
{
InitSystem();
__enable_interrupt();
__bis_SR_register(LPM0_bits); // Enter LPM0
}
void InitSystem(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop Watchdog timer
// Clock system setup
FLL_CTL0 |= DCOPLUS + XCAP18PF; // DCO+ set, freq = xtal x D x N+1
SCFI0 |= FN_4; // x2 DCO freq, 8MHz nominal DCO
SCFQCTL = 121; // (121+1) x 32768 x 2 = 7.99 MHz
P1SEL |= 0x10; // Output SMCLK on P1.4
P1DIR |= 0x10; // Set P1.4 to output
// Configure DMA Channel 0 to source the I2C Module
DMACTL0 = DMA0TSEL_13; // Trigger is USCI_B0 transmit
DMA0CTL = DMASRCINCR_3 + DMADSTBYTE + DMASRCBYTE;
DMA0SA = (__SFR_FARPTR)(unsigned long)&EEPROMImage; // Source is virtual EEPROM
DMA0DA = (__SFR_FARPTR)(unsigned long)&UCB0TXBUF; // Dest is USCI_B0 TX buffer
DMA0SZ = sizeof EEPROMImage;
DMA0CTL |= DMAEN; // Enable DMA channel 0
// Init USCI_B0 Module for slave mode
P3SEL |= 0x06; // Assign I2C pins to USCI_B0
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMODE_3 + UCSYNC; // I2C Slave, synchronous mode
UCB0I2COA = EEPROM_ADDRESS; // Set Own Address
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
IE2 |= UCB0RXIE; // Enable RX interrupt
}
//------------------------------------------------------------------------------
// The USCIB0 data ISR is used to receive data from the TUSB3410 I2C master.
// This data is used as an EEPROM emulation start address by using the two
// received bytes as the start address for the next I2C read transaction. The
// DMA is used for efficient data transfers. Note that the temporary value
// 0xffff which is used to determine if the 1st/2nd byte was received is
// also generated CPU internal by the constant generator, thus allowing for
// a maximum-efficiency implementation.
//------------------------------------------------------------------------------
__interrupt void USCIAB0TX_ISR_FUNC(void)
{
static unsigned int EEPROMTemp = 0xffff; // Assign initial value,
// 'static' to preserve variable
// over ISR calls
if (EEPROMTemp == 0xffff) // MSB already received?
{
EEPROMTemp = UCB0RXBUF; // No, load address MSB
}
else // Yes, re-assign DMA source addr
{
DMA0CTL &= ~DMAEN; // Disable DMA channel 0
DMA0SA = (__SFR_FARPTR)((unsigned long)&EEPROMImage + (EEPROMTemp << 8) + UCB0RXBUF);
DMA0CTL |= DMAEN; // Re-enable DMA channel 0
EEPROMTemp = 0xffff; // Ready for new address
}
}
USCIAB0TX_ISR(USCIAB0TX_ISR_FUNC) // Assign interrupt vector
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -