i2c


Configuring STM32 output ports for I2C


I am currently trying to get a pair of stm32l152 (discovery kit) to communicate via I2C. (i am not using the standard peripheral library provided by STM as i want to try to implement the i2c myself..)
My configuration is as followed:
7-bit addressing mode (no dual address, only OAR1)
100khz speed
ACK enabled (on slave)
ACK disabled (on master, since only 1 byte is transferred between master/slave at any time)
on both master/slave, using GPIOB (PB10) as SCL and GPIOB (PB11) as SDA
Here's the weird part: when i configure the 2 GPIOB pins as push-pull (no pullup/down), i am able to see my master send out the start bit, address byte.. on the oscilloscope.
But my slave is not sending back an acknowledgement. i know this for sure because the master did not assert ADDR bit in SR1, i see no ack on the scope and also the slave did not go into interrupt ( i enabled I2C event interrupt on the slave).
on closer look at the waveform on the scope, i realised the signal (both SCL, SDA) did not fully go to 0Volts for logic low, they are at 1 volts instead. i am guessing this maybe why the slave cannot read the address byte from the master and therefore did not send back ack.
So i configure the 2 GPIO pins to be open-drain (no pullup/down)..but now my master cannot send out the start bit.. i step through the code and saw that the master's SB bit in SR1 is set when i set the START bit.. but i do not see the any response on the SDA and SCL signals on the scope (both are high at 3V).
(i pulled both SCL and SDA to 3v using 10kohms on each line).
ok, i think i found the answer.. I looked up the standard peripheral library provided by STM and followed their configuration sequence. Before that, i was using the wrong sequence of configuring the GPIO ports...
The sequence tested to be working is:
Enable i2c and GPIOs clocks.
Configure the desired AF of the ports. (AF4 for i2c in stm32).
Configure GPIOs:
3a. set GPIOs as AF.
3b. set port speed.
3c. set port type (open-drain).
3d. set to no pull-up/pull-down.
Configure i2c. (registers CR2, CCR, CR1, OAR1, ...).
Previously, i was doing step 3 BEFORE step 2, and there is no output from the ports when i generated the START bit.
Hope this helps those who have the same problem.

Related Links

Re: I2C, what does “clocked out” mean?
interpreting i2c register map for ISL12022
I2C repeated start
what is better using while loop or if statement when checking status codes of atmega 32?
Atmega64A pins SCL/SDA no respond
atmega64 I2c ds3231 not responding
Sending double through I2C from Arduino Pro Mini to ESP8266
Texas Instruments DS92LX1621/2
How do you adjust an I2C driver to handle smbus specs?
I2C Communication between 2 Beaglebone black
MUX channels not needed, how to wire?
I2C clock stretching details
comunication from stm32 Nucleo L152RE and shield x-nucleo IKS01A1 with protocol I2C and DMA
NACK and ACK responses on I2c bus
SH72867 with I2C
Not ACK bit in the AT24C512C EEPROM Read operation via I2C connection

Categories

HOME
sharepoint
sql-server-2008
swift
visual-studio-2015
converter
crystal-reports
warnings
avro
amazon-product-api
playframework
hana
wysiwyg
nuxt.js
pyyaml
anychart
ms-access-2007
aws-cognito
jni
sql-update
bcrypt
pdfsharp
compare-and-swap
mef2
excel-2013
unpack
gzip
bxslider
hibernate-cache
lmdb
hotmail
geopy
ocs
mmdrawercontroller
broadleaf-commerce
nodeclipse
redhat-datavirt
poco-libraries
silverlight-3.0
alchemy.js
tic-tac-toe
cross-entropy
bayesian-networks
stdclass
service-fabric-stateful
homekit
automator
jenkins-jira-trigger
workflow-foundation-4.5
chrome-remote-desktop
photon-controller
mcrypt
opencpu
pdfkit
inject
metalsmith
inotifypropertychanged
mongo-c-driver
scriptlet
proxygen
loose-typing
affix
mysqldumpslow
paypal-nvp
graphical-logo
digits
scrollspy
code-first-migrations
musl
obfuscar
errorprovider
vcl
author
neoload
kraken.js
dvcs
swrl
multiple-conditions
mstsc
android-contextmenu
trailing-slash
android-4.0
dropdownlistfor
maven-ear-plugin
javascriptserializer
datarepeater
flexicious
surf
printing-web-page
msbuildextensionpack
associative
noir
sendfile
symbol-server
chatroom
asp.net-routing
recordset
file-encodings
openwysiwyg
visual-studio-2010-beta-2
dotproject

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App