Skip to main content
Ali Yazdanifar
Associate II
July 5, 2018
Question

spi problem with interrupt

  • July 5, 2018
  • 1 reply
  • 852 views
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ØŸ

    This topic has been closed for replies.

    1 reply

    T J
    Senior III
    July 5, 2018
    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.

    T J
    Senior III
    July 6, 2018
    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.