uint16_t GetTemperature(uint8_t *idbuf){ uint16_t dirtytemp; uint8_t buf[2]; uint8_t cmd[12]; uint8_t i; cmd[0]=0x55; for (i=1;i<9;i++) { cmd[i]=idbuf[i-1]; } cmd[9]=0x44; OW_Send(OW_SEND_RESET, cmd, 10, NULL, NULL, OW_NO_READ); Delay(20); cmd[9]=0xbe; cmd[10]=0xff; cmd[11]=0xff; OW_Send(OW_SEND_RESET, cmd, 12, buf, 2, 10); dirtytemp = buf[1]*0x100+buf[0]; return dirtytemp; }
s8 get_temperature_3wire(){ u8 buf[2]; if(OW_Send(OW_SEND_RESET, (u8 *)"\xcc\x44", 2, 0, 0, OW_NO_READ) == OW_NO_DEVICE) {return 0;} #if DS18B20_RESOLUTION == DS18B20_9BIT delay_for(100); #endif #if DS18B20_RESOLUTION == DS18B20_10BIT delay_for(200); #endif #if DS18B20_RESOLUTION == DS18B20_11BIT delay_for(400); #endif #if DS18B20_RESOLUTION == DS18B20_12BIT delay_for(750); #endif OW_Send(OW_SEND_RESET, (u8 *)"\xcc\xbe\xff\xff", 4, (u8 *)buf, 2, 2); buf[0] >>= 4; // убираем дробную часть buf[1] <<= 4; // убираем лишние знаки return(buf[1] | buf[0]); // объединяем 2 байта -> возврат }
uint16_t GetSingleTemperature(void){ uint16_t dirtytemp; uint8_t buf[2]; OW_Send(OW_SEND_RESET, "\xcc\x44", 2, NULL, NULL, OW_NO_READ); Delay(2); OW_Send(OW_SEND_RESET, "\xcc\xbe\xff\xff", 4, buf, 2, 2); dirtytemp = buf[1]*0x100+buf[0]; return dirtytemp; }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { uint8_t i; uint8_t flag = 0; number_of_devices = 1; OW_Scan(id_buffer, number_of_devices); OW_Send(OW_SEND_RESET, (uint8_t *)"\xcc\x44", 2, 0, 0, OW_NO_READ); HAL_Delay(700); for (i = 0; i < number_of_devices; i++) { OW_Massage(flag); OW_Send(OW_SEND_RESET, massage_buffer, 12, temperature_buffer, 2, 10); OW_Output(); flag++; } /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
uint32_t owGetDate(uint8_t *idbuf){ uint8_t cmd[10]; uint8_t i; uint8_t buf[4]; cmd[0]=0x55; for (i=1;i<9;i++) { cmd[i]=idbuf[i-1]; } OW_Send(OW_SEND_RESET, cmd, 9, NULL, NULL, OW_NO_READ); Delay(10); OW_Send(OW_NO_RESET, "\x66\xff\xff\xff\xff\xff", 6, buf, 4, 2); return buf[3]*0x1000000+buf[2]*0x10000+buf[1]*0x100+buf[0]; //return (uint32_t) *buf; }
//не отлажено на железе!!! void get_temperature_2wire(int *hb, int *lb){ //команда всем сенсорам - измерять if(OW_Send(OW_SEND_RESET, (u8 *)"\xcc\x44", 2, 0, 0, OW_NO_READ)==OW_NO_DEVICE) {return;} //PIN_ON(LED_GREEN); // назначаем функцию двухтактного выхода - подаем "питание" на шину OW_out_set_as_Power_pin(); // выдерживаем время измерения (например 750 мс для 12-битного измерения) #if DS18B20_RESOLUTION == DS18B20_9BIT delay_for(100); #endif #if DS18B20_RESOLUTION == DS18B20_10BIT delay_for(200); #endif #if DS18B20_RESOLUTION == DS18B20_11BIT delay_for(400); #endif #if DS18B20_RESOLUTION == DS18B20_12BIT delay_for(750); #endif // восстанавливаем функцию передатчика UART OW_out_set_as_TX_pin(); u8 buf[2]; OW_Send(OW_SEND_RESET, (u8 *)"\xcc\xbe\xff\xff", 4, (u8 *)buf, 2, 2); #if 0 buf[0] >>= 4; // убираем дробную часть buf[1] <<= 4; // убираем лишние знаки return(buf[1] | buf[0]); // объединяем 2 байта -> возврат #endif get_temperature_value(buf, *hb, *lb); }
void owSetDate(uint8_t *idbuf){ uint8_t cmd[15]; uint8_t i; cmd[0]=0x55; for (i=1;i<9;i++) { cmd[i]=idbuf[i-1]; } cmd[9]=0x99; cmd[10]=0x0c; cmd[11]=0xff; cmd[12]=0xef; cmd[13]=0x72; cmd[14]=0x50; OW_Send(OW_SEND_RESET, cmd, 15, NULL, NULL, OW_NO_READ); }
int8_t SendData(void) { uint8_t OW_Status = OW_ERROR; OW_Status = OW_Send( CommandToSend.Reset, CommandToSend.DataToSend, CommandToSend.NumByteToSend +CommandToSend.NumByteForRead, CommandToSend.DataForRead, CommandToSend.NumByteForRead, CommandToSend.ReadStartByte); CheckOwStatus(OW_Status); if( OW_Status != OW_OK ) return OW_Status; OW_Status = CRCCheck(); if(CommandToSend.OutputOption == NO_SILENT) PrintReadData(); return OW_Status; }