OLIMEX© 2020
MOD-IO user's manual
i2cStart();
//Send start condition
i2cSend(0xb0);
//This is 0x58 shifted to left one time and added 0 as W
i2cSend(0x10);
//Command to set relays
i2cSend(0x05);
//0x05 → 0b00000101 → This way we will set REL1 and REL3
i2cClose();
//Send stop condition
2.7.2 Getting the state of opto-isolators
The board features four optoisolated inputs named IN1, IN2, IN3 and IN4 and their statuses can be read
together with one command. The command should have the following format:
************************************
S aaaaaaaW cccccccc P S aaaaaaaR 0000dddd P
************************************
,where
S – start condition
aaaaaaa – slave address of the board
W – write mode, should be 0
cccccccc – command code, should be 0×20
P – Stop condition
R – read mode, should be 1
dddd – bitmap of the input states received from the MOD-IO board, i.e. bit0 corresponds to IN1,
bit1 to IN2 and so on. '1' means that power is applied to the optocoupler, '0' means the opposite.
Note: Successive readings from the board without reissuing the command code will not get an updated
value of the ports (i.e. the user will read the same value) until another command is issued.
Example:
Reading optocoupled inputs in pseudo code
i2cStart()
//Send start condition;
i2cSend(0xb0);
//This is 0×58 shifted to left one time and added 0 as W
i2csend(0x20);
//Read inputs commands
i2cClose();
//Send stop condition
i2cStart();
//Send start condition. You can use i2cRestart() instead
i2cSend(0xb1);
//This is 0×58 shifted to left one time and added 1 as W
byte = i2cRead();
//Read one byte of data;
i2cClose();
/* “byte” now holds the state of the inputs. To “decode” bitmask the data. */
in1 = byte & 0x01;
//To get state of IN1
in2 = byte & 0x02;
//To get state of IN2
in3 = byte & 0x04;
//To get state of IN3
in4 = byte & 0x08;
//To get state of IN4
Page 11 of 30