Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.73 KB | None | 0 0
  1. #include "stm32f4xx.h"
  2. #include "stm32f4_discovery.h"
  3.  
  4. #include "tm_stm32f4_ds18b20.h"
  5. #include "one_wire_lib/tm_stm32f4_onewire.h"
  6.  
  7.  
  8. #define EXPECTING_SENSORS    1
  9.  
  10. int main(void) {
  11.  
  12.     RCC_PLLConfig(RCC_PLLSource_HSE, 8, 336, 2, 7);
  13.  
  14.     STM_EVAL_LEDInit(LED4);
  15.     STM_EVAL_LEDInit(LED5);
  16.  
  17.     uint8_t devices, i, j, count, alarm_count;
  18.     uint8_t device[EXPECTING_SENSORS][8];
  19.     float temps[EXPECTING_SENSORS];
  20.  
  21.     /* OneWire working struct */
  22.     TM_OneWire_t OneWire1;
  23.  
  24.     /* Initialize system */
  25.     SystemInit();
  26.  
  27.     /* Initialize delay */
  28.     TM_DELAY_Init();
  29.  
  30.     /* Initialize OneWire on pin PD0 */
  31.     TM_OneWire_Init(&OneWire1, GPIOD, GPIO_Pin_0);
  32.  
  33.     count = 0;
  34.     devices = TM_OneWire_First(&OneWire1);
  35.     while (devices) {
  36.         /* Increase counter */
  37.         count++;
  38.  
  39.         /* Get full ROM value, 8 bytes, give location of first byte where to save */
  40.         TM_OneWire_GetFullROM(&OneWire1, device[count - 1]);
  41.  
  42.         /* Get next device */
  43.         devices = TM_OneWire_Next(&OneWire1);
  44.     }
  45.  
  46.     /* If any devices on 1wire */
  47.     if (count > 0) {
  48.         STM_EVAL_LEDOn(LED4);
  49.     } else {
  50.         STM_EVAL_LEDOn(LED5);
  51.     }
  52.  
  53.     for (i = 0; i < count; i++) {
  54.         /* Set resolution to 12bits */
  55.         TM_DS18B20_SetResolution(&OneWire1, device[i],
  56.                 TM_DS18B20_Resolution_9bits);
  57.     }
  58.  
  59.     /* Disable alarm temperatures on all devices */
  60.     for (i = 0; i < count; i++) {
  61.         TM_DS18B20_DisableAlarmTemperature(&OneWire1, device[i]);
  62.     }
  63.  
  64.     while (1) {
  65.  
  66.         /* Start temperature conversion on all devices on one bus */
  67.         TM_DS18B20_StartAll(&OneWire1);
  68.  
  69.         /* Wait until all are done on one onewire port */
  70.         while (!TM_DS18B20_AllDone(&OneWire1))
  71.             ;
  72.  
  73.             /* Read temperature from ROM address and store it to temps variable */
  74.             TM_DS18B20_Read(&OneWire1, device[0], &temps[0]);
  75.  
  76.  
  77.  
  78.     }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement