请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:MSP430FR2433 您好!
每当我调用 ROM_EUSCI_B_I2C_masterSendMultiByteStart()时,它在 func 内的 while 循环上挂起,我在网络上有另一个从设备,但没有 任何东西可以摆脱挂起。
//***************************************************************************** //! This example shows how to configure the I2C module as a master for //! single byte transmission in interrupt mode. The address of the slave //! module that the master is communicating with also set in this example. //! //! Demo - EUSCI_B0 I2C Master TX single bytes to MSP430 Slave //! //! Description: This demo connects two MSP430's via the I2C bus. The master //! transmits to the slave. This is the master code. It continuously //! transmits 00h, 01h, ..., 0ffh and demonstrates how to implement an I2C //! master transmitter sending a single byte using the USCI_B0 TX interrupt. //! ACLK = n/a, MCLK = SMCLK = BRCLK = default DCO = ~1MHz //! //! /|\ /|\ //! MSP430FR4133 10k 10k MSP430FR4133 //! slave | | master //! ----------------- | | ----------------- //! -|XIN P5.2/UCB0SDA|<-|----+->|P5.2/UCB0SDA XIN|- //! | | | | | 32kHz //! -|XOUT | | | XOUT|- //! | P5.3/UCB0SCL|<-+------>|P5.3/UCB0SCL | //! | | | P1.0|--> LED //! //! This example uses the following peripherals and I/O signals. You must //! review these and change as needed for your own board: //! - I2C peripheral //! - GPIO Port peripheral (for I2C pins) //! - SCL2 //! - SDA //! - CS //! //! This example uses the following interrupt handlers. To use this example //! in your own application you must add these interrupt handlers to your //! vector table. //! - USCI_B0_VECTOR. //! // //***************************************************************************** #include "driverlib.h" //***************************************************************************** // //Set the address for slave module. This is a 7-bit address sent in the //following format: //[A6:A5:A4:A3:A2:A1:A0:RS] // //A zero in the "RS" position of the first byte means that the master //transmits (sends) data to the selected slave, and a one in this position //means that the master receives data from the slave. // //***************************************************************************** #define SLAVE_ADDRESS 0xBE//or could be 0xBE MC also says to write is BE to read is BF //***************************************************************************** // //Target frequency for SMCLK in kHz i2c standard mode // //***************************************************************************** #define CS_SMCLK_DESIRED_FREQUENCY_IN_KHZ 1000 //***************************************************************************** // //SMCLK/FLLRef Ratio // //***************************************************************************** #define CS_SMCLK_FLLREF_RATIO 30 uint8_t transmitData; void Send_I2C_Start(uint16_t reg) { ROM_EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B0_BASE,reg >> 8); ROM_EUSCI_B_I2C_masterSendMultiByteNext(EUSCI_B0_BASE,reg & 0xFF); } void Send_I2C_End() { ROM_EUSCI_B_I2C_masterSendMultiByteStop(EUSCI_B0_BASE); } void Send_I2C(uint8_t* data,uint8_t size) { //send data uint8_t i = 0; for(i = 0; i < size; i++) { ROM_EUSCI_B_I2C_masterSendMultiByteNext(EUSCI_B0_BASE,data[i]); } } void main (void) { WDT_A_hold(WDT_A_BASE); //Set Ratio and Desired MCLK Frequency and initialize DCO CS_initFLLSettle( CS_SMCLK_DESIRED_FREQUENCY_IN_KHZ, CS_SMCLK_FLLREF_RATIO ); //Set SMCLK = DCO with frequency divider of 1 CS_initClockSignal( CS_SMCLK, CS_DCOCLKDIV_SELECT, CS_CLOCK_DIVIDER_1 ); //Set MCLK = DCO with frequency divider of 1 CS_initClockSignal( CS_MCLK, CS_DCOCLKDIV_SELECT, CS_CLOCK_DIVIDER_1 ); // Configure Pins for I2C /* * Select Port 5 * Set Pin 2, 3 to input with function, (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL). */ GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P5, GPIO_PIN2 + GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION ); /* * Disable the GPIO power-on default high-impedance mode to activate * previously configured port settings */ PMM_unlockLPM5(); //Initialize Master EUSCI_B_I2C_initMasterParam param = {0}; param.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK; param.i2cClk = CS_getSMCLK(); param.dataRate = EUSCI_B_I2C_SET_DATA_RATE_100KBPS; param.byteCounterThreshold = 50; param.autoSTOPGeneration = EUSCI_B_I2C_NO_AUTO_STOP; ROM_EUSCI_B_I2C_initMaster(EUSCI_B0_BASE, ¶m); //Specify slave address ROM_EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE, SLAVE_ADDRESS ); //Set in transmit mode ROM_EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE ); //Enable I2C Module to start operations ROM_EUSCI_B_I2C_enable(EUSCI_B0_BASE); ROM_EUSCI_B_I2C_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_TRANSMIT_INTERRUPT1 + EUSCI_B_I2C_TRANSMIT_INTERRUPT2 + EUSCI_B_I2C_TRANSMIT_INTERRUPT3 + EUSCI_B_I2C_STOP_INTERRUPT); uint8_t index = 0; while(index++ < 5) { Send_I2C_Start(0x01); uint8_t data[] = {0xFF,0xFD}; Send_I2C(data,2); Send_I2C_End(); } }