Skip to main content
HAlau.1
Associate II
February 11, 2020
Question

Problem in communication 2 slaves and 1 master using SPI.

  • February 11, 2020
  • 19 replies
  • 3735 views

hello everyone, I have a problem in communication 2 slaves and 1 master using SPI.

master will send a code to activate one of the slaves and then the master will receive data from the slave, but sending the initial data is always wrong and only when the reset button is pressed the sending of data becomes correct and so on.

does anyone know where the error is? and please give me a solution.

thank you

This topic has been closed for replies.

19 replies

HAlau.1
HAlau.1Author
Associate II
February 18, 2020

thank you beredindi, sorry I'm new about this, what should I do and what's the difference between soft NSS and hard NSS? Does it have to be a different type of slave and master? and this is my code in slave

 __HAL_SPI_ENABLE(&hspi4);
	 HAL_SPI_Receive (&hspi4, txslave2, 6, 50);
 
	 input=atoi((char *)txslave2);
 
	 if (input==2){
	 __HAL_SPI_ENABLE(&hspi4);
//	 HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4,GPIO_PIN_SET);
	 HAL_SPI_Transmit (&hspi4,outputBuffer2, 6, 50);
//	 HAL_SPI_Receive (&hspi4, spiRxBuf, 1, 50);
//	 HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4,GPIO_PIN_SET);
	 }

berendi
Principal
February 18, 2020

> what should I do

  • Read some textbook on communication protocols in general, and understand how SPI works, what is the function of NSS (most literature calls it CS), clock and data signals.
  • Read the SPI chapter in the reference manual carefully to understand how the SPI controller in your MCU works.
  • Get a clear idea on how can the master and the slave SPI interface is going to synchronize to each other.
HAlau.1
HAlau.1Author
Associate II
February 18, 2020

thank you @. , I understand what you're talking about, but I was confused when writing it in the master and slave program, can you give a little sample code?