cancel
Showing results for 
Search instead for 
Did you mean: 

spi problem with interrupt

Ali Yazdanifar
Associate II
Posted on July 05, 2018 at 16:53

Hi every one I have problem in spi communication , I want to Send and

Receive

data with loopback(mosi connects to miso) in stm32f103c8t6 by interrupt . I set this settings in stm32cube : clock 8m, prescaler 128 ,,,....... 

in IDE I use this code:

.

.

.

uint8_t tx[13]={'aliyazdanifar'};

uint8_t rx[13];

HAL_StatusTypeDef a,b;

.

.

void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)

{

while(1);

}

void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)

{

}

.

.

.

a=HAL_SPI_Receive_IT(&spi1,rx,13);

b=HAL_SPI_Transmit_IT((&spi1,tx,13);

.

.

while(1)

{}

when I debug this code ,I have (a=hal_ok,b=hal_busy,) and spi is not work.

What should I doØŸ

3 REPLIES 3
T J
Lead
Posted on July 06, 2018 at 01:01

HAL_SPI_Receive_IT(&spi1,rx,13);   // this will force 13 bytes to be clocked into the SPI1Rx buffer,

So now, I guess the HAL unit is busy. clocking in 13 bytes..

then you run this: HAL_SPI_Transmit_IT((&spi1,tx,13)

? I guess you are waiting for the receive to finish before you can transmit.

Posted on July 06, 2018 at 01:32

if you had 2 SPI ports, one set to master and one set to slave.

take the master clock to the slave clock,

take MOSI from master to MISO of Slave,

then run you existing code, both DMAs should work.

Posted on July 06, 2018 at 09:44

yes, your saying is correct , but the same of this code runs correctly for uart , but about spi does not work . that's a surprise for me