30 #include <libopencmsis/core_cm3.h> 31 #include <libopencm3/cm3/nvic.h> 32 #include <libopencm3/stm32/rcc.h> 33 #include <libopencm3/stm32/gpio.h> 34 #include <libopencm3/stm32/timer.h> 43 #define ONEWIRE_MASTER_TIMER 2 50 #define ONEWIRE_MASTER_PORT A 51 #define ONEWIRE_MASTER_PIN 4 154 timeout = UINT16_MAX;
194 timeout = UINT16_MAX;
221 if (NULL==data || 0==length) {
226 for (uint8_t i=0; i<length; i++) {
228 for (uint8_t b=0; b<8; b++) {
248 if (NULL==data || 0==bits) {
271 if (NULL==data || 0==bits) {
288 uint8_t rom_code[8] = {0};
298 for (uint32_t i=0; i<8; i++) {
299 code += (uint64_t)rom_code[i]<<(8*i);
307 static uint8_t conflict_last = 64;
308 uint8_t conflict_current = 64;
309 uint8_t bits[1] = {0};
312 uint8_t command = 0xf0;
320 if (conflict_last>=64) {
325 for (uint8_t bit=0; bit<64; bit++) {
332 if (bit==conflict_last) {
333 *code |= (((uint64_t)1)<<bit);
335 conflict_current = bit;
336 *code &= ~(((uint64_t)1)<<bit);
340 *code |= (((uint64_t)1)<<bit);
343 *code &= ~(((uint64_t)1)<<bit);
355 uint8_t rom_code[8] = {0};
356 for (uint8_t i=0; i<
LENGTH(rom_code); i++) {
357 rom_code[i] = *code>>(8*i);
364 conflict_last = conflict_current;
365 if (conflict_current<64) {
382 uint8_t rom_code[8] = {0};
383 for (uint8_t i=0; i<
LENGTH(rom_code); i++) {
384 rom_code[i] = code>>(8*i);
static volatile uint32_t buffer_bit
number of bits read/written
#define TIM_ISR(x)
get interrupt service routine for timer base on TIM identifier
#define ONEWIRE_MASTER_PORT
GPIO port.
#define RCC_GPIO(x)
get RCC for GPIO based on GPIO identifier
uint64_t onewire_master_rom_read(void)
send READ ROM command and read ROM code response
bool onewire_master_rom_search(uint64_t *code, bool alarm)
send SEARCH ROM command
#define NVIC_TIM_IRQ(x)
get NVIC IRQ for timer base on TIM identifier
bool onewire_master_function_write(uint8_t function, uint8_t *data, uint32_t bits)
issue function and write data
#define ONEWIRE_MASTER_PIN
GPIO pin.
waiting for slave response to reset pulse
void onewire_master_setup(bool parasite, uint16_t recovery)
setup 1-wire peripheral
global definitions and methods (API)
#define GPIO(x)
get GPIO based on GPIO identifier
static bool onewire_master_read(void)
read bits on 1-Wire bus
#define RCC_TIM(x)
get RCC for timer based on TIM identifier
library for 1-wire protocol as master (API)
bool onewire_master_function_read(uint8_t function, uint8_t *data, uint32_t bits)
issue function and read data
bool onewire_master_rom_skip(void)
send SKIP ROM command (all slaves on the bus will be selected)
static bool onewire_master_write(void)
write bits on 1-Wire bus
to count the number of possible states
static uint16_t onewire_master_recovery
the recovery time in us (1 < Trec)
static uint8_t * buffer
input/output buffer for read/write commands/functions
static uint32_t buffer_size
size of buffer in bits
#define LENGTH(x)
get the length of an array
bool onewire_master_rom_match(uint64_t code)
send MATCH ROM command to select a specific slave
static bool onewire_master_parasite
if parasite power should be provided whenever the is no communication
#define TIM(x)
get TIM based on TIM identifier
static volatile bool slave_presence
if slaves have been detected
uint8_t onewire_master_crc(uint8_t *data, uint32_t length)
compute CRC for 1-Wire
bool onewire_master_reset(void)
send reset pulse
enum @0 onewire_master_state
state of 1-Wire communication
#define ONEWIRE_MASTER_TIMER
timer ID