12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #include "stm32f1xx_hal.h"
- #include "oneWireDriver.h"
- #include<stdio.h>
- uint8_t check = 2, temp_l = 0, temp_h = 0;
- int16_t temp = 0;
- float temperature;
- int tempInt;
- void testOneWireTimingFunc() {
- HAL_Delay(100);
- gpio_set_input(); // set as output
- while(1) {
- writeByte(0xAA);
- us_delay(100);
- /*writeBitOn();
- us_delay(40);
- gpio_set_input(); // set as output
- us_delay(10);
- gpio_set_output(); // set as output
- writeBitOff();
- us_delay(20);
- */
- }
- }
- void initReadTemp()
- {
- uint32_t noOfSlots = 0;
- oneWire_init();
- writeByte(0xCC); // skip ROM
- writeByte(0x44); // convert t
- while( readSlot() == 0 ) {
- noOfSlots++;
- us_delay(10);
- }
- printf("Sl:%u\n",noOfSlots);
- }
- float readTemperature()
- {
- uint8_t retVal = oneWire_init();
- writeByte(0xCC); // skip ROM
- writeByte(0xBE); // Read Scratchpad
- temp_l = readByte();
- temp_h = readByte();
- uint8_t b3 = readByte();
- uint8_t b4 = readByte();
- uint8_t b5 = readByte();
- uint8_t b6 = readByte();
- uint8_t b7 = readByte();
- uint8_t b8 = readByte();
- temp = (int16_t)((temp_h << 8) | temp_l);
- temperature = (float)temp / 16;
- printf("retVal=%u %u %u %u %u %u ",retVal,temp_l,temp_h,b3,b4,b5);
- printf(" %u %u %u\n",b6,b7,b8);
- return temperature;
- }
|