430 G2553 LAUNCHPAD 简单I2C通信,用TI官方的 using IIC MASTER(slaa382) 代码,改从器件地址后总是悬在while (UCB0CTL1 & UCTXSTP)语句过不去。
详细是这样的:
用430 G2553 LAUNCHPAD作简单I2C通信和BQ27441电源板通信。认真读了几百页的SLAU44J(2553用户手册)。认真读了飞利浦I2C协议原版(为理清基本概念)。用http://www.ti.com/general/docs/litabsmultiplefilelist.tsp?&literatureNumber=slaa382 中的标准官方代码,仅仅改动了头文件包含 为 2553,
I2C从器件地址55(7位地址,未加读写控制位) ,引脚从P3改P1,避开加LED的p1.6,用1.4和1.7管脚当 SLC 和 sda。
/*** USCI master library ************************************************************
In this file the usage of the USCI I2C master library without DMA support is
shown. This library uses pointers to specify what data is to be sent.
When calling the TI_USCI_I2C_receive or TI_USCI_I2C_transmit routines
the number of bytes, which are to be transmitted or received have to be passed as
well as a pointer to a data field, that contains(or stores) the data.
This code checks if there is a slave with address 0x50 is connected to the I2C
bus and if the slave device is present, bytes are received and transmitted.
Uli Kretzschmar
MSP430 Systems
Freising
*******************************************************************************/
#include
#include "TI_USCI_I2C_master.h"
unsigned char timercounter;
unsigned char array[40] = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb };
unsigned char store[40] = { 13, 13, 13, 13, 13, 13, 13, 0, 0, 0};
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
_EINT();
TI_USCI_I2C_transmitinit(0x55,0x40); // init transmitting with USCI
while ( TI_USCI_I2C_notready() ); // wait for bus to be free
if ( TI_USCI_I2C_slave_present(0x55) ) // slave address may differ from initialization
{
TI_USCI_I2C_receiveinit(0x55,0x40); // init receiving with USCI
while ( TI_USCI_I2C_notready() ); // wait for bus to be free
TI_USCI_I2C_receive(1,store);
while ( TI_USCI_I2C_notready() ); // wait for bus to be free
TI_USCI_I2C_transmitinit(0x55,0x40); // init transmitting with
while ( TI_USCI_I2C_notready() ); // wait for bus to be free
TI_USCI_I2C_transmit(4,array); // start transmitting
}
LPM3;
}
下面是TI_USCI_I2C