Basic Interface (I2C,GPIO) to start interfacing Rohm sensors to Multi-Tech Development Board
Fork of YYY_DragonflyHelloWorld by
Diff: main.cpp
- Revision:
- 4:8be5ec736893
- Parent:
- 3:e2e8d92e5fcd
--- a/main.cpp Wed Sep 23 23:02:58 2015 +0000 +++ b/main.cpp Thu Sep 24 21:50:52 2015 +0000 @@ -2,12 +2,13 @@ #define RPR0521_MODE_CONT_CONTENT (0xC6u) // Temperature Register #define RPR0521_MODE_CONT (0x41u) // Configuration Register -#define BH1745_SAD (0x38u) // LM75 address +#define BH1745_SAD (0x38u) // BH1745 address +#define BH1745_SYSTEM_CONTROL (0x40u) #define BH1745_MODE_CONTROL1 (0x41u) #define BH1745_MODE_CONTROL2 (0x42u) #define BH1745_MODE_CONTROL3 (0x43u) #define BH1745_PERSISTANT (0x61u) -#define BH1745_CLEAR_LSB (0x50u) +#define BH1745_CLEAR_LSB (0x56u) I2C i2c(I2C_SDA, I2C_SCL); DigitalOut myled(LED1); @@ -18,7 +19,7 @@ */ // LED blink rate: higher -> faster blinking -#define LED_BLINK_RATE 8 //Hertz +#define LED_BLINK_RATE 18 //Hertz //Define the LED pin output //DigitalOut data00(D0); @@ -61,7 +62,7 @@ // Configure I2C ********************************************************** char data_write[2]; - char data_read[2]; + char data_read[6]; /* Configure the Temperature sensor device STLM75: - Thermostat mode Interrupt @@ -79,7 +80,7 @@ } data_write[0] = BH1745_MODE_CONTROL1; - data_write[1] = 0x00u; + data_write[1] = 0x05u; status = i2c.write(BH1745_SAD, data_write, 2, 0); if (status != 0) { // Error while (1) { @@ -112,12 +113,17 @@ while (1) { // I2C Routines ******************************************************* // Read temperature register - data_write[0] = BH1745_CLEAR_LSB; + data_write[0] = BH1745_SYSTEM_CONTROL; i2c.write(BH1745_SAD, data_write, 1, 1); // no stop - i2c.read(BH1745_SAD, data_read, 1, 0); + i2c.read(BH1745_SAD, data_read, 6, 0); // Calculate temperature value in Celcius - int tempval = (int)data_read[0]; + int tempval1 = (int)data_read[0]; + int tempval2 = (int)data_read[1]; + int tempval3 = (int)data_read[2]; + int tempval4 = (int)data_read[3]; + int tempval5 = (int)data_read[4]; + int tempval6 = (int)data_read[5]; /* tempval >>= 7; if (tempval <= 256) { @@ -152,8 +158,8 @@ //********************************************************************* // UART - if (print_timer.read() >= 5) { //print_timer.read() returns time in seconds - printf("Hello Francis %d!\n",tempval); + if (print_timer.read() >= 1) { //print_timer.read() returns time in seconds + printf("Francis' Test: %d, %d, %d, %d. %d, %d!\n",tempval1,tempval2,tempval3,tempval4,tempval5,tempval6); print_timer.reset(); //Resets timer count to 0 }