SPI Data Register is Always 0 on my STM32F302CBTx
I have a code working on STM32L476VETx, it reads SPI data from AFE4400 Chip. Now I want to use this code on STM32F302CBTx (SPI2) but it does not work since I always get zero on data register.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-08 4:36 AM
Here is the code:
uint32_t AFE4490Read (uint8_t address){
uint32_t data = 0;
uint8_t buf[3];
HAL_GPIO_WritePin(AFE_STE_GPIO_Port, AFE_STE_Pin, LOW); // enable device
HAL_SPI_Transmit(&hspi2, &address, 1, 1000); // send address to device
HAL_SPI_Receive(&hspi2, buf, 3, 1000); // SPI.transfer (data);
data |= (((uint32_t)buf[0])<<16); // read top 8 bits data
data |= (((uint32_t)buf[1])<<8); // read middle 8 bits data
data |= ((uint32_t)buf[2]); // read bottom 8 bits data
HAL_GPIO_WritePin(AFE_STE_GPIO_Port, AFE_STE_Pin, HIGH); // disable device
return data; // return with 24 bits of read data
}
- Labels:
-
SPI
-
STM32F3 Series
-
STM32L4 series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-08 4:45 AM
Hello @SLONK.1​
For STM32 HAL SPI driers there is no a noticeable difference between L4 and F3 series.
Did you verified the configuration you used for F3 from datasheet ? ( Clock, GPIO Pins, ..)
Regards,
Amira
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-08 6:35 AM
Hello,
Thanks for your response.
Yes I verify It. In fact I just generate it with STMCubeMx software. I generate the code on STM32CubeIDE for programming and debugging.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-08 7:05 AM
Hello and thanks for sharing these details.
I have some doubts about the clock configuration. You can refer to the provided examples (SPI) within STM32F3Cube package and follow the same clock config.
It can help you!
Regards,
Amira
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-08 8:14 AM
Sir,
I'm using STMCubeMx to configure the clock. STM32F3Cube is a package as I know, How can it help me ? How to follow what you are calling "same clock config".
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-08 8:44 AM
Monitoring DR has consequences. If your debugger reads data, it won't be read by your program.
How do you know the data on the line isn't 0? Can you show a scope plot of it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-08 9:10 AM
Yes I know but when I monitor the same code on STM32L476VETx, I got data and it works fine. So I don't think it is the reason. You can check on the image the value of DR (not 0) when using it. So I think it is not the problem. For the data on the line, I don't know. May be I should find a scope to plot it; I don'h have a scope.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-08 9:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-08 10:04 AM
I see, I check with multimeter and the mean voltage on SPI_SOMI of the STM32F302CBTx is less than the one on the STM32L476VETx where the code works well. I will try to find a scope to cofirm that.
