ссылка на мой проект
Спойлер
Код: Выделить всё
void ow_search(uint8_t *id, int depth, int reset)
{
int i, b1, b2, f;
if (depth == 64) {
// we have all 64 bit in this ow_search branch
uart_WriteString("found: ");
for (i = 0; i < 8; i++) {
uart_WriteString("%02x");
uart_putchar(id[i]);
}
uart_WriteString("\n");
return;
}
if (reset) {
if (f = ow_reset()) {
uart_WriteString("reset failed\n");
if (f == 1) {
uart_WriteString("not pulldown\n");
}
if (f == 2) {
uart_WriteString("must be released\n");
}
return;
}
}
ow_write_byte(DS1820_SEARCHROM); // ow_search ROM command
// send currently recognized bits
for (i = 0; i < depth; i++)
{
b1 = ow_read_bit();
b2 = ow_read_bit();
ow_write_bit(id[i / 8] & (1 << (i % 8)));
}
// check another bit
b1 = ow_read_bit();
b2 = ow_read_bit();
if (b1 && b2) {
uart_WriteString("no response to search\n");
return; // no response to ow_search
};
if (!b1 && !b2) // two devices with different bits on this position
{
// check devices with this bit = 0
ow_write_bit(0);
id[depth / 8] &= ~(1 << (depth % 8));
ow_search(id, depth + 1, 0);
// check devices with this bit = 1
id[depth / 8] |= 1 << (depth % 8);
ow_search(id, depth + 1, 1); // different branch, reset must be issued
} else if (b1) {
// devices have 1 on this position
ow_write_bit(1);
id[depth / 8] |= 1 << (depth % 8);
ow_search(id, depth + 1, 0);
} else if (b2) {
// devices have 0 on this position
ow_write_bit(0);
id[depth / 8] &= ~(1 << (depth % 8));
ow_search(id, depth + 1, 0);
}
}Здесь добавлены проверки на наличие устройств, все сообщения отсылаются в порт. Это всё работает. А поиск - нет