Go Down

Topic: Arduino mega (Master) and Uno (slave) via Maxim DS28E17 bridge (Read 127 times) previous topic - next topic

PLZR

Hello people !

I'm trying to send a value to my slave (arduino uno) via an 1-Wire-to-I2C Master Bridge DS28E17 with 20m of RJ45 cable. The DS28E17 module is well recognised by the master (arduino Mega2560) (using 1Wire scanner showing the correct adress of the DS28E17 module).
But the Slaved UNO is not responding... Even if I using an I2C scanner in  local (both arduinos connected together without RJ45 cable), no adress is recognised... Can you help me please??


I'm following already this topic, but nothing is working... (https://forum.arduino.cc/index.php?topic=431939.msg2987174#msg2987174)

The datasheet of the DS28E17 module : https://datasheets.maximintegrated.com/en/ds/DS28E17.pdf

The serial monitor is showing this on the master (nothing on the slave serial monitor):

Code: [Select]
Status =2
Write Status =255


My code :
Master on Mega
Code: [Select]
#include <OneWire.h>


#define ONEWIRE_PIN 8

#define DS28E17_ID            0x19,0x41,0xA3,0x02,0x00,0x00,0x00,0x0F
#define WRITE_DATA_WITH_STOP  0x4B
#define I2C_ADDRESS           0x04

OneWire oneWire(ONEWIRE_PIN);

uint8_t address[8];

void printBytes(uint8_t *addr, uint8_t count, bool newline=0)
{
  for (uint8_t i = 0; i < count; i++)
  {
    Serial.print(addr[i] >> 4, HEX);  //prints the first 4 bits (most left) of addr in Hexadecimal system
    Serial.print(addr[i] & 0x0f, HEX); //BitWise between addr e 00001111, allows to print the other 4 bits (on the right)
    Serial.print(" ");
  }
  if (newline)
  {
    Serial.println();
  }
}

bool write(uint8_t i2cAddress, uint8_t i2cData) // Write a single byte to the I2C slave
{
uint8_t packet[6];                        // Reserve bytes to transmit data
 
  packet[0] = WRITE_DATA_WITH_STOP;         // Command ("Write Data With Stop")
  packet[1] = i2cAddress;                   // I2C slave to address
  packet[2] = 0x01;                         // Number of data bytes to write
  packet[3] = i2cData;                      // The data to write
 
  uint16_t CRC16 = oneWire.crc16(&packet[0], 4);
 
  CRC16 = ~CRC16;
  packet[5] = CRC16 >> 8;                   // Most significant byte of 16 bit CRC
  packet[4] = CRC16 & 0xFF;                 // Least significant byte of 16 bit CRC
 
  oneWire.reset();
  oneWire.select(address);
  oneWire.write_bytes(packet, sizeof(packet), 1); //Write the packet and hold the bus
  while(oneWire.read_bit() == true)         // Wait for not busy
  {
    delay(1);
  }
  Serial.print(F("Status ="));
  Serial.println(oneWire.read());
  Serial.print(F("Write Status ="));
  Serial.println(oneWire.read());
 
  oneWire.depower();                        // Release the bus
}

void setup()
{
  Serial.begin(9600);
 
  Serial.println(F("Looking for ID"));
  if (!oneWire.search(address))
  {
    Serial.println(F("No address."));
  }
  else
  {
    Serial.println(F("Got this address..."));
    printBytes(address, sizeof(address), true);
  }
 
  if (address[0] == DS28E17_ID)
  {
    Serial.println(F("Found a DS28E17 I2C Bridge"));
  }
  else
  {
    while (1);  // Halt if not the right 1 wire device
  }
 Serial.print("I2c adress "),Serial.println(I2C_ADDRESS);
}

void loop()
{
  write(I2C_ADDRESS, 15);   //I2C Address, I2C Data Byte
  delay(3000);
}


Slave on UNO
Code: [Select]
#include <Wire.h>

void Reception(int data)
{
  //This function triggers when data is sent by Master
 
  Serial.print(F("Data on BUS detected: "));
  byte x = Wire.read();
  Serial.println(x);
}


void setup() {
  Serial.begin(9600);
 
  //Slave Code
  Wire.begin(4);   //Initializing Arduino as Slave with address 0x04h
  Wire.onReceive(Reception); //Call the function Reception when data is sent
  Serial.println("ready");
 
 
}
void loop() {
 
}

sherzaad

have a look at the I2C master/slave example here:

https://www.arduino.cc/en/Tutorial/MasterWriter


does the example work for your MEGA-UNO setup?

PLZR

Hello thanks for your quick answer !

have a look at the I2C master/slave example here:

https://www.arduino.cc/en/Tutorial/MasterWriter


does the example work for your MEGA-UNO setup?
It's working with this configuration finally (in local, with no cable lenght), I'm a f**king idiot! I did'nt used the right pins on the MEGA....

Anyway.. It's still not working over my RJ45 cable... Do you think that I made a mistake in the I2C command and I have to work with your example to find the mistake?

PLZR

Problem solved...

The code is correct, but the syntaxe not...

In the master code, in the bool function "write", all the CRC16 need to be written like this
Code: [Select]
crc16 instead of
Code: [Select]
CRC16

It's look too easy now !

The full code for others :
Code: [Select]
#include <OneWire.h>


#define ONEWIRE_PIN 8

#define DS28E17_ID            0x19
#define WRITE_DATA_WITH_STOP  0x4B
#define I2C_ADDRESS           0x04

OneWire oneWire(ONEWIRE_PIN);

uint8_t address[8];

void printBytes(uint8_t *addr, uint8_t count, bool newline=0)
{
  for (uint8_t i = 0; i < count; i++)
  {
    Serial.print(addr[i] >> 4, HEX);  //prints the first 4 bits (most left) of addr in Hexadecimal system
    Serial.print(addr[i] & 0x0f, HEX); //BitWise between addr e 00001111, allows to print the other 4 bits (on the right)
    Serial.print(" ");
  }
  if (newline)
  {
    Serial.println();
  }
}

bool write(uint8_t i2cAddress, uint8_t i2cData) // Write a single byte to the I2C slave
{
  uint8_t packet[6];                        // Reserve bytes to transmit data
 
  packet[0] = WRITE_DATA_WITH_STOP;         // Command ("Write Data With Stop")
  packet[1] = i2cAddress << 1;              // I2C slave to address
  packet[2] = 0x01;                         // Number of data bytes to write
  packet[3] = i2cData;                      // The data to write
 
  uint16_t crc16 = oneWire.crc16(&packet[0], 4);
 
  crc16 = ~crc16;                           // Invert the crc16 value
  packet[5] = crc16 >> 8;                   // Most significant byte of 16 bit CRC
  packet[4] = crc16 & 0xFF;                 // Least significant byte of 16 bit CRC
 
  oneWire.reset();
  oneWire.select(address);
  oneWire.write_bytes(packet, sizeof(packet), 1); //Write the packet and hold the bus
  while(oneWire.read_bit() == true)         // Wait for not busy
  {
    delay(1);
  }
  Serial.print(F("Status ="));
  Serial.println(oneWire.read(),BIN);
  Serial.print(F("Write Status ="));
  Serial.println(oneWire.read(),BIN);
 
  oneWire.depower();                        // Release the bus
}

void setup()
{
  Serial.begin(9600);
 
  Serial.println(F("Looking for ID"));
  if (!oneWire.search(address))
  {
    Serial.println(F("No address."));
  }
  else
  {
    Serial.println(F("Got this address..."));
    printBytes(address, sizeof(address), true);
  }
 
  if (address[0] == DS28E17_ID)
  {
    Serial.println(F("Found a DS28E17 I2C Bridge"));
  }
  else
  {
    while (1);  // Halt if not the right 1 wire device
  }
 
}

void loop()
{
  write(I2C_ADDRESS, 15);   //I2C Address, I2C Data Byte
  delay(3000);
}

Go Up