Author Topic: Sync Master board with 5 Slave boards with 5 I/O's  (Read 431 times)

0 Members and 1 Guest are viewing this topic.

Offline ShowKemp

  • Contributor
  • Posts: 16
  • Country: ls
Sync Master board with 5 Slave boards with 5 I/O's
« on: February 22, 2019, 11:36:24 pm »

I'm working on a already done circuit, let's call it Master, Master have 5 I/O lines on it's connector that goes to 5 Slave circuits connected in parallel. Like the following image:

I need to send commands from the master board to all five slave boards, each of them have an 'unique' address.

The problem:
I can't change the Master board hardware, i don't have UART nor I2C on the 5 I/O lines, but i do have MOSI, SCLK and MISO available (+ 2 I/O), so i can't address the slave boards as they were SPI Slaves.

I tried:
I have tried 'broadcasting' 1 byte data packets (using the MOSI and SCLK lines) from the Master board to the Slave boards

1. First i set an I/O line low (as a chip select for all 5 slave boards).
2. Send data with the following format:

bit 7:4 contain the slave unique address the command is meant to, and bits 3:0 have the command sent to that slave.

3. Then i set high the I/O line.

So when the slaves see the I/O line going low they wait for the data and then parse it, getting the address and command, if this address match theirs then they execute the command.

Sometimes it works as expected, but most of the time it doesn't, the slave boards get 'random' data from the SPI bus.

I tried to do it like this on the slave board side:
Code: [Select]


// Wait for data
HAL_SPI_Receive(&SLAVE_SPI_HANDLE, slave_rcv_buffer, 1, HAL_MAX_DELAY);

// Data received

println("Data received: 0x%X", slave_rcv_buffer[0]);
uint8_t addr = slave_rcv_buffer[0] >> 4;
uint8_t data = slave_rcv_buffer[0] & 0xF;
println("Address: %d", addr);
println("Data: %d", data);

// was the data for me?
if (slave.address != addr) {
// It was not, set all my outputs to 0
} else {
// It was, set my outputs accordingly

My question:
Do yall know any way to sync the master board with the slave boards?

I was thinking in using 3 I/O lines to indicate the slave address the data is meant to (this way i can address up to 8 slave boards), and then send the data. Maybe I can even use an specific pattern to reset all slave boards. The slaves can 'see' the address I/O changing and get ready to get the data.

But i haven't time to test this, maybe you know a better way to do it?

All boards use an STM32 microcontroller if that matters.



Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 2150
  • Country: ca
Re: Sync Master board with 5 Slave boards with 5 I/O's
« Reply #1 on: February 23, 2019, 12:12:27 am »
Your method is Ok. Implementation is the problem. Can't tell what exactly. May be you use an incorrect SPI mode. If lines are too long, this might be the problem as well.


Code: [Select]

doesn't look good. You may be waiting at the very moment you need to be receiving data. I would remove the delay as it doesn't serve any purpose:

Code: [Select]

Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo