Sync Master board with 5 Slave boards with 5 I/O's - Page 1
Forum section: electronics / general

author: ShowKemp
author_rank: Contributor
timestamp: February 22, 2019, 11:36:24 pm
content: Hi,I'm working on a already done circuit, let's call itMaster,Masterhave 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 boards1. 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: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 dataHAL_SPI_Receive(&SLAVE_SPI_HANDLE, slave_rcv_buffer, 1, HAL_MAX_DELAY);// Data receivedHAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);println("Data received: 0x%X", slave_rcv_buffer);uint8_t addr = slave_rcv_buffer >> 4;uint8_t data = slave_rcv_buffer & 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 0set_output_io(0);} else {// It was, set my outputs accordinglyset_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

author: NorthGuy
author_rank: Super Contributor
timestamp: February 23, 2019, 12:12:27 am
content: 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.This:Code:while (GPIO_PIN_RESET != HAL_GPIO_ReadPin(TEST_TRIGGER_GPIO_Port, TEST_TRIGGER_Pin)) {HAL_Delay(1);}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:while (GPIO_PIN_RESET != HAL_GPIO_ReadPin(TEST_TRIGGER_GPIO_Port, TEST_TRIGGER_Pin));