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

msp430fr2433 I2C通讯异常

更新

按照user guide重写了初始化和发送接收函数,依旧出现类似问题,通过仿真调试发现,一直作发送操作时无问题,转换为接收后就会出现发送完成标志位一直没有置位

代码如下

void I2C_init(void)
{
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_UCB0SCL,GPIO_PIN_UCB0SCL,GPIO_FUNCTION_UCB0SCL);
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_UCB0SDA,GPIO_PIN_UCB0SDA,GPIO_FUNCTION_UCB0SDA);

UCB0CTL1 |= UCSWRST; // put eUSCI_B in reset state
UCB0CTLW0 |= UCMODE_3 + UCMST + UCSSEL_2; // I2C master mode
UCB0BRW = 0x0008; // baud rate = SMCLK / 8
UCB0CTLW1 = UCASTP_0; // automatic STOP assertion
UCB0TBCNT = 0x00; // TX 7 bytes of data
UCB0CTL1 &= ~UCSWRST; // eUSCI_B in operational state
}

void I2C_send_to_receive(uint8_t id, uint8_t *sbuf, uint8_t slen, uint8_t *rbuf, uint8_t rlen)
{
uint16_t i;

UCB0I2CSA = id;
UCB0CTLW0 |= UCTR;

UCB0IFG = 0;
UCB0CTLW0 |= UCTXSTT;
while((UCB0IFG & UCTXIFG) == 0);
for(i = 0; i < slen; i++)
{
UCB0TXBUF = sbuf[i];
while((UCB0IFG & UCTXIFG) == 0);
}

if(rlen)
{
UCB0CTLW0 &= ~UCTR;
UCB0CTLW0 |= UCTXSTT;
while((UCB0IFG & UCTXIFG) == 0);
for(i = 0; i < rlen – 1; i++)
{
while((UCB0IFG & UCRXIFG) == 0);
rbuf[i] = UCB0RXBUF;
}
UCB0CTLW0 |= UCTXSTP;
while((UCB0CTLW0 & UCTXSTP));
rbuf[i++] = UCB0RXBUF;
UCB0IFG = 0;
}
else
{
UCB0CTLW0 |= UCTXSTP;
while((UCB0IFG & UCTXIFG) == 0);
UCB0IFG = 0;
}
}
#endif

更新

查看了库函数,发现有疑似BUG,但是更正后也没有用,如下图

在MSP430FR2433平台调试I2C接口时发现通讯异常,表现为进行发送并转换为接收,在接收完预期字节数后,别外产生了多个时钟信号,并且调试程序时发现其死在如下代码(库函数):

多余的时钟(如红框所示):

在库函数基础上编写的I2C读写代码,未使用中断

void I2C_init(void)
{
EUSCI_B_I2C_initMasterParam param = {0};

// Configure Pins for I2C
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_UCB0SCL,GPIO_PIN_UCB0SCL,GPIO_FUNCTION_UCB0SCL);
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_UCB0SDA,GPIO_PIN_UCB0SDA,GPIO_FUNCTION_UCB0SDA);

param.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK;
param.i2cClk = CS_getSMCLK();
param.dataRate = EUSCI_B_I2C_SET_DATA_RATE_100KBPS;
param.byteCounterThreshold = 0;
param.autoSTOPGeneration = EUSCI_B_I2C_NO_AUTO_STOP;
EUSCI_B_I2C_initMaster(EUSCI_B0_BASE, &param);

}

void I2C_send_to_receive(uint8_t id, uint8_t *sbuf, uint8_t slen, uint8_t *rbuf, uint8_t rlen)
{
uint16_t i;

while(EUSCI_B_I2C_SENDING_STOP == EUSCI_B_I2C_masterIsStopSent(EUSCI_B0_BASE));

EUSCI_B_I2C_disable(EUSCI_B0_BASE);
EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE, id);
EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE);
EUSCI_B_I2C_enable(EUSCI_B0_BASE);
//EUSCI_B_I2C_disableInterrupt(EUSCI_B0_BASE, 0xff);

EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, sbuf[0]);
for(i = 1; i < slen; i++)
{
EUSCI_B_I2C_masterSendMultiByteNext(EUSCI_B0_BASE, sbuf[i]);
}

if(rlen)
{
EUSCI_B_I2C_masterReceiveStart(EUSCI_B0_BASE);
for(i = 0; i < rlen – 1; i++)
{
rbuf[i] = EUSCI_B_I2C_masterReceiveSingle(EUSCI_B0_BASE);
}
rbuf[i] = EUSCI_B_I2C_masterReceiveMultiByteFinish(EUSCI_B0_BASE);
}
else
{
EUSCI_B_I2C_masterSendMultiByteStop(EUSCI_B0_BASE);
}
}

不知程序是否有误?

环境:

MCU:msp430fr2433

供电:3.3VDC

I2C连接器件:HT16L23

user3787132:

从波形上看,发送数据后好像没有STOP信号。

ping wu:

回复 user3787132:

查看了库函数,发现有疑似BUG,但是更正后也没有用,如下图

Susan Yang:

回复 ping wu:

看不到您的图片,请您重新上传一下

ping wu:

回复 Susan Yang:

图片已经贴到帖子正文了

赞(0)
未经允许不得转载:TI中文支持网 » msp430fr2433 I2C通讯异常
分享到: 更多 (0)