Skip to main content
Youngmin Choi
Visitor II
April 19, 2018
Question

How can I set pb8 to SDA on stm32f103rc?

  • April 19, 2018
  • 1 reply
  • 650 views
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?

    This topic has been closed for replies.

    1 reply

    waclawek.jan
    Super User
    April 19, 2018
    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