cancel
Showing results for 
Search instead for 
Did you mean: 

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

JPhan.1
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
JPhan.1
Associate II

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

View solution in original post

6 REPLIES 6
TDK
Guru

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
Associate II

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

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".

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
Associate II

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
Associate II

0693W00000Bb5OQQAZ.png