Example doesn't compile due to implicit declaration of functions
Struggling with programming DS18B20 in ESP-IDF
incorrect declaration of ets_delay_us
ESP8266 non-os SDK problems
Hello,
I'm trying to make a program to get temperature readings from a DS18B20. I can get the initialization working but can't get the read ROM (maybe SKIP ROM and CONVERT T as well) command to work. I get 111111111111 as my output in binary when I run my code. I've looked at sample code on GitHub and other than not using hex to send commands, not having code for all commands and not having capabilities for multiple sensors, I'm not sure where I'm going wrong. I also don't have a very in-depth knowledge of programming MCUs and using C, so I'm sure I'm missing something.
I'm hoping someone could help me identify my mistake(s).
#include <stdio.h>
#include "rom/gpio.h"
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "rom/ets_sys.h"
#include "esp_timer.h"
#define DATA_BUS 4
void writeOne();
void writeZero();
int readBus();
void app_main(void)
{
gpio_pad_select_gpio(DATA_BUS);
while(1)
{
int binary[12] = {};
//INITIALIZATION
gpio_set_direction(DATA_BUS, GPIO_MODE_OUTPUT);
portDISABLE_INTERRUPTS();
gpio_set_level(DATA_BUS, 0);
ets_delay_us(500);
gpio_set_direction(DATA_BUS, GPIO_MODE_INPUT);
ets_delay_us(75);
portENABLE_INTERRUPTS();
if(gpio_get_level(DATA_BUS) == 0)
{
//SKIP ROM send CCh = 1100 1100b
writeZero();
writeZero();
writeOne();
writeOne();
writeZero();
writeZero();
writeOne();
writeOne();
//CONVERT T send 44h = 0100 0100b
writeZero();
writeZero();
writeOne();
writeZero();
writeZero();
writeZero();
writeOne();
writeZero();
vTaskDelay(1000 / portTICK_PERIOD_MS);
//INITIALIZATION
gpio_set_direction(DATA_BUS, GPIO_MODE_OUTPUT);
portDISABLE_INTERRUPTS();
gpio_set_level(DATA_BUS, 0);
ets_delay_us(500);
gpio_set_direction(DATA_BUS, GPIO_MODE_INPUT);
ets_delay_us(75);
portENABLE_INTERRUPTS();
if(gpio_get_level(DATA_BUS) == 0)
{
//SKIP ROM send CCh = 1100 1100b
writeZero();
writeZero();
writeOne();
writeOne();
writeZero();
writeZero();
writeOne();
writeOne();
//READ SCRATCHPAD send BEh == 1011 1110b
writeZero();
writeOne();
writeOne();
writeOne();
writeOne();
writeOne();
writeZero();
writeOne();
for(int i = 0; i < 12; i++)
{
binary[i] = readBus();
}
gpio_set_direction(DATA_BUS, GPIO_MODE_OUTPUT);
portDISABLE_INTERRUPTS();
gpio_set_level(DATA_BUS, 0);
ets_delay_us(500);
gpio_set_direction(DATA_BUS, GPIO_MODE_INPUT);
ets_delay_us(75);
portENABLE_INTERRUPTS();
printf("\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
else
{
printf("Error2\n");
}
}
else
{
printf("Error1\n");
}
}
}
//first: initialize
//second: skip rom
//third: convert t
//fourth: initialize
//fifth: skip rom
//sixth: read scratchpad
void writeOne()
{
gpio_set_direction(DATA_BUS, GPIO_MODE_OUTPUT);
portDISABLE_INTERRUPTS();
gpio_set_level(DATA_BUS, 0);
ets_delay_us(10);
gpio_set_direction(DATA_BUS, GPIO_MODE_INPUT);
ets_delay_us(80);
ets_delay_us(10);
portENABLE_INTERRUPTS();
}
void writeZero()
{
gpio_set_direction(DATA_BUS, GPIO_MODE_OUTPUT);
portDISABLE_INTERRUPTS();
gpio_set_level(DATA_BUS, 0);
ets_delay_us(80);
gpio_set_direction(DATA_BUS, GPIO_MODE_INPUT);
ets_delay_us(10);
ets_delay_us(10);
portENABLE_INTERRUPTS();
}
int readBus()
{
int value;
gpio_set_direction(DATA_BUS, GPIO_MODE_OUTPUT);
portDISABLE_INTERRUPTS();
gpio_set_level(DATA_BUS, 0);
ets_delay_us(3);
gpio_set_direction(DATA_BUS, GPIO_MODE_INPUT);
ets_delay_us(3);
value = gpio_get_level(DATA_BUS);
ets_delay_us(64);
portENABLE_INTERRUPTS();
printf("%d\n", value);
return value;
}Hello, I am trying to build this (https://github.com/esp-rs/esp-idf-template) template project for ESP32 but when I try to cargo build this it gets stuck on: “Building [=======================> ] 167/171: esp-idf-sys(build)” for many minutes and then it crashes with:
“error: failed to run custom build command for esp-idf-sys v0.31.12
Caused by: process didn't exit successfully: /[path]/test01/target/debug/build/esp-idf-sys-e68285a66a988f80/build-script-build (exit status: 101)”
I am new to Rust so maybe it’s just a stupid mistake I am making. cargo clean doesn’t fix it. Does anyone have an idea how to fix it?