调试硬件IIC一直出不来,做IIC读写的时候用示波器看SCL脚没有时钟波形(同样的脚,使用软件IIC时是有波形的),代码如下,还望帮我看下问题所在:
void hw_iic_Init(void)
[
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);
GPIOPadConfigSet(GPIO_PORTB_BASE,GPIO_PIN_2,GPIO_STRENGTH_8MA,GPIO_PIN_TYPE_STD_WPU);
GPIOPadConfigSet(GPIO_PORTB_BASE,GPIO_PIN_3,GPIO_STRENGTH_8MA,GPIO_PIN_TYPE_OD);
I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false); //false:100kbps true:400kbps
I2CMasterEnable(I2C0_BASE);
]
void i2c_writebyte(uint8_t slave_addr,uint8_t reg_addr,uint8_t data)
[
I2CMasterSlaveAddrSet(I2C0_BASE, slave_addr, false);
I2CMasterDataPut(I2C0_BASE, reg_addr);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusy(I2C0_BASE));
I2CMasterDataPut(I2C0_BASE, data);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusy(I2C0_BASE));
]
uint8_t i2c_readbyte(uint8_t slave_addr,uint8_t reg_addr)
[
uint8_t data;
I2CMasterSlaveAddrSet(I2C0_BASE, slave_addr, false);
I2CMasterDataPut(I2C0_BASE, reg_addr);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusy(I2C0_BASE));
I2CMasterSlaveAddrSet(I2C0_BASE, slave_addr, true);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
while(I2CMasterBusy(I2C0_BASE));
data = I2CMasterDataGet(I2C0_BASE);
return data;
]
0