Other Parts Discussed in Thread:LMP91000, MSP430F5528
各位TI专家们好,我使用MSP403FR5959与LMP91000连接,代码用的是官方案例中的,但是一直无法通讯,想知道是不是官方的代码不适用于FR系列?
代码如下,
//******************************************************************************
// Description: This file contains functions that allow the MSP430 device to
// access the I2C interface of the LMP91000. There are multiple
// instances of each function; the one to be compiled is selected by the
// system variable TI_LMP91000_SER_INTF, defined in "TI_LMP91000_hardware_board.h".
//
// MSP430/LMP91000 Interface Code Library v1.0
////
// Vishy Natarajan
// Texas Instruments Inc.
// October 2011
// Built with CCE Version: 4.2 and IAR Embedded Workbench Version: 5.3x
//******************************************************************************
// Change Log:
//******************************************************************************
// Version: 1.00
// Comments: Initial Release Version
//******************************************************************************
/* Copyright 2007-2009 Texas Instruments Incorporated. All rights reserved.
IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user who
downloaded the software, his/her employer (which must be your employer) and
Texas Instruments Incorporated (the "License"). You may not use this Software
unless you agree to abide by the terms of the License. The License limits your
use, and you acknowledge, that the Software may not be modified, copied or
distributed unless embedded on a Texas Instruments microcontroller or used
solely and exclusively in conjunction with a Texas Instruments radio frequency
transceiver, which is integrated into your product. Other than for the
foregoing purpose, you may not use, reproduce, copy, prepare derivative works
of, modify, distribute, perform, display or sell this Software and/or its
documentation for any purpose.
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED 揂S IS� WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL TEXAS
INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL
EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT
LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL
DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS,
TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
*******************************************************************************/
#include "msp430.h"
#include <stdint.h>
#include "TI_MSP430.h"
#include "TI_MSP430_hardware_board.h"
#include "TI_MSP430_i2c.h"
//******************************************************************************
// Support for 552x USCI_B0
//******************************************************************************
#if TI_LMP91000_SER_INTF == TI_LMP91000_SER_INTF_USCIB0_5xx
int8_t PtrTransmit;
uint8_t I2CBufferArray[16];
uint8_t I2CBuffer;
/*—————————————————————————-*/
// Description:
// Initialization of the I2C Module
/*—————————————————————————-*/
void I2CSetup(uint8_t device_i2c_address)
{
TI_LMP91000_I2C_USCIB0_PxSEL |= TI_LMP91000_I2C_USCIB0_SDA +
TI_LMP91000_I2C_USCIB0_SCL; // Assign I2C pins to USCI_B0
// Recommended initialisation steps of I2C module as shown in User Guide:
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTLW0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2 + UCTR + UCSWRST; // Use SMCLK, TX mode, keep SW reset
UCB0BR0 = SCL_CLOCK_DIV; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = device_i2c_address; // define Slave Address
// In this case the Slave Address
// defines the control byte that is
// sent to the LMP91000.
UCB0I2COA0 = 0x01A5; // own address.
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
if (UCB0STAT & UCBBUSY) // test if bus to be free
{ // otherwise a manual Clock on is
// generated
TI_LMP91000_I2C_USCIB0_PxSEL &= ~TI_LMP91000_I2C_USCIB0_SCL; // Select Port function for SCL
TI_LMP91000_I2C_USCIB0_PxOUT &= ~TI_LMP91000_I2C_USCIB0_SCL; //
TI_LMP91000_I2C_USCIB0_PxDIR |= TI_LMP91000_I2C_USCIB0_SCL; // drive SCL low
TI_LMP91000_I2C_USCIB0_PxSEL |= TI_LMP91000_I2C_USCIB0_SDA +
TI_LMP91000_I2C_USCIB0_SCL; // select module function for the
// used I2C pins
};
}
/*—————————————————————————*/
// Description:
// Initialization of the I2C Module for Write operation.
/*—————————————————————————*/
void I2CWriteInit(void)
{
UCB0CTL1 |= UCTR; // UCTR=1 => Transmit Mode (R/W bit = 0)
UCB0IFG &= ~UCTXIFG;
UCB0IE &= ~UCRXIE; // disable Receive ready interrupt
UCB0IE |= UCTXIE; // enable Transmit ready interrupt
}
/*—————————————————————————-*/
// Description:
// Initialization of the I2C Module for Read operation.
/*—————————————————————————-*/
void I2CReadInit(void)
{
UCB0CTL1 &= ~UCTR; // UCTR=0 => Receive Mode (R/W bit = 1)
UCB0IFG &= ~UCRXIFG;
UCB0IE &= ~UCTXIE; // disable Transmit ready interrupt
UCB0IE |= UCRXIE; // enable Receive ready interrupt
}
/*—————————————————————————-*/
// Description:
// Register Write Operation. The communication via the I2C bus with a LMP91000
// is realized. A data byte is written into a user defined address.
/*—————————————————————————-*/
void LMP91000_I2CWriteReg(uint8_t address, uint8_t data)
{
while (UCB0STAT & UCBUSY); // wait until I2C module has
// finished all operations.
I2CBufferArray[1] = address; // Byte address.
I2CBufferArray[0] = data;
PtrTransmit = 1; // set I2CBufferArray Pointer
I2CWriteInit();
UCB0CTL1 |= UCTXSTT; // start condition generation
// => I2C communication is started
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts
UCB0CTL1 |= UCTXSTP; // I2C stop condition
while(UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
}
/*—————————————————————————-*/
// Description:
// Register Read Operation. Data byte is read from the LMP91000. The LMP91000
// address is defined with the parameter address.
/*—————————————————————————-*/
uint8_t LMP91000_I2CReadReg(uint8_t address)
{
while (UCB0STAT & UCBUSY); // wait until I2C module has
// finished all operations
I2CBufferArray[0] = address; // store single bytes that have to
// be sent in the I2CBuffer.
PtrTransmit = 0; // set I2CBufferArray Pointer
// Write Address first
I2CWriteInit();
UCB0CTL1 |= UCTXSTT; // start condition generation
// => I2C communication is started
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts
// Read Data byte
I2CReadInit();
UCB0CTL1 |= UCTXSTT; // I2C start condition
while(UCB0CTL1 & UCTXSTT); // Start condition sent?
UCB0CTL1 |= UCTXSTP; // I2C stop condition
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts
while(UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
return I2CBuffer;
}
/*—————————————————————————*/
/* Interrupt Service Routines */
/*—————————————————————————-*/
#pragma vector=USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)
{
switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG)) // I2C stop condition))
{
case 0: break; // Vector 0: No interrupts
case 2: break; // Vector 2: ALIFG
case 4: break; // Vector 4: NACKIFG
case 6: break; // Vector 6: STTIFG
case 8: break; // Vector 8: STPIFG
case 22: // Vector 12: TXIFG
I2CBuffer = UCB0RXBUF; // store received data in buffer
__bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
break; // Vector 10: RXIFG
case 24:
if (PtrTransmit >= 0) // Check Transmit pointer
{
UCB0TXBUF = I2CBufferArray[PtrTransmit]; // Load TX buffer
PtrTransmit–; // Decrement TX byte counter
}
else
{
UCB0IFG &= ~UCTXIFG; // Clear USCI_B0 TX int flag
__bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
}
break;
default: break;
}
}
#endif
Susan Yang:
The software examples have been developed for the MSP430F5528 breakout board, but can easily be ported to another hardware platform
您是否进行了相关的改动?
,
Susan Yang:
请看一下
www.ti.com/…/snaa138c.pdf
的5.3 Adapting the Demo Project to Other Hardware
,
user6494387:
是我之前某个设置有问题,谢谢了
,
Susan Yang:
很高兴您能解决问题!