Skip to main content
JPhan.1
Associate
Jun 14, 2021 11:01 PM UTC
Solved

The chip-selected pin goes high even set low during SPI transition

Hello Group,

I am reading SPI from the Nucleo STM#@F401RE with the ST accelerometer LIS2DW12. I set the chip-selected pin low during the transition, but I saw the selected pin go high.

How I fix this problem?

Thanks a lot for your time,

Jack

void readId()

{

      uint8_t bufp[1];

      uint8_t reg = LIS2DW12_WHO_AM_I;

      reg |= 0x80;

      HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);

      HAL_SPI_Transmit(&hspi2, &reg, 1, 1000);

      HAL_SPI_Receive(&hspi2, bufp, 1, 1000);

      HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);

}

 0693W00000Bay6FQAR.png

This topic has been closed for replies.
JPhan.1
JPhan.1Best answer
Associate
Jun 15, 2021 9:36 PM UTC

Hello Group,

I found my problem.

My logic analyzer ground connection is loose and that causes this problem.

I put here the correct result.

Thanks,

Jack

6 replies

TDK
Jun 14, 2021 11:56 PM UTC

Is CS_up configured as a GPIO output pin?

Break it down to where you can toggle the pin successfully, then add in the SPI transfer.

"If you feel a post has answered your question, please click ""Accept as Solution""."
JPhan.1
JPhan.1Author
Associate
Jun 15, 2021 12:12 AM UTC

Yes, set the chip-selected pin as GPIO output and control it.

During the transition, I set it low, but I see a glitch that goes high. So what is the problem causes this.

Thanks,

Jack

TDK
Jun 15, 2021 12:17 AM UTC
Nothing wrong with the code that you've shown. Either you're monitoring the wrong pin, or it's not set up correctly, or something else is controlling it.
"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
Jun 15, 2021 6:39 AM UTC

I don't quite understand the Cube gibberish, but maybe you want to use HAL_SPI_TransmitReceive() instead of those two separate functions.

JW

JPhan.1
JPhan.1AuthorBest answer
Associate
Jun 15, 2021 9:36 PM UTC

Hello Group,

I found my problem.

My logic analyzer ground connection is loose and that causes this problem.

I put here the correct result.

Thanks,

Jack

JPhan.1
JPhan.1Author
Associate
Jun 15, 2021 9:37 PM UTC

0693W00000Bb5OQQAZ.png