November 23, 2024, 05:43:04 AM

OLIMEXINO-328 + MOD-RS485-ISO

Started by in06khattab, July 15, 2014, 12:32:11 PM

Previous topic - Next topic

in06khattab

Hi,

I am trying to send data from the MOD-RS485-ISO. The example code and firmware was useful to just interact with I2C, but I could not manage to receive any data from the RS485. I tried to manually add some wire.write commands to try and get an output, but unfortunately I did not receive any data.

The firmware file states that when writing, you need to do this:
START|ADDRESS|W|ACK|DATA1|ACK|DATA2|ACK.....|STOP

I tried implementing this and here is my code, DATA1 and DATA2 are 0x01 and 'A'
The serial printline is not necessary but I just wanted to see what happens, and it gives out 255 each time the button is pressed.

#include <Wire.h>
#include <RS485ISO.h>
#include "../Wire/Wire.h"

/* Check if the readed ID is correct */
RS485ISO rs(0x22);
void setup()
{
  pinMode(2, INPUT);
  Serial.begin(9600);
}
void loop()
{
  if(digitalRead(2) == LOW){
    unsigned char data; 

    Wire.begin();
    Wire.beginTransmission(0x22);
    Wire.write(0x30);
    Wire.write(0x00);
    //This is it from the firmware, the rest is my attempt to send data
   
    Wire.write(0x01);
    Wire.write(0x00);
    Wire.write("A");
    Wire.write(0x00);
    Wire.endTransmission();
   
    data = Wire.read();
    Serial.println(data);
   
   
    while(digitalRead(2) == LOW);
  }
}


LubOlimex

Hello in06khattab,

We haven't yet converted the example we have available for firmware version 2.

If you are in a hurry, please take a look at the example we had for firmware version 1 (note that the I2C address is different between firmware revisions):

https://www.olimex.com/Products/Duino/AVR/OLIMEXINO-328/resources/OLIMEXINO-328-MOD-RS485-ISO.zip

Best regards,
Lub/OLIMEX
Technical support and documentation manager at Olimex

in06khattab

Thank you, I managed to send a hello world when both jumpers were closed, but however, when both jumpers were open, i could not manage so send any data.

How do I send data through full duplex?

Here was the code I used:
#include <Wire.h>
#include <RS485ISO.h>
#include <ctype.h>


/* Enable communication while button is pressed. */
RS485ISO rs(0x22);

void setup()
{
  Serial.begin(9600);

}


void loop()
{
  if(digitalRead(2) == LOW){
    rs.openChannel(rs.CHANNEL_IN | rs.CHANNEL_OUT);

    Serial.write("Hello World");

    while(digitalRead(2) == LOW);
  }
  else {
    rs.closeChannel(rs.CHANNEL_IN | rs.CHANNEL_OUT);
    while(digitalRead(2) == HIGH);
  }
}