775 views|1 replies

1

Posts

0

Resources
The OP
 

Based on STM32F103, the first two levels of the TM03 capacitive displacement sensor are always high. [Copy link]

This post was last edited by Bai Xiaocai on 2024-2-19 16:25

When I was learning to use STM32 to read the displacement value, I found that the first two levels were always 1 no matter how the data changed. I changed the PB11 SCK to rising edge trigger and only the first level was 1. According to the signal timing, it should be falling edge triggered.

I don't understand it. Please help me.

In the program, I use the PB11 SCK falling edge to trigger the interrupt, and then get the PB10 SDA level signal

uint8_t BinaryDisplacementData[20];		//接收位移的二进制数据
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
	if (GPIO_Pin == GPIO_PIN_11)
	{
    GPIO_PinState pin_state = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_10);
		if (pin_state == GPIO_PIN_SET) 
			pin_state = 1;
		else 
			pin_state = 0;
		i_data++;
    //获取0-19的20位数据
    if (i_data <= 19) {
			BinaryDisplacementData[i_data-1]= pin_state;
			
    }
    else if (i_data <= 23) {
        //获取20-23的四位标志位
      data21_24[i_21_24]=pin_state;
			i_21_24++;
    }
    else
    {
		for(uint8_t i=0;i<20;i++)
		{
			TM_N_data+=BinaryDisplacementData[i]<<i;
			printf(" %d",BinaryDisplacementData[i]);
		}
      	TM_N_data = 0x00;
		memset((uint8_t *)BinaryDisplacementData,0,20);
		memset(data21_24,0,4);
		i_data = 0x00;
		i_21_24=0x00;	
    }
  }
}

PB11 SDA IO configuration is falling edge trigger

  /*Configure GPIO pins : PBPin PBPin PB11 */
  GPIO_InitStruct.Pin = OK_Button_Pin|R_Button_Pin|GPIO_PIN_11;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pin : PB10 */
  GPIO_InitStruct.Pin = GPIO_PIN_10;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

The output shows that the first two are always 1, and the default should be 0.


Using an oscilloscope to check the signal, there is no problem. The upper one is SCK and the lower one is SDA

This post is from stm32/stm8

Latest reply

No matter how the data changes, it is always 1 when read. There is a high probability that there is a problem with the hardware circuit   Details Published on 2024-2-20 07:46
 

6593

Posts

0

Resources
2
 

No matter how the data changes, it is always 1 when read.

There is a high probability that there is a problem with the hardware circuit

This post is from stm32/stm8
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list