cancel
Showing results for 
Search instead for 
Did you mean: 

simple spi on F103 have little problem

MacLaren
Associate III

hi

i use two spi and connect together

spi 1 send(Full D Master) and 2 receive(Full D slave ) all in dma

if i change send buffer, in receive first array not change. it was first init that send dma

uint8_t TXBuf[]={0,1,2,3,4,5,6,7,8,9};
uint8_t RXBuf[10];
 
int main(void)
{
 
  HAL_Init();
 
  SystemClock_Config();
 
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_SPI1_Init();
  MX_SPI2_Init();
 
  HAL_SPI_Receive_DMA(&hspi2,RXBuf,10);
 
  HAL_SPI_Transmit_DMA(&hspi1,TXBuf,10);
 
TXBuf[0]=9;
TXBuf[1]=8;
TXBuf[2]=7;
TXBuf[3]=6;
TXBuf[4]=5;
TXBuf[5]=4;
TXBuf[6]=3;
TXBuf[7]=2;
TXBuf[8]=1;
TXBuf[9]=0;
HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin);
 
	while (1)
	{
 
	}
 
}

in this code RXBuf[0]=0

TXBuf[0] one time send according to first init

other byte OK and changeable if TXBuf[1:9] change i see that in RXBuf[1:9]

1 REPLY 1
S.Ma
Principal

If the goal is to have 1 MCU as master and 1 MCU as slave and use SPI as serial interface, better jump directly with 2 real MCU boards.

What you try to do here won't be a step by step approach and actually might even be slowing you down.

Example:

Here all is sequential, all is controlled.

In real 2 MCU, you don't know when each MCU will start their code after reset, actually the one under debug surely won't sync with the other.

Then you will realize that to sync both you will need NSS and possibly EXTI as "start/stop" markers.

Take some cube nucleo example for master and slave and use 2 boards.