Hi,
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:
while (GPIO_PIN_RESET != HAL_GPIO_ReadPin(TEST_TRIGGER_GPIO_Port, TEST_TRIGGER_Pin)) {
HAL_Delay(1);
}
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
// Wait for data
HAL_SPI_Receive(&SLAVE_SPI_HANDLE, slave_rcv_buffer, 1, HAL_MAX_DELAY);
// Data received
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
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
set_output_io(0);
} else {
// It was, set my outputs accordingly
set_output_io(data);
}
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.
Regards