i2c通信 msp430g2553_430 G2553 LAUNCHPAD 简单I2C通信,用TI官方的 using IIC MASTER(slaa382) 代码,改从器件地址后总是悬在while (...

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值