other/i2c_stts75_sensor: Cosmetics.

This commit is contained in:
Uwe Hermann 2011-11-13 09:00:28 +01:00
parent 53a0c44bfd
commit 8a77630997
3 changed files with 18 additions and 15 deletions

View File

@ -79,16 +79,16 @@ void i2c_setup(void)
i2c_set_fast_mode(I2C2); i2c_set_fast_mode(I2C2);
/* /*
* fclock for I2C is 36MHz APB2 -> cycle time 28ns, low time at 400KHz * fclock for I2C is 36MHz APB2 -> cycle time 28ns, low time at 400kHz
* incl trise -> Thigh= 1600ns; CCR= tlow/tcycle= 0x1C,9; * incl trise -> Thigh = 1600ns; CCR = tlow/tcycle = 0x1C,9;
* datasheet suggests 0x1e. * Datasheet suggests 0x1e.
*/ */
i2c_set_ccr(I2C2, 0x1e); i2c_set_ccr(I2C2, 0x1e);
/* /*
* fclock for I2C is 36MHz -> cycle time 28ns, rise time for * fclock for I2C is 36MHz -> cycle time 28ns, rise time for
* 400KHz => 300ns and 100KHz => 1000ns; 300ns/28ns = 10; * 400kHz => 300ns and 100kHz => 1000ns; 300ns/28ns = 10;
* incremented by 1 -> 11. * Incremented by 1 -> 11.
*/ */
i2c_set_trise(I2C2, 0x0b); i2c_set_trise(I2C2, 0x0b);
@ -140,7 +140,7 @@ int main(void)
gpio_clear(GPIOB, GPIO6); /* LED2 on */ gpio_clear(GPIOB, GPIO6); /* LED2 on */
while(1); /* Halt. */ while (1); /* Halt. */
return 0; return 0;
} }

View File

@ -43,7 +43,8 @@ void stts75_write_config(u32 i2c, u8 sensor)
/* Sending the data. */ /* Sending the data. */
i2c_send_data(i2c, 0x1); /* stts75 config register */ i2c_send_data(i2c, 0x1); /* stts75 config register */
while (!(I2C_SR1(i2c) & I2C_SR1_BTF)); /* Await ByteTransferedFlag. */ while (!(I2C_SR1(i2c) & I2C_SR1_BTF)); /* Await ByteTransferedFlag. */
i2c_send_data(i2c, 0x4); /* pol reverse - LED glows if temp is below Tos/Thyst */ /* Polarity reverse - LED glows if temp is below Tos/Thyst. */
i2c_send_data(i2c, 0x4);
while (!(I2C_SR1(i2c) & (I2C_SR1_BTF | I2C_SR1_TxE))); while (!(I2C_SR1(i2c) & (I2C_SR1_BTF | I2C_SR1_TxE)));
/* Send STOP condition. */ /* Send STOP condition. */
@ -76,7 +77,8 @@ void stts75_write_temp_os(u32 i2c, u8 sensor, u16 temp_os)
i2c_send_data(i2c, (u8)(temp_os >> 8)); /* MSB */ i2c_send_data(i2c, (u8)(temp_os >> 8)); /* MSB */
while (!(I2C_SR1(i2c) & I2C_SR1_BTF)); while (!(I2C_SR1(i2c) & I2C_SR1_BTF));
i2c_send_data(i2c, (u8)(temp_os & 0xff00)); /* LSB */ i2c_send_data(i2c, (u8)(temp_os & 0xff00)); /* LSB */
while (!(I2C_SR1(i2c) & (I2C_SR1_BTF | I2C_SR1_TxE))); /* After the last byte we have to wait for TxE too. */ /* After the last byte we have to wait for TxE too. */
while (!(I2C_SR1(i2c) & (I2C_SR1_BTF | I2C_SR1_TxE)));
/* Send STOP condition. */ /* Send STOP condition. */
i2c_send_stop(i2c); i2c_send_stop(i2c);
@ -108,7 +110,8 @@ void stts75_write_temp_hyst(u32 i2c, u8 sensor, u16 temp_hyst)
i2c_send_data(i2c, (u8)(temp_hyst >> 8)); /* MSB */ i2c_send_data(i2c, (u8)(temp_hyst >> 8)); /* MSB */
while (!(I2C_SR1(i2c) & I2C_SR1_BTF)); while (!(I2C_SR1(i2c) & I2C_SR1_BTF));
i2c_send_data(i2c, (u8)(temp_hyst & 0xff00)); /* LSB */ i2c_send_data(i2c, (u8)(temp_hyst & 0xff00)); /* LSB */
while (!(I2C_SR1(i2c) & (I2C_SR1_BTF | I2C_SR1_TxE))); /* After the last byte we have to wait for TxE too. */ /* After the last byte we have to wait for TxE too. */
while (!(I2C_SR1(i2c) & (I2C_SR1_BTF | I2C_SR1_TxE)));
/* Send STOP condition. */ /* Send STOP condition. */
i2c_send_stop(i2c); i2c_send_stop(i2c);
@ -165,7 +168,7 @@ u16 stts75_read_temperature(u32 i2c, u8 sensor)
reg32 = I2C_SR2(i2c); reg32 = I2C_SR2(i2c);
/* Cleaning I2C_SR1_ACK. */ /* Cleaning I2C_SR1_ACK. */
I2C_CR1(i2c) &= ~ I2C_CR1_ACK; I2C_CR1(i2c) &= ~I2C_CR1_ACK;
/* Now the slave should begin to send us the first byte. Await BTF. */ /* Now the slave should begin to send us the first byte. Await BTF. */
while (!(I2C_SR1(i2c) & I2C_SR1_BTF)); while (!(I2C_SR1(i2c) & I2C_SR1_BTF));