2018-12-12 10:45 PM
Hello.
I've been using STM MCU's for quite a long time now and I'm fortunate to use a wide range of series which includes F0,F1 and F2. F2 is my personal favorite.
While using them I've come across some discrepancies while using the standard peripheral library's SPI source file.
Note: I was using the updated Peripheral library which was updated on the company's website.
I interfaced a slave device (EEPROM) with STM32F071 and the same slave with STM32F101VcT6.
The clock configurations and the SPI speed is same in both the codes.
In F0 I use the following code to send data to the Slave device.
SPI1 -> DR = Data;
while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_BSG));
Now by sending commands with the above code my slave device gives a proper response on the MCU's MISO line. However, the same code doesn't work for F1. If I use the same SPI send function which I've used above there is no response on the MISO line.
After few hours I modified the sending data function in F1 with this :
SPI1 -> DR = Data;
while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_BSG));
while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_RXNE) != SET);
return SPI1->DR;
After this modification the slave is giving proper responses to the Commands which are sent to it.
Is this problem related to the SPI slave or the way in which I'm handling the SPI standard peripheral library?
I also changed the SPI slave (FLASH chip instead of EEPROM). Still the same output.
Please give me some insight in this.
Best Regards,
Nishit.
2018-12-13 12:28 AM
Hi there,
First, it is not clear from your post if you are using for each family the corresponding SPL, i.e. SPL_F0 and SPL_F1.
Second, you don't seem to use the actual SPL functions for the SPI, i.e. SPI_SendData8() or SPI_I2S_SendData16().
Last, I am not sure the SPI peripheral is the same between F1 and F0, which would explain why your code differs between the 2.
Also from your code snippet, is Data 16 bits or 8 bits ?
2018-12-13 02:20 AM
Hello Kraal.
> Yes, I'm using the same SPI ie SPI1 in both F0 and F1.
> Yes, I'm using the SPI_SendData8() routines of the standard peripheral library. In the snippet I pasted the code which is present inside this routine.
> What do you mean by the third question? In what ways an SPI peripheral can differ between a microcontroller family?
> The data is 8 bits.
Regards,
Nishit.
2018-12-13 07:37 AM
Hello,
You misread my first question, there are standard peripheral libraries for each families (well the one that existed before HAL).
The F1 family is the oldest, so the SPI inside might be different from the one in the F0 families. In the F0 writing as you do to SPI->DR without a cast will send 16 bits on the bus, not 8. I don't know for the F1.
The snippet you show seems to be for the F1 family as it does not have the *(uint8_t *) cast before SPI->DR.
2018-12-13 08:32 PM
Hello.
Okay so you suggest that the Controller would be sending 16 bits instead of 8 to the slave and that's the reason the slave was behaving differently?
I do not think this is the case because I monitored the MOSI line too while the data was being sent. It was 8 bits.
Also I had such discrepancy while using STM of the same family ie STM32F101VcT6 and STM32F101RcT6. Here also the SPL used was same but the slave responded differently as mentioned above.
And I did not use SPL for a particular STM family. Instead, I used SPL which had libraries for all the STM families separated by #define Preprocessor.
Best,
Nishit.
2018-12-13 11:04 PM
Hi again,
Thank you for the answers. I am quite sure about the F0 sending 16 bits when accessing DR directly, monitoring MOSI alone is not enough, adding SCK and CS to the picture would help better.
Where did you find the multifamily SPL ? I can't find it on the STM website.
Now having discrepancy between 2 F101 is quite odd for sure... I don't have any other ideas, sorry.