Monday, 25 February 2019

How work with two slaves

This comes from Github:

Hello! I can not understand and in the examples there is no option when the master works with two or more slave devices. If there are examples - I will be grateful for the help.

And my answer:

Hi,
As a "quick and dirty" example, I would suggest you to modify the current advanced Master and declare the second telegram for another slave:

// telegram 0: read registers
telegram[0].u8id = 1; // slave address
telegram[0].u8fct = 3; // function code (this one is registers read)
telegram[0].u16RegAdd = 0; // start address in slave
telegram[0].u16CoilsNo = 4; // number of elements (coils or registers) to read
telegram[0].au16reg = au16data; // pointer to a memory array in the Arduino

// telegram 1: read a single register from another slave
telegram[1].u8id = 2; // another slave address
telegram[1].u8fct = 3 // function code
telegram[1].u16RegAdd = 0; // start address in slave
telegram[1].u16CoilsNo = 4; // number of elements (coils or registers) to read
telegram[1].au16reg = au16data+4; // pointer to a memory array in the Arduino

The rest of the code would be the same. 

No comments:

Post a Comment