aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorUwe Hermann2011-11-13 09:00:28 +0100
committerUwe Hermann2011-11-13 23:16:12 +0100
commit8a77630997a6f8e4cb543528d5c1c63b060fd7de (patch)
tree344f6ed773cbeb8666ddda8a3fa3212dca663dff /examples
parent53a0c44bfdf6d059d02f09cfc92c06d7b3a61362 (diff)
other/i2c_stts75_sensor: Cosmetics.
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32/f1/other/i2c_stts75_sensor/i2c_stts75_sensor.c14
-rw-r--r--examples/stm32/f1/other/i2c_stts75_sensor/stts75.c17
-rw-r--r--examples/stm32/f1/other/i2c_stts75_sensor/stts75.h2
3 files changed, 18 insertions, 15 deletions
diff --git a/examples/stm32/f1/other/i2c_stts75_sensor/i2c_stts75_sensor.c b/examples/stm32/f1/other/i2c_stts75_sensor/i2c_stts75_sensor.c
index d8f2404..634f457 100644
--- a/examples/stm32/f1/other/i2c_stts75_sensor/i2c_stts75_sensor.c
+++ b/examples/stm32/f1/other/i2c_stts75_sensor/i2c_stts75_sensor.c
@@ -79,16 +79,16 @@ void i2c_setup(void)
i2c_set_fast_mode(I2C2);
/*
- * fclock for I2C is 36MHz APB2 -> cycle time 28ns, low time at 400KHz
- * incl trise -> Thigh= 1600ns; CCR= tlow/tcycle= 0x1C,9;
- * datasheet suggests 0x1e.
+ * fclock for I2C is 36MHz APB2 -> cycle time 28ns, low time at 400kHz
+ * incl trise -> Thigh = 1600ns; CCR = tlow/tcycle = 0x1C,9;
+ * Datasheet suggests 0x1e.
*/
i2c_set_ccr(I2C2, 0x1e);
/*
* fclock for I2C is 36MHz -> cycle time 28ns, rise time for
- * 400KHz => 300ns and 100KHz => 1000ns; 300ns/28ns = 10;
- * incremented by 1 -> 11.
+ * 400kHz => 300ns and 100kHz => 1000ns; 300ns/28ns = 10;
+ * Incremented by 1 -> 11.
*/
i2c_set_trise(I2C2, 0x0b);
@@ -107,7 +107,7 @@ int main(void)
int i = 0;
u16 temperature;
- rcc_clock_setup_in_hse_16mhz_out_72mhz();
+ rcc_clock_setup_in_hse_16mhz_out_72mhz();
gpio_setup();
usart_setup();
i2c_setup();
@@ -140,7 +140,7 @@ int main(void)
gpio_clear(GPIOB, GPIO6); /* LED2 on */
- while(1); /* Halt. */
+ while (1); /* Halt. */
return 0;
}
diff --git a/examples/stm32/f1/other/i2c_stts75_sensor/stts75.c b/examples/stm32/f1/other/i2c_stts75_sensor/stts75.c
index f28019c..e09f877 100644
--- a/examples/stm32/f1/other/i2c_stts75_sensor/stts75.c
+++ b/examples/stm32/f1/other/i2c_stts75_sensor/stts75.c
@@ -43,7 +43,8 @@ void stts75_write_config(u32 i2c, u8 sensor)
/* Sending the data. */
i2c_send_data(i2c, 0x1); /* stts75 config register */
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)));
/* Send STOP condition. */
@@ -75,8 +76,9 @@ void stts75_write_temp_os(u32 i2c, u8 sensor, u16 temp_os)
while (!(I2C_SR1(i2c) & I2C_SR1_BTF));
i2c_send_data(i2c, (u8)(temp_os >> 8)); /* MSB */
while (!(I2C_SR1(i2c) & I2C_SR1_BTF));
- 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. */
+ i2c_send_data(i2c, (u8)(temp_os & 0xff00)); /* LSB */
+ /* After the last byte we have to wait for TxE too. */
+ while (!(I2C_SR1(i2c) & (I2C_SR1_BTF | I2C_SR1_TxE)));
/* Send STOP condition. */
i2c_send_stop(i2c);
@@ -107,8 +109,9 @@ void stts75_write_temp_hyst(u32 i2c, u8 sensor, u16 temp_hyst)
while (!(I2C_SR1(i2c) & I2C_SR1_BTF));
i2c_send_data(i2c, (u8)(temp_hyst >> 8)); /* MSB */
while (!(I2C_SR1(i2c) & I2C_SR1_BTF));
- 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. */
+ i2c_send_data(i2c, (u8)(temp_hyst & 0xff00)); /* LSB */
+ /* After the last byte we have to wait for TxE too. */
+ while (!(I2C_SR1(i2c) & (I2C_SR1_BTF | I2C_SR1_TxE)));
/* Send STOP condition. */
i2c_send_stop(i2c);
@@ -154,7 +157,7 @@ u16 stts75_read_temperature(u32 i2c, u8 sensor)
/* Say to what address we want to talk to. */
i2c_send_7bit_address(i2c, sensor, I2C_READ);
-
+
/* 2-byte receive is a special case. See datasheet POS bit. */
I2C_CR1(i2c) |= (I2C_CR1_POS | I2C_CR1_ACK);
@@ -165,7 +168,7 @@ u16 stts75_read_temperature(u32 i2c, u8 sensor)
reg32 = I2C_SR2(i2c);
/* 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. */
while (!(I2C_SR1(i2c) & I2C_SR1_BTF));
diff --git a/examples/stm32/f1/other/i2c_stts75_sensor/stts75.h b/examples/stm32/f1/other/i2c_stts75_sensor/stts75.h
index 57f6190..283299d 100644
--- a/examples/stm32/f1/other/i2c_stts75_sensor/stts75.h
+++ b/examples/stm32/f1/other/i2c_stts75_sensor/stts75.h
@@ -32,7 +32,7 @@
#define STTS75_SENSOR7 0x4f
void stts75_write_config(u32 i2c, u8 sensor);
-void stts75_write_temp_os(u32 i2c, u8 sensor, u16 temp_os);
+void stts75_write_temp_os(u32 i2c, u8 sensor, u16 temp_os);
void stts75_write_temp_hyst(u32 i2c, u8 sensor, u16 temp_hyst);
u16 stts75_read_temperature(u32 i2c, u8 sensor);