cancel
Showing results for 
Search instead for 
Did you mean: 

SPI communication between STM32F427 (Master) and STM32WB55 (Slave)

olope.1
Associate

Hi everyone,

I used this two MCU with freertos.

What i want to do :

-The master send data to the slave

-The slave respond with some data

What i've already done:

I succeeded to send the data to the slave.

For that i used DMA on master and DMA on the slave.

It's work fine, I was up to a request every 100 ms without error.

Now i've activate receive DMA on master and transmit DMA on slave.

The result is that the data receive on slave are not what i've sended from the master, and the data receive on master are just only 0.

I've noticed, that on mys slave the date receive are with 2 byte in more at the beggining of the buffer.

Now, i'm juste blocked, each time i tried to send back data all the data are wrong.

Doeas anyone have any idea ?

Master Code:

void LEXAN_mdw_task(void *params)
{
    (void) params; /* -Wunused-parameter */
 
    EventBits_t events;
    UNUSED(events);
    u16 u16_cpt = 0;
    u8 u8_Flag = 0;
 
    while (1)
    {
    	HAL_Delay(2000);
    	LEXAN_driver_writeOutput(u8_Flag);
    	if(u8_Flag == 0)
    		u8_Flag = 1;
    	else
    		u8_Flag = 0;
    	MAP_write_M1(37,++u16_cpt);
    	HAL_Delay(2000);
    }
}
 
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef * hspi)
{
	if(hspi == &DISP_SPI_s_HandleStruct)
	{
		LEXAN_CS(1);
	}
}
 
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef * hspi)
{
	if(hspi == &DISP_SPI_s_HandleStruct)
	{
 
	}
}
void LEXAN_driver_writeOutput(u16 u16_typeLexan)
{
	static u16 u16_cpt38 = 0;
	static u16 u16_cpt39 = 0;
	static u16 u16_cpt40 = 0;
	static u16 u16_cpt41 = 0;
	static u16 u16_cpt42 = 0;
	static u16 u16_cpt43 = 0;
 
	memset(u8_buffTxSPI,0,sizeof(u8_buffTxSPI));
 
	u8_buffTxSPI[1] = 1;
	u8_buffTxSPI[3] = 1;
	u8_buffTxSPI[5] = 10;
 
	if(u16_typeLexan == 0)
	{
		u8_buffTxSPI[6] = 1;
		u8_buffTxSPI[8] = 1;
		u8_buffTxSPI[10] = 1;
	}
	else
	{
		u8_buffTxSPI[7] = 1;
		u8_buffTxSPI[9] = 1;
		u8_buffTxSPI[11] = 1;
	}
 
	LEXAN_CS(0);
	HAL_StatusTypeDef status = HAL_SPI_Transmit_DMA(&DISP_SPI_s_HandleStruct,u8_buffTxSPI,256);
	if( status == HAL_OK)
	{	
 
	}
	else
	{
		u16_cpt40++;
	}
	MAP_write_M1(38,u16_cpt38);
	MAP_write_M1(39,u16_cpt39);
	MAP_write_M1(40,u16_cpt40);
	MAP_write_M1(41,u16_cpt41);
	MAP_write_M1(42,u16_cpt42);
	MAP_write_M1(43,u16_cpt43);
	HAL_Delay(1);
}
 

Slave Code:

void COM_mdw_task_SPI(void *params)
{
	(void)params;
	for(;;)
	{
		switch(wTransferState)
		{
		case TRANSFER_WAIT:
		{
			memset(u8t_buffRx,44,sizeof(u8t_buffRx));
			HAL_StatusTypeDef status = HAL_SPI_Receive_DMA(&hspi1, &u8t_buffRx[0], 256);
			if(status != HAL_OK)
			{
				printf("toto");
			}
			else
			{
				wTransferState = TRANSFERING;
			}
		}
			break;
		case TRANSFERING:
			break;
		case TRANSFER_COMPLETE:
			wTransferState = TRANSFER_WAIT;
 
			if(u8t_buffRx[1] == 1)
			{
				if (u8t_buffRx[5] == 10)
				{
					cptOk++;
					MAP_write_Q1(Q1_LED_LEXAN_LOCAL_INDEX,u8t_buffRx[6]);
					MAP_write_Q1(Q1_LED_LEXAN_DEFAUT_INDEX,u8t_buffRx[7]);
					MAP_write_Q1(Q1_LED_LEXAN_MARCHE_V_INDEX,u8t_buffRx[8]);
					MAP_write_Q1(Q1_LED_LEXAN_MARCHE_R__INDEX,u8t_buffRx[9]);
					MAP_write_Q1(Q1_LED_LEXAN_ARRET_V__INDEX,u8t_buffRx[10]);
					MAP_write_Q1(Q1_LED_LEXAN_ARRET_R_INDEX,u8t_buffRx[11]);
 
					//HAL_Delay(2);
					//COM_spi_drv_send(cptError1,cptError2);
				}
				else
				{
					printf("Pb");
					cptError1++;
				}
			}
			else
			{
				printf("Toto");
				cptError2++;
			}
			break;
		case TRANSFER_ERROR:
			wTransferState = TRANSFER_WAIT;
			break;
		}	}
}
 
void DMA1_Channel2_IRQHandler(void)
{
  /* USER CODE BEGIN DMA1_Channel2_IRQn 0 */
 
  /* USER CODE END DMA1_Channel2_IRQn 0 */
  HAL_DMA_IRQHandler(&hdma_spi1_rx);
  /* USER CODE BEGIN DMA1_Channel2_IRQn 1 */
 
  /* USER CODE END DMA1_Channel2_IRQn 1 */
}
 
void DMA1_Channel3_IRQHandler(void)
{
  /* USER CODE BEGIN DMA1_Channel2_IRQn 0 */
 
  /* USER CODE END DMA1_Channel2_IRQn 0 */
  HAL_DMA_IRQHandler(&hdma_spi1_tx);
  /* USER CODE BEGIN DMA1_Channel2_IRQn 1 */
 
  /* USER CODE END DMA1_Channel2_IRQn 1 */
}
 
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef * hspi)
{
	printf("toto");
	wTransferState = TRANSFER_COMPLETE;
//	COM_spi_drv_send(cptError1,cptError2);
}
 
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef * hspi)
{
	printf("toto");
}
//
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi)
{
  wTransferState = TRANSFER_ERROR;
}
 
void COM_spi_drv_send(uint8_t cptError1,uint8_t cptError2)
{
	static u8 u8_cptSend = 0;
	memset(u8_buffTx,0,sizeof(u8_buffTx));
	u8_buffTx[1] = 2;
	u8_buffTx[3] = 0;
	u8_buffTx[5] = 23;
 
	u8_buffTx[6] = MAP_read_I1(I1_INPUT_BP1_INDEX);
	u8_buffTx[7] = MAP_read_I1(I1_INPUT_BP2_INDEX);
	u8_buffTx[8] = MAP_read_I1(I1_INPUT_BP3_INDEX);
	u8_buffTx[9] = MAP_read_I1(I1_INPUT_BP4_INDEX);
 
	u8_buffTx[10] = MAP_read_I1(I1_INPUT_BP5_INDEX);
	u8_buffTx[11] = MAP_read_I1(I1_INPUT_1_INDEX);
	u8_buffTx[12] = MAP_read_I1(I1_INPUT_2_INDEX);
	u8_buffTx[13] = MAP_read_I1(I1_INPUT_3_INDEX);
 
	u8_buffTx[14] = MAP_read_I1(I1_INPUT_4_INDEX);
	u8_buffTx[15] = MAP_read_I1(I1_INPUT_5_INDEX);
	u8_buffTx[16] = MAP_read_I1(I1_INPUT_6_INDEX);
	u8_buffTx[17] = MAP_read_I1(I1_INPUT_7_INDEX);
 
	u8_buffTx[18] = MAP_read_I1(I1_INPUT_8_INDEX);
	u8_buffTx[19] = MAP_read_I1(I1_INPUT_9_INDEX);
	u8_buffTx[20] = MAP_read_I1(I1_INPUT_10_INDEX);
	u8_buffTx[21] = MAP_read_I1(I1_INPUT_11_INDEX);
 
	u8_buffTx[22] = MAP_read_I1(I1_INPUT_12_INDEX);
	u8_buffTx[23] = MAP_read_I1(I1_INPUT_13_INDEX);
	u8_buffTx[24] = MAP_read_I1(I1_INPUT_14_INDEX);
	u8_buffTx[25] = MAP_read_I1(I1_INPUT_15_INDEX);
	u8_buffTx[26] = u8_cptSend;
	u8_buffTx[27] = cptError1;
	u8_buffTx[28] = cptError2;
 
	HAL_StatusTypeDef status = HAL_SPI_Transmit_DMA(&hspi1, u8_buffTx, 256);
	if(status != HAL_OK)
	{
		u8_cptSend++;
		printf("toto");
	}
	else
		printf("toto");
 
 
}

Thanks for the reading, and have a nice day.

0 REPLIES 0