2018-04-18 11:10 PM
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?
2018-04-19 12:30 PM
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