cancel
Showing results for 
Search instead for 
Did you mean: 

How can I set pb8 to SDA on stm32f103rc?

Youngmin Choi
Associate
Posted on April 19, 2018 at 08:10

I want I2C function on stm32f103rct.

pb8-> sda and pb9-> scl

I set ports configuration  like this

#define

I2C_SCL_HIGH

    GPIOB->

BSRR

=

0x00000200

   

//PB9 0x00000200 set PB9 to 1

#define

I2C_SCL_LOW

    GPIOB->

BRR

=

0x00000200

// reset PB9

#define

I2C_SDA_HIGH

    GPIOB->

BSRR

=

0x00000100

//PB8 0x00000100 set PB8 to 1

#define

I2C_SDA_LOW

    GPIOB->

BRR

=

0x00000100

// reset PB8

#define

I2C_SDA_INPUT

  (GPIOB->

IDR

&

0x00000100

)

// get PB8 is bit

#define

I2C_SDA_INPUT_MODE

 GPIOB->

CRH

&=

0x0fffffff

; GPIOB->

CRH

|=

0x00000008

//PB8 set input push-pull-up

#define

I2C_SDA_OUTPUT_MODE

GPIOB->

CRH

&=

0x0fffffff

; GPIOB->

CRH

|=

0x00000003

//PB8 output mode max speed 50Mhz */

but pb8 input is always 0.

Is there any consideration on this setting?

1 REPLY 1
Posted on April 19, 2018 at 21:30

In the last two macros, you set the lowermost 4 bits, but before that you clear the topmost 4 bits, this is probably a mistake.

JW