RS232/485 Half Duplex

Description

This feature, present ton OI-Core/OI-CoreLite allow you to use two different protocol on same physical interface: RS485 half duplex or RS232.

There is no terminaison resistance. If you use RS485 bus and place the module at end of line you will need to add a 120Ohms resistance.

Characteristics

RS232 specifications

Requirements

Type

Value

Driver output voltage (min)

±5V

loaded with 3kΩ to Ground

Receiver input voltage high

2.2V

above this value, a logic ‘1’ is guaranteed

Receiver input voltage low

0.8V

below this value, a logic ‘0 ‘ is guaranteed

Receiver maximum input voltage

25V

Receiver minimum input voltage

-25V

RS485 specifications

Requirements

Type

Value

Driver differential voltage (typical)

2V

Driver differential voltage (min)

1.5V

Driver differential voltage (max)

5V

Code examples

The example code above demonstrates how to use RS232 on OI-Core/OI-CoreLite.

#include "OpenIndus.h"
#include "Arduino.h"

OICore core;

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

    /* Init RS */
    core.rs.begin(OI::RS_232);
}

void loop(void)
{
    char data[100];
    size_t size = core.rs.available();

    if (size) {
        core.rs.read(data, size);
        Serial.printf("%s\n", data);
    }

    core.rs.write("Hello OpenIndus\r\n");
    delay(10);
}

The example code above demonstrates how to use RS485 on OI-Core/OI-CoreLite.

#include "OpenIndus.h"
#include "Arduino.h"

OICore core;

void setup(void)
{
    Serial.begin(115200);
    
    /* Init RS */
    core.rs.begin(OI::RS_485);
}

void loop(void)
{
    char data[100];
    size_t size = core.rs.available();

    if (size) {
        core.rs.read(data, size);
        Serial.printf("%s\n", data);
    }

    core.rs.write("Hello OpenIndus\r\n");
    delay(10);
}

Software API

void OI::RS::begin(RS_Mode_t mode, unsigned long baudrate = 115200)
void OI::RS::end(void)
int OI::RS::available(void)
int OI::RS::availableForWrite(void)
int OI::RS::read(void)
size_t OI::RS::read(uint8_t *buffer, size_t size)
inline size_t OI::RS::read(char *buffer, size_t size)
size_t OI::RS::write(uint8_t byte)
size_t OI::RS::write(uint8_t *data, size_t len)
inline size_t OI::RS::write(const char *buffer, size_t size)
inline size_t OI::RS::write(const char *s)
inline size_t OI::RS::write(unsigned long n)
inline size_t OI::RS::write(long n)
inline size_t OI::RS::write(unsigned int n)
inline size_t OI::RS::write(int n)