G2755做I2C从机,在测试中发现,主机低频率(每条数据间隔100MS读取)读取数据正常,而高频率(每条数据间隔10MS)读取数据时会出现概率性MCU自动复位现象。
Butterfly:
I2C速率设的多少?
yue feng1:
回复 Butterfly:
主从机都是100KHZ。如下:初始化配置和中断处理。
void TI_USCI_I2C_slaveinit(void (*SCallback)(), void (*TCallback)(unsigned char volatile *value), void (*RCallback)(unsigned char value), void (*StCallback)(), unsigned char slave_address){ P3SEL |= SDA_PIN + SCL_PIN; // Assign I2C pins to USCI_B0 UCB0CTL1 |= UCSWRST; // Enable SW reset UCB0CTL0 = UCMODE_3 + UCSYNC; // I2C Slave, synchronous mode UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset UCB0BR0 = 10; // Set prescaler 1M/10~100KHZ UCB0BR1 = 0; UCB0I2COA = slave_address; // set own (slave) address UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation IE2 |= UCB0TXIE + UCB0RXIE; // Enable TX RX interrupt UCB0I2CIE |= UCSTTIE+UCSTPIE; // Enable STT STP interrupt TI_start_callback = SCallback; TI_stop_callback = StCallback; TI_receive_callback = RCallback; TI_transmit_callback = TCallback;}
#pragma vector = USCIAB0TX_VECTOR__interrupt void USCIAB0TX_ISR(void){ if (IFG2 & UCB0TXIFG) { TI_transmit_callback(&UCB0TXBUF); } else { TI_receive_callback(UCB0RXBUF); }
}
// USCI_B0 State ISR#pragma vector = USCIAB0RX_VECTOR__interrupt void USCIAB0RX_ISR(void){ if(UCB0STAT&UCSTTIFG) { UCB0STAT &= ~UCSTTIFG; // Clear start condition int flag rxnum=0;//接收到开始信号清零 } if(UCB0STAT&UCSTPIFG) { UCB0STAT&=~UCSTPIFG; TI_stop_callback(); }}
灰小子:
回复 yue feng1:
通讯造成复位的常见原因主要有以下三种:
1、非法操作了某个寄存器;
2、数据溢出
3、通讯时序错误,等待到看门狗超时
楼主看看最可能是遇到了哪一种