小弟用TM4C129X 开发板和板子自带外设TMP100进行I2C通信,把TI给的例程按照板子对应借口修改了下,但是示波器显示SCL时钟和SDA数据显示一直无输出,不知道问题出在哪里,请各位指教
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
按照如下程序写的话,读出来高位109,低位255,和TMP100手册不符,手册说低字节的低四位缺省为0,。目前怀疑I2CMasterControl( I2C6_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH ); //start+从机地址+主机数据+stop传输 写早了,注释掉后,高字节输出109 低字节也输出109,感觉读的不是正确的温度值,错误在哪里呢?
// 使能I2C模块及对应控制引脚端口
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C6);
// 配置相应控制端口
GPIOPinConfigure(GPIO_PB6_I2C6SCL);
GPIOPinConfigure(GPIO_PB7_I2C6SDA);
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_6);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_7);
// 设置I2C模块传输速率
I2CMasterInitExpClk(I2C6_BASE, ui32SysClock, ture);
I2CMasterEnable(I2C6_BASE);
ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
I2CMasterSlaveAddrSet( I2C6_BASE, 0x4A, true); //控制传输方向为主机写
I2CMasterDataPut( I2C6_BASE, 0x01 ); //写入主机数据(TMP100控制寄存器地址)
I2CMasterControl( I2C6_BASE, I2C_MASTER_CMD_BURST_SEND_START ); //start+从机地址+主机数据传输
while( I2CMasterErr(I2C6_BASE) | I2CMasterBusy(I2C6_BASE) );
I2CMasterDataPut( I2C6_BASE, 0xED ); //写入主机数据(TMP100控制寄存器内容)
I2CMasterControl( I2C6_BASE, I2C_MASTER_CMD_BURST_SEND_CONT ); //主机数据传输
while( I2CMasterErr(I2C6_BASE) | I2CMasterBusy(I2C6_BASE) );
delay_ms(35);
I2CMasterDataPut( I2C6_BASE, 0x00 ); //读取温度
I2CMasterControl( I2C6_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH ); //start+从机地址+主机数据+stop传输
while( I2CMasterErr(I2C6_BASE) | I2CMasterBusy(I2C6_BASE) );
delay_ms(25);
I2CMasterSlaveAddrSet( I2C6_BASE, 0x4A, true); //控制传输方向为主机写
I2CMasterControl( I2C6_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START );
while( I2CMasterErr(I2C6_BASE) | I2CMasterBusy(I2C6_BASE) );
Result_H = I2CMasterDataGet( I2C6_BASE );
delay_ms(325);
I2CMasterControl( I2C6_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH ); //start+从机地址+主机数据+stop传输
while( I2CMasterErr(I2C6_BASE) | I2CMasterBusy(I2C6_BASE) );
delay_ms(325);
Result_L = I2CMasterDataGet( I2C6_BASE ); //读出转换结果的低八位
delay_ms(325);