2020-04-06 10:51 PM
I'm trying to program i2C1 interface of STM32L151 with 3-rd side tools - Algocraft WN programmer.
The sequence of operations attached in the DOC file.
After these operations the START bit does not generated (checked by scope) and MASTER bit doesn't appear in SR1.
What am I doing wrong?
2020-04-11 08:32 AM
Looks like I found what's a problem.
After I write to GPIO port mode register (GPIOB_MODER). RST_PANEL(PB5), PB6,PB7 - Alternate function mode
write -t h40020400 -l 4 --data h0000A800 --mask h0000fc00
lines PB6 and PB7 become LOW, and the BUSY flag is set in I2C1_SR2.
The problem is that the flag remains high even after the reset by setting and release of the SWRST bit in I2C1_CR1.
After I set SWRST bit:
write -t h40005400 -l 4 --data h8000 --mask hbffb
I read the BUSY flag LOW.
But after release SWRST
write -t h40005400 -l 4 --data h0000 --mask hbffb
The flag is HIGH again.
Both lines PB6 and PB7 are in LOW state permanently after Alternate function mode definition, even during SWRST.
There are external pull up resistors on both lines (20K).
Can someone help me?
2020-04-19 04:06 AM
You need to set also the AFR register in GPIO, read GPIO chapter in Reference Manual (RM) and the AF pin table in Datasheet (DS).
JW
2020-04-19 07:05 AM
Dear JW,
Thank you.
Now after AFRL register programming at AF4 for PB6, PB7 (0x44000000), both lines are HIGH.
BUSY flag in SR2 is LOW.
But writing into CR2 register (0x00000002) (I'm using MSI clock) doesn't work. I read back 0x0 from it.
What wrong now?
2020-04-19 07:28 AM
Ok. I found the reason.
Just I put I2C1 in RESET in RCC_APB1RSTR and forgot to release it.
Now I able to program CR2, CCR and TRISE registers.
After that I set PE in CR1 (0x0001) and after that also set START bit (0x0101).
But read back only 0x0001.
2020-04-19 07:40 AM
Ok. I see. This bit cleared by hardware.
I see Start condition generated and bit SB in CR1 set.
Will continue.
Thank you very much.
2020-04-19 07:44 AM
I2Cx_CR1.START is self-clearing.
The whole I2C module is tricky, and it requires careful reading and re-reading both the narrative in I2C chapter, and the description of the registers/bits.
JW