Part Number:MSP430FR2433Other Parts Discussed in Thread: HDC1080
参考官方的硬件IIC程序,无法成功,调试进入中断后,立即结束,ReceiveBuffer一直都是0。单独的MSP430硬件IIC到底该如何配置
Susan Yang:
硬件I2C的话,您可以参考
https://www.lifewieller.com/2015/08/%E8%B5%B0%E8%BF%9Bmsp430%EF%BC%889%EF%BC%89-msp430g2-%E7%A1%AC%E4%BB%B6iic%E4%BD%BF%E7%94%A8%EF%BC%88%E5%AE%8C%E7%BB%93%EF%BC%89/
https://www.ti.com/lit/an/slaa249b/slaa249b.pdf
user6518570 说:调试进入中断后,立即结束,ReceiveBuffer一直都是0
您的配置是怎样的?
,
user6518570:
谢谢 我参考一下您发给我的链接,再尝试一下,如果有问题的话我再来回复您
,
user6518570:
您发给我的参考例程,相当于向从机地址为0x1E的设备写入一个0x0a? IIC的SDA线上返回的数据会直接进入发送中断中的 RX_Data[RX_CNT] = UCB0RXBUF;吗?
,
user6518570:
您能否提供一份可移植的MSP430FR2433硬件IIC配置函数,我去验证一下是我IIC配置的问题还是对HDC1080寄存器操作的不正确?
,
user6518570:
#include "include.h"
#define HDC1080_I2C_ADDR 0x80#define Temperature 0x00#define Humidity 0x01#define Configuration 0x02#define Manufacturer_ID 0xFE#define Device_ID 0xFF
#define Manufacturer_ID_value 0x5449#define Device_ID_value 0x1050#define Configuration_1 0x1000#define Configuration_2 0x3000
#define CMD_TYPE_0_SLAVE 0#define CMD_TYPE_1_SLAVE 1#define CMD_TYPE_2_SLAVE 2
#define CMD_TYPE_0_MASTER 3#define CMD_TYPE_1_MASTER 4#define CMD_TYPE_2_MASTER 5
#define TYPE_0_LENGTH 1#define TYPE_1_LENGTH 2#define TYPE_2_LENGTH 6
#define MAX_BUFFER_SIZE 20
uint8_t MasterType2 [TYPE_2_LENGTH] = {'F', '4', '1', '9', '2', 'B'};uint8_t MasterType1 [TYPE_1_LENGTH] = { 8, 9};uint8_t MasterType0 [TYPE_0_LENGTH] = { 11};
uint8_t SlaveType2 [TYPE_2_LENGTH] = {0};uint8_t SlaveType1 [TYPE_1_LENGTH] = {0};uint8_t SlaveType0 [TYPE_0_LENGTH] = {0};
typedef enum I2C_ModeEnum{ IDLE_MODE, NACK_MODE, TX_REG_ADDRESS_MODE, RX_REG_ADDRESS_MODE, TX_DATA_MODE, RX_DATA_MODE, SWITCH_TO_RX_MODE, SWITHC_TO_TX_MODE, TIMEOUT_MODE} I2C_Mode;
I2C_Mode MasterMode = IDLE_MODE;
uint8_t TransmitRegAddr = 0;
uint8_t ReceiveBuffer[MAX_BUFFER_SIZE] = {0};uint8_t RXByteCtr = 0;uint8_t ReceiveIndex = 0;uint8_t TransmitBuffer[MAX_BUFFER_SIZE] = {0};uint8_t TXByteCtr = 0;uint8_t TransmitIndex = 0;
I2C_Mode I2C_Master_WriteReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t count);I2C_Mode I2C_Master_ReadReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t count);void CopyArray(uint8_t *source, uint8_t *dest, uint8_t count);
I2C_Mode I2C_Master_ReadReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t count){ /* Initialize state machine */ MasterMode = TX_REG_ADDRESS_MODE; TransmitRegAddr = reg_addr; RXByteCtr = count; TXByteCtr = 0; ReceiveIndex = 0; TransmitIndex = 0;
/* Initialize slave address and interrupts */ UCB0I2CSA = dev_addr; UCB0IFG &= ~(UCTXIFG + UCRXIFG); // Clear any pending interrupts UCB0IE &= ~UCRXIE; // Disable RX interrupt UCB0IE |= UCTXIE; // Enable TX interrupt
UCB0CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition __bis_SR_register(GIE); // Enter LPM0 w/ interrupts
return MasterMode;
}
I2C_Mode I2C_Master_WriteReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t count){ /* Initialize state machine */ MasterMode = TX_REG_ADDRESS_MODE; TransmitRegAddr = reg_addr;
//Copy register data to TransmitBuffer CopyArray(reg_data, TransmitBuffer, count);
TXByteCtr = count; RXByteCtr = 0; ReceiveIndex = 0; TransmitIndex = 0;
/* Initialize slave address and interrupts */ UCB0I2CSA = dev_addr; UCB0IFG &= ~(UCTXIFG + UCRXIFG); // Clear any pending interrupts UCB0IE &= ~UCRXIE; // Disable RX interrupt UCB0IE |= UCTXIE; // Enable TX interrupt
UCB0CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition __bis_SR_register(GIE); // Enter LPM0 w/ interrupts
return MasterMode;}
void CopyArray(uint8_t *source, uint8_t *dest, uint8_t count){ uint8_t copyIndex = 0; for (copyIndex = 0; copyIndex < count; copyIndex++) { dest[copyIndex] = source[copyIndex]; }}
void initGPIO(){ // I2C pins P1SEL0 |= BIT2 | BIT3; // I2C pins
// Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings PM5CTL0 &= ~LOCKLPM5;}
void initI2C(){ UCB0CTLW0 = UCSWRST; // Enable SW reset UCB0CTLW0 |= UCMODE_3 | UCMST; UCB0BRW = 0x8; UCB0I2CSA = HDC1080_I2C_ADDR; // Slave Address UCB0CTLW0 &= ~UCSWRST; // Clear SW reset, resume operation UCB0IE |= UCTXIE0 | UCRXIE0 | UCNACKIE; }
//******************************************************************************// Main ************************************************************************// Send and receive three messages containing the example commands *************//******************************************************************************
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initGPIO(); initI2C(); Usart_Init();// I2C_Master_WriteReg(HDC1080_I2C_ADDR, CMD_TYPE_0_MASTER, MasterType0, TYPE_0_LENGTH);
printf("BEFORE:%x\r\n",ReceiveBuffer[0]); I2C_Master_ReadReg(HDC1080_I2C_ADDR, Manufacturer_ID, TYPE_0_LENGTH); CopyArray(ReceiveBuffer, SlaveType0, TYPE_0_LENGTH); printf("AFTER:%x\r\n",ReceiveBuffer[0]);
__bis_SR_register(GIE); return 0;}
//******************************************************************************// I2C Interrupt ***************************************************************//******************************************************************************
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)#pragma vector = USCI_B0_VECTOR__interrupt void USCI_B0_ISR(void)#elif defined(__GNUC__)void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCI_B0_ISR (void)#else#error Compiler not supported!#endif{ //Must read from UCB0RXBUF uint8_t rx_val = 0; switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG)) { case USCI_NONE: break; // Vector 0: No interrupts case USCI_I2C_UCALIFG: break; // Vector 2: ALIFG case USCI_I2C_UCNACKIFG: // Vector 4: NACKIFG break; case USCI_I2C_UCSTTIFG: break; // Vector 6: STTIFG case USCI_I2C_UCSTPIFG: break; // Vector 8: STPIFG case USCI_I2C_UCRXIFG3: break; // Vector 10: RXIFG3 case USCI_I2C_UCTXIFG3: break; // Vector 12: TXIFG3 case USCI_I2C_UCRXIFG2: break; // Vector 14: RXIFG2 case USCI_I2C_UCTXIFG2: break; // Vector 16: TXIFG2 case USCI_I2C_UCRXIFG1: break; // Vector 18: RXIFG1 case USCI_I2C_UCTXIFG1: break; // Vector 20: TXIFG1 case USCI_I2C_UCRXIFG0: // Vector 22: RXIFG0 rx_val = UCB0RXBUF; if (RXByteCtr) { ReceiveBuffer[ReceiveIndex++] = rx_val; RXByteCtr–; }
if (RXByteCtr == 1) { UCB0CTLW0 |= UCTXSTP; } else if (RXByteCtr == 0) { UCB0IE &= ~UCRXIE; MasterMode = IDLE_MODE; __bic_SR_register_on_exit(CPUOFF); // Exit LPM0 } break; case USCI_I2C_UCTXIFG0: // Vector 24: TXIFG0 switch (MasterMode) { case TX_REG_ADDRESS_MODE: UCB0TXBUF = TransmitRegAddr; if (RXByteCtr) {// MasterMode = SWITCH_TO_RX_MODE; // Need to start receiving now UCB0IE |= UCRXIE; // Enable RX interrupt UCB0IE &= ~UCTXIE; // Disable TX interrupt UCB0CTLW0 &= ~UCTR; // Switch to receiver MasterMode = RX_DATA_MODE; // State state is to receive data UCB0CTLW0 |= UCTXSTT; // Send repeated start if (RXByteCtr == 1) { //Must send stop since this is the N-1 byte while((UCB0CTLW0 & UCTXSTT)); UCB0CTLW0 |= UCTXSTP; // Send stop condition } } else {// MasterMode = TX_DATA_MODE; // Continue to transmision with the data in Transmit Buffer if (TXByteCtr) { UCB0TXBUF = TransmitBuffer[TransmitIndex++]; TXByteCtr–; } else { //Done with transmission UCB0CTLW0 |= UCTXSTP; // Send stop condition MasterMode = IDLE_MODE; UCB0IE &= ~UCTXIE; // disable TX interrupt __bic_SR_register_on_exit(CPUOFF); // Exit LPM0 } } break;
case SWITCH_TO_RX_MODE: UCB0IE |= UCRXIE; // Enable RX interrupt UCB0IE &= ~UCTXIE; // Disable TX interrupt UCB0CTLW0 &= ~UCTR; // Switch to receiver MasterMode = RX_DATA_MODE; // State state is to receive data UCB0CTLW0 |= UCTXSTT; // Send repeated start if (RXByteCtr == 1) { //Must send stop since this is the N-1 byte while((UCB0CTLW0 & UCTXSTT)); UCB0CTLW0 |= UCTXSTP; // Send stop condition } break;
case TX_DATA_MODE: if (TXByteCtr) { UCB0TXBUF = TransmitBuffer[TransmitIndex++]; TXByteCtr–; } else { //Done with transmission UCB0CTLW0 |= UCTXSTP; // Send stop condition MasterMode = IDLE_MODE; UCB0IE &= ~UCTXIE; // disable TX interrupt __bic_SR_register_on_exit(CPUOFF); // Exit LPM0 } break;
default: __no_operation(); break; } break; default: break; }}
,
user6518570:
这是我参I2C.MASTER修改的程序
,
Susan Yang:
user6518570 说:您能否提供一份可移植的MSP430FR2433硬件IIC配置函数
目前没有直接FR2433的,或许您可以看一下github的程序
https://github.com/XuanThiep/HDC1080-With-MSP430
,
user6518570:
这个是我现在的程序?为何我读取HDC1080 0XFE地址中的ID一直为0?
#include "include.h"
#define HDC1080_I2C_ADDR 0x80#define HDC1080_Temperature 0x00#define HDC1080_Humidity 0x01#define HDC1080_Configuration 0x02#define HDC1080_Manufacturer_ID 0xFE#define HDC1080_Device_ID 0xFF
#define Manufacturer_ID_value 0x5449#define Device_ID_value 0x1050#define Configuration_1 0x1000#define Configuration_2 0x3000
#define CMD_TYPE_0_SLAVE 0#define CMD_TYPE_1_SLAVE 1#define CMD_TYPE_2_SLAVE 2
#define CMD_TYPE_0_MASTER 3#define CMD_TYPE_1_MASTER 4#define CMD_TYPE_2_MASTER 5
#define TYPE_0_LENGTH 1#define TYPE_1_LENGTH 2#define TYPE_2_LENGTH 6
#define MAX_BUFFER_SIZE 20
uint8_t SlaveType2 [MAX_BUFFER_SIZE] = {0};uint8_t SlaveType1 [MAX_BUFFER_SIZE] = {0};uint8_t SlaveType0 [MAX_BUFFER_SIZE] = {0};
typedef enum I2C_ModeEnum{ IDLE_MODE, NACK_MODE, TX_REG_ADDRESS_MODE, RX_REG_ADDRESS_MODE, TX_DATA_MODE, RX_DATA_MODE, SWITCH_TO_RX_MODE, SWITHC_TO_TX_MODE, TIMEOUT_MODE} I2C_Mode;I2C_Mode MasterMode = IDLE_MODE;
uint8_t TransmitRegAddr = 0;
uint8_t ReceiveBuffer[MAX_BUFFER_SIZE] = {0};uint8_t RXByteCtr = 0;uint8_t ReceiveIndex = 0;uint8_t TransmitBuffer[MAX_BUFFER_SIZE] = {0};uint8_t TXByteCtr = 0;uint8_t TransmitIndex = 0;
I2C_Mode I2C_Master_WriteReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t count);I2C_Mode I2C_Master_ReadReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t count);void CopyArray(uint8_t *source, uint8_t *dest, uint8_t count);
I2C_Mode I2C_Master_ReadReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t count){ /* Initialize state machine */ MasterMode = TX_REG_ADDRESS_MODE; TransmitRegAddr = reg_addr; RXByteCtr = count; TXByteCtr = 0; ReceiveIndex = 0; TransmitIndex = 0;
/* Initialize slave address and interrupts */ UCB0I2CSA = dev_addr; UCB0IFG &= ~(UCTXIFG + UCRXIFG); // Clear any pending interrupts UCB0IE &= ~UCRXIE; // Disable RX interrupt UCB0IE |= UCTXIE; // Enable TX interrupt
UCB0CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition __bis_SR_register(GIE); // Enter LPM0 w/ interrupts
return MasterMode;
}
I2C_Mode I2C_Master_WriteReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t count){ /* Initialize state machine */ MasterMode = TX_REG_ADDRESS_MODE; TransmitRegAddr = reg_addr;
//Copy register data to TransmitBuffer CopyArray(reg_data, TransmitBuffer, count);
TXByteCtr = count; RXByteCtr = 0; ReceiveIndex = 0; TransmitIndex = 0;
/* Initialize slave address and interrupts */ UCB0I2CSA = dev_addr; UCB0IFG &= ~(UCTXIFG + UCRXIFG); // Clear any pending interrupts UCB0IE &= ~UCRXIE; // Disable RX interrupt UCB0IE |= UCTXIE; // Enable TX interrupt
UCB0CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition __bis_SR_register(GIE); // Enter LPM0 w/ interrupts
return MasterMode;}
void CopyArray(uint8_t *source, uint8_t *dest, uint8_t count){ uint8_t copyIndex = 0; for (copyIndex = 0; copyIndex < count; copyIndex++) { dest[copyIndex] = source[copyIndex]; }}
void initGPIO(){ // I2C pins P1SEL0 |= BIT2 | BIT3;
// Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings PM5CTL0 &= ~LOCKLPM5;}
void initClockTo16MHz(){ // Configure one FRAM waitstate as required by the device datasheet for MCLK // operation beyond 8MHz _before_ configuring the clock system. FRCTL0 = FRCTLPW | NWAITS_1;
// Clock System Setup __bis_SR_register(SCG0); // disable FLL CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source CSCTL0 = 0; // clear DCO and MOD registers CSCTL1 &= ~(DCORSEL_7); // Clear DCO frequency select bits first CSCTL1 |= DCORSEL_5; // Set DCO = 16MHz CSCTL2 = FLLD_0 + 487; // DCOCLKDIV = 16MHz __delay_cycles(3); __bic_SR_register(SCG0); // enable FLL while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // FLL locked}
void initI2C(){ UCB0CTLW0 = UCSWRST; // Enable SW reset UCB0CTLW0 |= UCMODE_3 | UCMST | UCSSEL__SMCLK | UCSYNC; // I2C master mode, SMCLK UCB0BRW = 160; // fSCL = SMCLK/160 = ~100kHz UCB0I2CSA = HDC1080_I2C_ADDR; // Slave Address UCB0CTLW0 &= ~UCSWRST; // Clear SW reset, resume operation UCB0IE |= UCTXIE0 | UCRXIE0 | UCNACKIE;}
//******************************************************************************// Main ************************************************************************// Send and receive three messages containing the example commands *************//******************************************************************************
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initClockTo16MHz(); initGPIO(); initI2C(); Usart_Init();// I2C_Master_WriteReg(HDC1080_I2C_ADDR, Configuration, Configuration_1, TYPE_0_LENGTH); printf("BEFORE:%x\r\n",ReceiveBuffer[0]); I2C_Master_ReadReg(HDC1080_I2C_ADDR, HDC1080_Manufacturer_ID, MAX_BUFFER_SIZE); CopyArray(ReceiveBuffer, SlaveType0, TYPE_0_LENGTH); printf("AFTER:%x\r\n",ReceiveBuffer[0]);
__bis_SR_register(GIE); return 0;}
//******************************************************************************// I2C Interrupt ***************************************************************//******************************************************************************
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)#pragma vector = USCI_B0_VECTOR__interrupt void USCI_B0_ISR(void)#elif defined(__GNUC__)void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCI_B0_ISR (void)#else#error Compiler not supported!#endif{ //Must read from UCB0RXBUF uint8_t rx_val = 0; switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG)) { case USCI_NONE: break; // Vector 0: No interrupts case USCI_I2C_UCALIFG: break; // Vector 2: ALIFG case USCI_I2C_UCNACKIFG: // Vector 4: NACKIFG break; case USCI_I2C_UCSTTIFG: break; // Vector 6: STTIFG case USCI_I2C_UCSTPIFG: break; // Vector 8: STPIFG case USCI_I2C_UCRXIFG3: break; // Vector 10: RXIFG3 case USCI_I2C_UCTXIFG3: break; // Vector 12: TXIFG3 case USCI_I2C_UCRXIFG2: break; // Vector 14: RXIFG2 case USCI_I2C_UCTXIFG2: break; // Vector 16: TXIFG2 case USCI_I2C_UCRXIFG1: break; // Vector 18: RXIFG1 case USCI_I2C_UCTXIFG1: break; // Vector 20: TXIFG1 case USCI_I2C_UCRXIFG0: // Vector 22: RXIFG0 rx_val = UCB0RXBUF; if (RXByteCtr) { ReceiveBuffer[ReceiveIndex++] = rx_val; RXByteCtr–; }
if (RXByteCtr == 1) { UCB0CTLW0 |= UCTXSTP; } else if (RXByteCtr == 0) { UCB0IE &= ~UCRXIE; MasterMode = IDLE_MODE; } break; case USCI_I2C_UCTXIFG0: // Vector 24: TXIFG0 switch (MasterMode) { case TX_REG_ADDRESS_MODE: UCB0TXBUF = TransmitRegAddr; if (RXByteCtr) {// MasterMode = SWITCH_TO_RX_MODE; // Need to start receiving now UCB0IE |= UCRXIE; // Enable RX interrupt UCB0IE &= ~UCTXIE; // Disable TX interrupt UCB0CTLW0 &= ~UCTR; // Switch to receiver MasterMode = RX_DATA_MODE; // State state is to receive data UCB0CTLW0 |= UCTXSTT; // Send repeated start if (RXByteCtr == 1) { //Must send stop since this is the N-1 byte while((UCB0CTLW0 & UCTXSTT)); UCB0CTLW0 |= UCTXSTP; // Send stop condition } } else {// MasterMode = TX_DATA_MODE; // Continue to transmision with the data in Transmit Buffer if (TXByteCtr) { UCB0TXBUF = TransmitBuffer[TransmitIndex++]; TXByteCtr–; } else { //Done with transmission UCB0CTLW0 |= UCTXSTP; // Send stop condition MasterMode = IDLE_MODE; UCB0IE &= ~UCTXIE; // disable TX interrupt } } break;
case SWITCH_TO_RX_MODE: UCB0IE |= UCRXIE; // Enable RX interrupt UCB0IE &= ~UCTXIE; // Disable TX interrupt UCB0CTLW0 &= ~UCTR; // Switch to receiver MasterMode = RX_DATA_MODE; // State state is to receive data UCB0CTLW0 |= UCTXSTT; // Send repeated start if (RXByteCtr == 1) { //Must send stop since this is the N-1 byte while((UCB0CTLW0 & UCTXSTT)); UCB0CTLW0 |= UCTXSTP; // Send stop condition } break;
case TX_DATA_MODE: if (TXByteCtr) { UCB0TXBUF = TransmitBuffer[TransmitIndex++]; TXByteCtr–; } else { //Done with transmission UCB0CTLW0 |= UCTXSTP; // Send stop condition MasterMode = IDLE_MODE; UCB0IE &= ~UCTXIE; // disable TX interrupt __bic_SR_register_on_exit(CPUOFF); // Exit LPM0 } break;
default: __no_operation(); break; } break; default: break; }}
,
Susan Yang:
谢谢您的反馈。请问您是否有使用示波器看一下时序?
,
user6518570:
有的 示波器显示只有起始发送字节的一个脉冲?
,
user6518570:
SCL只有一个高电平 持续600ms左右就拉低了
,
Susan Yang:
能贴出示波器截图吗?
,
user6518570:
这是测量SCL引脚端的时序图,跟模拟时完全不同,不知道是代码中哪里的问题
,
user6518570:
SDA引脚端只有一个时钟沿向下的60us左右的一个脉冲
,
Susan Yang:
您的SDA SCL上的上拉电阻是多少?
SCL的话电平正常应该是高,如果是低电平,由于SCL一定是Master控制的,很有可能是因为没有ACK等原因导致MCU一直在等待。
正常波形应该如下图
,
user6518570:
我的上拉电阻不是10k,但是应该与这无关吧
,
user6518570:
您可以跑一下官方的例程给我看一看时序吗,因为我是直接参考的官方的master修改的,我刚才跑了一下原版例程,时序如现在一样,是我硬件的问题?
,
Susan Yang:
抱歉,开发板上没有上拉电阻,且只有一个板子,不好测试
,
user6518570:
您所说的没有ACK应答,這種情況如何检测解决?而且时序不对,是UCB0CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition没有奏效吗
,
Susan Yang:
user6518570 说:是UCB0CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition没有奏效吗
是的,您可以使用CCS调试一下看一下是什么情况
使用示波器看一下SCL和SDA的波形情况
user6518570 说:您所说的没有ACK应答,這種情況如何检测解决?
https://www.ti.com.cn/cn/lit/ug/slau445i/slau445i.pdf
您可以在调试中查看
Table 24-2. I 2C State Change Interrupt Flags
各个寄存器的情况,从而判断问题
,
user6518570:
while(!(UCB0IFG & UCTXIFG)) 程序一直死在这里是因为什么啊?是因为我的地址设置问题吗
,
user6518570:
谢谢您之前的回答,我在看了应用手册后,产生这样一个疑问?当msp430做主机时,实现可写可读功能。当调用读取功能时,是否是发起一个重启动来改变SDA线上数据的传输方向来实现读取。
,
user6518570:
我可以把我的工程压缩发给您 具体帮我看一下吗
,
Susan Yang:
可以的,但是我这边是不好实际进行测试的
,
user6518570:
嗯,没关系,如果有空的话,请帮我看看基础的一些初始化配置,或是时钟配置有无问题就好了。我第一次使用,也不确定哪些细节时要注意的。麻烦了MSP_I2C_TEST.zip
,
user6518570:
经过调试,现在已经可以读取HDC1080的MANUFACTURER ID,但是仅在调试模式下单步运行,可以读取,当我全速运行时为何就变成了0XFF?
,
Susan Yang:
user6518570 说:现在已经可以读取HDC1080的MANUFACTURER ID,
抱歉抱歉,之前漏掉了您的回复。请问您现在情况如何?若是可以读取的话,说明硬件上基本没有问题了。
user6518570 说:但是仅在调试模式下单步运行,可以读取,当我全速运行时为何就变成了0XFF?
还是建议您使用示波器看一下时序
,
user6518570:
嗯 已经没问题了,都已经可以正常读取温湿度了
,
user6518570:
现在在研究RTC,或许之后会有RTC的问题请教,hh
,
Susan Yang:
很高兴您能解决问题。是硬件上的问题吗?
user6518570 说:在在研究RTC,或许之后会有RTC的问题请教,hh
好的,您可以随时在论坛发帖询问
,
user6518570:
不是硬件的问题,还是时序的问题,我在I2C操作函数里稍加了延时,在即将对 HDC1080 初始化寄存器写操作之前又重新初始化了一遍I2C的配置,这里我也有点不理解,还望告知 。如果不这样做的话,经过验证,我在对HDC1080初始化寄存器写操作时就会一直在while((UCB0IFG & UCTXIFG)==0);这里造成卡死现象。
,
user6518570:
全速运行读取问题是加了一些延时后,就稳定了。
,
Susan Yang:
user6518570 说:在即将对 HDC1080 初始化寄存器写操作之前又重新初始化了一遍I2C的配置,这里我也有点不理解,还望告知
例程中的逻辑是这样的
在写寄存器之前来初始化I2C