This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

使用MSP430F5529的IIC与adxl345通信是遇到的问题




#include "inc/hw_memmap.h"
#include "usci_b_i2c.h"
#include "ucs.h"
#include "wdt_a.h"
#include "gpio.h"

#ifdef __IAR_SYSTEMS_ICC__
#include "deprecated/IAR/msp430xgeneric.h"
#else
#include "deprecated/CCS/msp430xgeneric.h"
#endif


#define SLAVE_ADDRESS 0x53

uint8_t transmitCounter = 0;
uint8_t receivedData;
//
void signle_write_ADXL345(uint8_t REG_Address,uint8_t REG_Date)
{

//Set Transmit mode
USCI_B_I2C_setMode(USCI_B0_BASE,
USCI_B_I2C_TRANSMIT_MODE
);

//Delay until transmission completes
while (USCI_B_I2C_isBusBusy(USCI_B0_BASE)) ;

//Initiate start and send first character
USCI_B_I2C_masterMultiByteSendStart(USCI_B0_BASE,
REG_Address
);

//Initiate send of character from Master to Slave
USCI_B_I2C_masterMultiByteSendNext(USCI_B0_BASE,
REG_Date
);
// stop character
USCI_B_I2C_masterMultiByteSendStop(USCI_B0_BASE);

}

void signle_read_ADXL345(uint8_t REG_Address)
{

//Set Transmit mode
USCI_B_I2C_setMode(USCI_B0_BASE,
USCI_B_I2C_TRANSMIT_MODE
);

//Delay until transmission completes
while (USCI_B_I2C_isBusBusy(USCI_B0_BASE)) ;

//Initiate start and send first character
USCI_B_I2C_masterMultiByteSendStart(USCI_B0_BASE,
0x32
);

// stop character
USCI_B_I2C_masterMultiByteSendStop(USCI_B0_BASE);

//Set Master in receive mode
USCI_B_I2C_setMode(USCI_B0_BASE,
USCI_B_I2C_RECEIVE_MODE
);
//
// USCI_B_I2C_clearInterruptFlag(USCI_B0_BASE,
// USCI_B_I2C_RECEIVE_INTERRUPT
// );

//Initiate command to receive a single character from Slave
//USCI_B_I2C_masterSingleReceiveStart(USCI_B0_BASE);

// __no_operation();
//
// while(0x00 == USCI_B_I2C_getInterruptStatus(USCI_B0_BASE, USCI_B_I2C_RECEIVE_INTERRUPT));
// receivedData = USCI_B_I2C_masterSingleReceive(
// USCI_B0_BASE);
// USCI_B_I2C_clearInterruptFlag(USCI_B0_BASE,
// USCI_B_I2C_RECEIVE_INTERRUPT
// );

//stop
// __delay_cycles(500);
// USCI_B_I2C_masterMultiByteReceiveStop (USCI_B0_BASE);

}


void main ()
{
//Stop WDT
WDT_A_hold(WDT_A_BASE);

//wait for slave is ready
__delay_cycles(5000);

//Assign I2C pins to USCI_B0
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P3,
GPIO_PIN1 + GPIO_PIN0
);

//Initialize Master
USCI_B_I2C_masterInit(USCI_B0_BASE,
USCI_B_I2C_CLOCKSOURCE_SMCLK,
UCS_getSMCLK(UCS_BASE),
USCI_B_I2C_SET_DATA_RATE_400KBPS
);

//Specify slave address
USCI_B_I2C_setSlaveAddress(USCI_B0_BASE,
SLAVE_ADDRESS
);

// //Set 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);

while (1)
{

signle_read_ADXL345(0x35);
__delay_cycles(50);

};
}

我使用的430WARE中的库函数,在仿真是发现,在执行while中的 signle_read_ADXL345(0x35);函数时发现 


//Set Master in receive mode
USCI_B_I2C_setMode(USCI_B0_BASE,
USCI_B_I2C_RECEIVE_MODE
);这个函数式不执行,直接跳过的,这是为什么呢?难道在一个程序中,430的的收发模式只能配置一次吗?

emptyProject.rar