#include "driverlib.h"
#define SLAVE_ADDRESS 0x80
uint8_t transmitData0;
uint8_t transmitData1;
uint8_t receivedData;
void main(void)
{
//Stop WDT
WDT_A_hold(WDT_A_BASE);
//Assign I2C pins to USCI_B0
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P3,
GPIO_PIN0 + GPIO_PIN1
);
//Initialize transmit data packet
transmitData0 = 0x81;
transmitData0 = 0xE0;
//Initialize Master
USCI_B_I2C_initMasterParam param = {0};
param.selectClockSource = USCI_B_I2C_CLOCKSOURCE_SMCLK;
param.i2cClk = UCS_getSMCLK();
param.dataRate = USCI_B_I2C_SET_DATA_RATE_100KBPS;
USCI_B_I2C_initMaster(USCI_B0_BASE, ¶m);
//Specify slave address
USCI_B_I2C_setSlaveAddress(USCI_B0_BASE,
SLAVE_ADDRESS
);
//Set in transmit mode
USCI_B_I2C_setMode(USCI_B0_BASE,
USCI_B_I2C_TRANSMIT_MODE
);
//Enable I2C Module to start operations
USCI_B_I2C_enable(USCI_B0_BASE);
USCI_B_I2C_clearInterrupt(USCI_B0_BASE,
USCI_B_I2C_RECEIVE_INTERRUPT
);
USCI_B_I2C_enableInterrupt(USCI_B0_BASE,
USCI_B_I2C_RECEIVE_INTERRUPT
);
//Send single byte data.
USCI_B_I2C_masterSendSingleByte(USCI_B0_BASE,
transmitData0
);
//Delay until transmission completes
while(USCI_B_I2C_isBusBusy(USCI_B0_BASE))
{
;
}
USCI_B_I2C_masterSendSingleByte(USCI_B0_BASE,
transmitData1
);
//Delay until transmission completes
while(USCI_B_I2C_isBusBusy(USCI_B0_BASE))
{
;
}
while(1)
{
//Initiate command to receive a single character from Slave
USCI_B_I2C_masterReceiveSingleStart(USCI_B0_BASE);
//Enter low power mode 0 with interrupts enabled.
//Wait until character is received.
__bis_SR_register(LPM0_bits + GIE);
__no_operation();
}
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_B0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(USCI_B0_VECTOR)))
#endif
void USCI_B0_ISR(void)
{
switch(__even_in_range(UCB0IV,12))
{
//Vector 10: Data received – RXIFG
case USCI_I2C_UCRXIFG:
{
//Grab data from data register
receivedData = USCI_B_I2C_masterReceiveSingle(
USCI_B0_BASE);
//Exit low power mode 0 and disable GIE on interrupt exit
__bic_SR_register_on_exit(LPM0_bits + GIE);
break;
}
default: break;
}
}
这是我写完读取命令后,接收iic的程序的代码,目前无法去数据,不知道哪里出现问题了,希望能帮忙解答一下,thanks!
灰小子:
已在另一个帖子回复http://www.deyisupport.com/question_answer/microcontrollers/msp430/f/55/p/84914/215097.aspx#215097