Skip to content
This repository was archived by the owner on Jun 9, 2018. It is now read-only.
This repository was archived by the owner on Jun 9, 2018. It is now read-only.

Same code works in Uno and not in Mega2560 #9

@elusive-code

Description

@elusive-code

Hello, I have something rather wierd.

I'm trying to join several arduinos in 1-wire network.
I wrote simple test bellow to check stuff - it just checks device presense.
It contains both code for master (BOARD_NUMBER=1) and slave(everything else).

Problem is, when I use Arduino Uno as a slave - it works fine.
However when I upload the same code to Arduino Mega 2560 and use it in the same setup master node doesn't see slave (slave initialized though - printed it's address in serial).

(Tried both with receive callback and without one. Tried both Uno and Mega as master)

Relevant part (quite basic though):

#include <OneWireSlave.h>
#define PIN 2
#define DEVICE_TYPE 0

byte address[8] = {};

void generate_address(){
    randomSeed(analogRead(A0));
    address[0] = DEVICE_TYPE;
    for (int i=0; i<7; i++){
        address[i] = random();
    }
    address[7] = OneWire::crc8( address, 7);     
}

void setup_onewire(){
      //OWSlave.setReceiveCallback(&receive);
      OWSlave.begin(address, PIN);        
 }
    
void setup() {    
    Serial.begin(9600);
    generate_address();
    setup_onewire();
    Serial.print("One wire address: ");
    for( int i = 0; i < 8; i++) {
        Serial.print(address[i], HEX);
        Serial.print(" ");
    }
    Serial.println();
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, LOW);  
}

Full code:
one-wire-test-code.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions