Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f4xx.h"
- #include "stm32f4_discovery.h"
- #include "tm_stm32f4_ds18b20.h"
- #include "one_wire_lib/tm_stm32f4_onewire.h"
- #define EXPECTING_SENSORS 1
- int main(void) {
- RCC_PLLConfig(RCC_PLLSource_HSE, 8, 336, 2, 7);
- STM_EVAL_LEDInit(LED4);
- STM_EVAL_LEDInit(LED5);
- uint8_t devices, i, j, count, alarm_count;
- uint8_t device[EXPECTING_SENSORS][8];
- float temps[EXPECTING_SENSORS];
- /* OneWire working struct */
- TM_OneWire_t OneWire1;
- /* Initialize system */
- SystemInit();
- /* Initialize delay */
- TM_DELAY_Init();
- /* Initialize OneWire on pin PD0 */
- TM_OneWire_Init(&OneWire1, GPIOD, GPIO_Pin_0);
- count = 0;
- devices = TM_OneWire_First(&OneWire1);
- while (devices) {
- /* Increase counter */
- count++;
- /* Get full ROM value, 8 bytes, give location of first byte where to save */
- TM_OneWire_GetFullROM(&OneWire1, device[count - 1]);
- /* Get next device */
- devices = TM_OneWire_Next(&OneWire1);
- }
- /* If any devices on 1wire */
- if (count > 0) {
- STM_EVAL_LEDOn(LED4);
- } else {
- STM_EVAL_LEDOn(LED5);
- }
- for (i = 0; i < count; i++) {
- /* Set resolution to 12bits */
- TM_DS18B20_SetResolution(&OneWire1, device[i],
- TM_DS18B20_Resolution_9bits);
- }
- /* Disable alarm temperatures on all devices */
- for (i = 0; i < count; i++) {
- TM_DS18B20_DisableAlarmTemperature(&OneWire1, device[i]);
- }
- while (1) {
- /* Start temperature conversion on all devices on one bus */
- TM_DS18B20_StartAll(&OneWire1);
- /* Wait until all are done on one onewire port */
- while (!TM_DS18B20_AllDone(&OneWire1))
- ;
- /* Read temperature from ROM address and store it to temps variable */
- TM_DS18B20_Read(&OneWire1, device[0], &temps[0]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement