cancel
Showing results for 
Search instead for 
Did you mean: 

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.

SLONK.1
Associate II

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

}

8 REPLIES 8
Amira
Associate III

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

SLONK.1
Associate II

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.

0693W00000BdAaaQAF.jpg0693W00000BdAbOQAV.jpg0693W00000BdAdPQAV.jpg

Amira
Associate III

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

SLONK.1
Associate II

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.

TDK
Guru

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?

If you feel a post has answered your question, please click "Accept as Solution".
SLONK.1
Associate II

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.

Seems very likely to be a hardware/wiring problem rather than a software issue.
If you feel a post has answered your question, please click "Accept as Solution".

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.