cancel
Showing results for 
Search instead for 
Did you mean: 

CMSIS SPI Driver wait forever in SendData function

b_
Associate II
Posted on February 11, 2014 at 14:00

Hi all,

I'm trying to use the SPI interface on a STM32F207 with CMSIS. Below you my sample code can be seen. The problem there is that within the function drv_Info->SendData(...) the function waits for the semaphore_busy but it somewhere hold and never released and therfore the function waits there forever. How can I make the SendData(..) function work? Is my code correct? Every hint is very welcome Benjamin

void th_SPI (void const *argument){
ARM_SPI_STATUS status;
ARM_DRV_VERSION version;
ARM_SPI_CAPABILITIES drv_capabilities;
uint32_t busSpeed;
uint8_t sendData[3];
uint32_t cr1;
sendData[0] = 16;
sendData[1] = 24;
sendData[2] = 144;
drv_info = &Driver_SPI1;
status = drv_info->Initialize(spiSignalCB);
status = drv_info->PowerControl(ARM_POWER_FULL);
SPI1->CR2 |= SPI_CR2_SSOE; //enable SlaveSelect
SPI1->CR1 |= SPI_CR1_MSTR; //necessary to enable Master Mode
status = drv_info->Configure(ARM_SPI_CPOL1_CPHA1,ARM_SPI_MSB_LSB); //clk polarity and phase see Reference manual and ad7794 datasheet
busSpeed = drv_info->BusSpeed(1e4);
drv_info->SlaveSelect(ARM_SPI_SS_ACTIVE);
status = drv_info->SendData(sendData,3);
if(status == ARM_SPI_ERROR){
status ++;
}
}

#spi #cmsis #stm32
5 REPLIES 5
Posted on February 11, 2014 at 14:05

I don't know anything about the CMSIS drivers, but if the peripheral is non-responsive, I'd start by checking if it's clock is correctly enabled.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
troy1818
Senior
Posted on February 12, 2014 at 10:40

I would make sure too look at the status variable for any errors.

Also, try and initialize it like they do:

http://www.keil.com/pack/doc/CMSIS/Driver/html/index.html

Regards,

/rygelxvi
b_
Associate II
Posted on February 13, 2014 at 13:45

Thank you for your comments.

I have checked the registers and saw that SPI1EN on APB2ENR and GPIOAEN on AHB1ENR has been set.

Has there anything more to be set?

I think the problem aren't the registers, it's more the mentioned semaphore which doesn't get released.

jtrexr2
Associate
Posted on February 17, 2014 at 16:25

I'm having the exact same problem, and I'm connected to an Aardvark SPI emulator device (slave mode). I get stuck on the same semaphore busy flag. 

I tried instead calling the TransferByte(byte) command to just send a single byte, which doesn't appear to use that semaphore. In the spi code, this function places the data in the outgoing data register then waits for a response, which it never receives. However, when I debug and step through each line, the line where the data is placed in the outgoing register: 

ptr_spi->spi->DR = out;

The ''DR'' remains 0x0000, whereas ''out'' is 0x41 (''A''). Since the ''DR'' doesn't appear to even change, the SPI subsystem doesn't send anything and thus doesn't receive anything. I encourage you to try this TransferByte function instead and see what you get.

davide2
Associate
Posted on February 12, 2015 at 12:08

Hi All

i'm stuck with the same problem.

Did anyone solve it?

thanks

Davide