|
使用LM3S的固件库
我弄了一个简单的DS1721, 可是怎么都无法读到数据, I2CMasterErr() 确显示没有错误……
我用的主要函数:
void init_i2c()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C);
I2CMasterInitExpClk(I2C_MASTER_BASE, SysCtlClockGet(), 0);
}
void init_ds1721()
{
I2CMasterSlaveAddrSet(I2C_MASTER_BASE, 0x48, 0);
I2CMasterDataPut(I2C_MASTER_BASE, 0x51);
I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
UARTprintf("(0) i2c master error: %d\n", I2CMasterErr(I2C_MASTER_BASE));
}
unsigned int i2c_temp_read()
{
I2CMasterSlaveAddrSet(I2C_MASTER_BASE, 0x48, 0);
I2CMasterDataPut(I2C_MASTER_BASE, 0xaa);
I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
UARTprintf("(1) i2c master error: %d\n", I2CMasterErr(I2C_MASTER_BASE));
I2CMasterSlaveAddrSet(I2C_MASTER_BASE, 0x48, 1);
I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
UARTprintf("(2) i2c master error: %d\n", I2CMasterErr(I2C_MASTER_BASE));
UARTprintf("(3) data: %d\n", (int)I2CMasterDataGet(I2C_MASTER_BASE));
UARTprintf("\n");
}
不知道哪位可以提点一下……
谢谢了! |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|