TI中文支持网
TI专业的中文技术问题搜集分享网站

MSP432 IIC 标志位不置位,求大神解答

用的官方给的例程,改了地址和数据,程序就会死在一句标志位检查语句

一直死在while里,这是在driverlib.c文件中

while (!BITBAND_PERI(EUSCI_B_CMSIS(moduleInstance)->rIFG.r, UCTXIFG_OFS));

我的程序,如下,死在了标红的语句里。

/* DriverLib Defines */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>

/* Standard Defines */
#include <stdint.h>
#include <stdbool.h>
#include <string.h>

/* Slave Address for I2C Slave */
#define SLAVE_ADDRESS 0xD0
#define NUM_OF_REC_BYTES 1

/* Variables */
const uint8_t TXData[] = {0x6B,0x00};
static uint8_t RXData;

/* I2C Master Configuration Parameter */
const eUSCI_I2C_MasterConfig i2cConfig =
{
EUSCI_B_I2C_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
3000000, // SMCLK = 3MHz (default)
EUSCI_B_I2C_SET_DATA_RATE_100KBPS, // Desired I2C Clock of 100khz
0, // No byte counter threshold
EUSCI_B_I2C_NO_AUTO_STOP // No Autostop
};

int main(void)
{
/* Disabling the Watchdog */
MAP_WDT_A_holdTimer();

/* Select Port 1 for I2C – Set Pin 6, 7 to input Primary Module Function,
* (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL).
*/
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
GPIO_PIN6 + GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);
MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);

MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN1);
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN1);

/* Initializing I2C Master to SMCLK at 100khz with no autostop */
MAP_I2C_initMaster(EUSCI_B0_BASE, &i2cConfig);

/* Specify slave address */
MAP_I2C_setSlaveAddress(EUSCI_B0_BASE, SLAVE_ADDRESS);

/* Enable I2C Module to start operations */
MAP_I2C_enableModule(EUSCI_B0_BASE);
MAP_Interrupt_enableInterrupt(INT_EUSCIB0);

// enable RX interrupts
MAP_I2C_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0);

while (1)
{
RXData=0;

/* Making sure the last transaction has been completely sent out */
while (MAP_I2C_masterIsStopSent(EUSCI_B0_BASE));

/* Send out EEPROM Mock Read Cmd (2 databytes) */
MAP_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, TXData[1]); // Start + 1Byte
MAP_I2C_masterSendMultiByteNext(EUSCI_B0_BASE, TXData[0]); // Poll for TXINT,Send 1Byte
/*———————————————*/
/* Now we need to initiate the read */
/* Wait until 2nd Byte has been output to shift register */
while(!(EUSCI_B0->IFG & EUSCI_B_IFG_TXIFG0));

// Send the restart condition, read one byte, send the stop condition right away
EUSCI_B0->CTLW0 &= ~(EUSCI_B_CTLW0_TR);
EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_TXSTT;
while(MAP_I2C_masterIsStartSent(EUSCI_B0_BASE));
EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_TXSTP;
//while(!(EUSCI_B0->IFG & EUSCI_B_IFG_RXIFG0));
//RXData = EUSCI_B0->RXBUF;

//———————————
MAP_PCM_gotoLPM0InterruptSafe();

// Slave should send a single 'R' back
if(RXData != 'R'){
// Error- set P1.0 high
MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
while(1);
}
__delay_cycles(300000); // ~100ms pause between transmissions
}
}

/*******************************************************************************
* eUSCIB0 ISR. The repeated start and transmit/receive operations happen
* within this ISR.
*******************************************************************************/
void EUSCIB0_IRQHandler(void)
{
uint_fast16_t status;

status = MAP_I2C_getEnabledInterruptStatus(EUSCI_B0_BASE);
MAP_I2C_clearInterruptFlag(EUSCI_B0_BASE, status);

/* Receives bytes into the receive buffer. If we have received all bytes,
* send a STOP condition */
if (status & EUSCI_B_I2C_RECEIVE_INTERRUPT0)
{
// One-byte Read
RXData = MAP_I2C_masterReceiveSingle(EUSCI_B0_BASE);
MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN1);
}
}

Susan Yang:

有可能是踩了勘误表里的USCI43

user5356195:

回复 Susan Yang:

我设置的是同步模式,查看寄存器也是同步模式,是我对UCBxCTLW0、UCBxSTATW、UCBxRXBUF、UCBxTXBUF、UCBxIFG和UCBxIV进行寄存器访问吗?我在那条语句I2C_masterSendMultiByteNext(EUSCI_B0_BASE, TXData[0]); 上面右加了一个启动条件,EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_TXSTT;全是可以正常进行,但这样会有什么影响吗。

Susan Yang:

回复 user5356195:

1 您的主从机使用的是同步时钟源?

2 有可能是您对这些寄存器操作造成的,在勘误表内有说明,避免在接收或发送时访问这些寄存器

3 建议使用勘误表内的CTLW1

赞(0)
未经允许不得转载:TI中文支持网 » MSP432 IIC 标志位不置位,求大神解答
分享到: 更多 (0)