Example description
I2C_10bitAddress
Example Description
This example provides a description of how to transfer a data buffer from I2C1 to
I2C2 in 10-bit addressing mode.
After enabling the two I2C peripherals, the transfer in 10-bit addressing mode
starts after the I2C1 start condition is generated. Each time an event occurs on
the master or the slave, it is managed on I2C1 or I2C2, respectively.
In this application, Tx_Buffer is transmitted from the master I2C1 to the slave
I2C2 and stored into Rx_Buffer. The transmitted and received buffers are compared
to check that all data have been correctly transferred.
The communication clock speed is set to 300KHz.
Directory contents
- I2C/10bitAddress/stm32f10x_conf.h Library Configuration file
- I2C/10bitAddress/stm32f10x_it.c Interrupt handlers
- I2C/10bitAddress/stm32f10x_it.h Interrupt handlers header file
- I2C/10bitAddress/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210E-EVAL (STM32F10x
High-Density) and STM3210B-EVAL (STM32F10x Medium-Density) evaluation boards
and can be easily tailored to any other supported device and development
board.
This example can't be tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity-Line) evaluation board since the I2C2 pins (PB10 and PB11) are
already used by Ethernet PHY module.
- STM3210E-EVAL Set-up
- Connect I2C1 SCL pin (PB.06) to I2C2 SCL pin (PB.10)
- Connect I2C1 SDA pin (PB.07) to I2C2 SDA pin (PB.11)
- Check that a pull-up resistor is connected on one I2C SDA pin
- Check that a pull-up resistor is connected on one I2C SCL pin
- STM3210B-EVAL Set-up
- Connect I2C1 SCL pin (PB.06) to I2C2 SCL pin (PB.10)
- Connect I2C1 SDA pin (PB.07) to I2C2 SDA pin (PB.11)
- Check that a pull-up resistor is connected on one I2C SDA pin
- Check that a pull-up resistor is connected on one I2C SCL pin
note The pull-up resitors are already implemented on the STM3210B-EVAL and
STM3210E-EVAL evaluation boards.
How to use it ?
In order to make the program work, you must do the following :
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_i2c.c
- stm32f10x_rcc.c
- stm32f10x_gpio.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity-line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
I2C_DualAddress
Example Description
This example provides a description of how to transfer two data buffer from I2C1
to I2C2 using its both addresses in the same application.
The example consist in two parts:
1. First step, the I2C1 master transmitter sends the Tx_Buffer1 data buffer to the
slave I2C2 which saves the received data in Rx_Buffer1. I2C2 is addressed in
this case by its first slave address I2C2_SLAVE1_ADDRESS7 programmed in the
I2C2 OAR1 register.
The transmitted and received buffers are compared to check that all data
have been correctly transferred.
2. Second step, the I2C2 is now addressed by its second slave address
I2C2_SLAVE2_ADDRESS7 programmed in the I2C2 OAR2 register. The Tx_Buffer2
contents are transmitted by the master I2C1 to the slave I2C2 which stores
them into Rx_Buffer2.
A second comparison takes place between the transmitted and received buffers.
The communication clock speed is set to 200KHz.
Directory contents
- I2C/DualAddress/stm32f10x_conf.h Library Configuration file
- I2C/DualAddress/stm32f10x_it.c Interrupt handlers
- I2C/DualAddress/stm32f10x_it.h Interrupt handlers header file
- I2C/DualAddress/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210E-EVAL (STM32F10x
High-Density) and STM3210B-EVAL (STM32F10x Medium-Density) evaluation boards
and can be easily tailored to any other supported device and development
board.
This example can't be tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity-Line) evaluation board since the I2C2 pins (PB10 and PB11) are
already used by Ethernet PHY module.
- STM3210E-EVAL Set-up
- Connect I2C1 SCL pin (PB.06) to I2C2 SCL pin (PB.10)
- Connect I2C1 SDA pin (PB.07) to I2C2 SDA pin (PB.11)
- Check that a pull-up resistor is connected on one I2C SDA pin
- Check that a pull-up resistor is connected on one I2C SCL pin
- STM3210B-EVAL Set-up
- Connect I2C1 SCL pin (PB.06) to I2C2 SCL pin (PB.10)
- Connect I2C1 SDA pin (PB.07) to I2C2 SDA pin (PB.11)
- Check that a pull-up resistor is connected on one I2C SDA pin
- Check that a pull-up resistor is connected on one I2C SCL pin
note The pull-up resitors are already implemented on the STM3210B-EVAL and
STM3210E-EVAL evaluation boards.
How to use it ?
In order to make the program work, you must do the following :
- Create a project and setup all project configuration
- Add the required Library files :
- stm32f10x_i2c.c
- stm32f10x_rcc.c
- stm32f10x_gpio.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity-line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
I2C_EEPROM
Example Description
This example provides a basic example of how to use the I2C software library and
an associate I2C EEPROM driver to communicate with an I2C EEPROM device (here the
example is interfacing with M24CXX EEPROMs where XX={01, 02, 04, 08, 16, 32, 64}.
I2C peripheral is configured in Master transmitter during write operation and in
Master receiver during read operation from I2C EEPROM.
The peripheral used is I2C1 but can be configured by modifying the defines values
in i2c_ee.h file. The speed is set to 200kHz.
For E24C02 to E24C16 devices, one I2C EEPROM Block address where the program will
write the buffer have to be selected from the four address available and defined
in the i2c_ee.h file.
For E24C32 and E24C64 devices all the memory is accessible through the two-bytes
addressing mode and need to define block addresses. In this case, only the physical
address has to be defined (according to the address pins (E0,E1 and E2) connection).
This address is defined in i2c_ee.h (default is 0xA0: E0, E1 and E2 tied to ground).
The EEPROM addresses where the program start the write and the read operations
is defined in the main.c file.
First, the content of Tx1_Buffer is written to the EEPROM_WriteAddress1 and the
written data are read. The written and the read buffers data are then compared.
Following the read operation, the program wait that the EEPROM reverts to its
Standby state. A second write operation is, then, performed and this time, Tx2_Buffer
is written to EEPROM_WriteAddress2, which represents the address just after the last
written one in the first write. After completion of the second write operation, the
written data are read. The contents of the written and the read buffers are compared.
Directory contents
- I2C/EEPROM/stm32f10x_conf.h Library Configuration file
- I2C/EEPROM/stm32f10x_it.c Interrupt handlers
- I2C/EEPROM/stm32f10x_it.h Interrupt handlers header file
- I2C/EEPROM/main.c Main program
- I2C/EEPROM/i2c_ee.c I2C EEPROM driver
- I2C/EEPROM/i2c_ee.h Header for the i2c_ee.c file
Hardware and Software environment
- This example runs on STM32F10x High-Density, STM32F10x Medium-Density,
STM32F10x Low-Density and STM32F10x Connectivity-Line devices.
- This example has been tested with STM3210C-EVAL (STM32F10x Connectivity-Line)
evaluation board (implemented EEPROM is E24C64) with no additional hardware.
This example has also been tested with STMicroelectronics STM3210E-EVAL
(STM32F10x High-Density) and STM3210B-EVAL (STM32F10x Medium-Density) evaluation
boards with addition of the hardware connection listed below, and can be easily
tailored to any other supported device and development board.
- STM3210C-EVAL Set-up
- Make sure the Jumper JP9 "I2C_SCK" is connected on the board.
- For write operations, make sure the jumper JP17 "ROM_WP" is connected on the
board (If this jumper is not connected, the EEPROM will be write-protected).
- No additional Hardware connections are needed.
- STM3210E-EVAL, STM3210B-EVAL or any other platform Set-up
- Connect I2C1 SCL pin (PB.06) to I2C EEPROM SCL (pin6)
- Connect I2C1 SDA pin (PB.07) to I2C EEPROM SDA (pin5)
- Check that a pull-up resistor (4.7K) is connected on one I2C SDA pin
- Check that a pull-up resistor (4.7K) is connected on one I2C SCL pin
- Connect I2C EEPROM Vcc (pin8) to Vdd
- Connect I2C EEPROM Vss (pin4) to Vss
- For E24C08: Connect I2C EEPROM E2 (pin1) to Vss for E24C08
- For E24C64/E24C32: Connect I2C EEPROM E0, E1 and E2 (pin1, pin2 and pin3) to Vss
note The pull-up resitors are already implemented on the STM3210B-EVAL and
STM3210E-EVAL evaluation boards.
How to use it ?
In order to make the program work, you must do the following :
- Create a project and setup all project configuration
- Add the required Library files :
- stm32f10x_i2c.c
- stm32f10x_rcc.c
- stm32f10x_gpio.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity-Line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
I2C_Interrupt
Example Description
This example provides a description of how to manage data transfer from
master transmitter to slave receiver and from slave transmitter to master receiver
using interrupts.
After enabling the two I2C peripherals, both event and buffer interrupts for
I2C1 and I2C2 and error interrupt for I2C2, the transfer in 7-bit addressing
mode starts after I2C1 start condition generation.
First, the master transmitter I2C1 send I2C1_Buffer_Tx data buffer to the
salve receiver I2C2. Data received by I2C2 is stored in I2C2_Buffer_Rx buffer.
Each time an event occurs on the master or the slave, it is managed in the I2C1
or I2C2 interrupts routines, respectively.
The PEC value is also transmitted from master transmitter to slave receiver and
it is stored in the same reception buffer I2C2_Buffer_Rx.
The transmitted and received buffers are compared to check that all data have
been correctly transferred (except the PEC value). This transfer status is stored
in TransferStatus1 variable.
Once the Re-Start condition is sent, thus the second step is started and the
I2C2_Buffer_Tx will be sent from the slave transmitter I2C2 to be recieved by
the master receiver I2C1 and stored in I2C1_Buffer_Rx.
Each time an event occurs on the master or the slave, it is managed in the I2C1
or I2C2 interrupts routines, respectively.
The transmitted and received buffers are compared to check that all data have been
correctly transferred. This transfer status is stored in TransferStatus2 variable.
The communication clock speed is set to 200KHz.
Directory contents
- I2C/Interrupt/stm32f10x_conf.h Library Configuration file
- I2C/Interrupt/stm32f10x_it.c Interrupt handlers
- I2C/Interrupt/stm32f10x_it.h Interrupt handlers header file
- I2C/Interrupt/main.h Main header file
- I2C/Interrupt/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210E-EVAL (STM32F10x
High-Density) and STM3210B-EVAL (STM32F10x Medium-Density) evaluation boards
and can be easily tailored to any other supported device and development
board.
This example can't be tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity-Line) evaluation board since the I2C2 pins (PB10 and PB11) are
already used by Ethernet PHY module.
- STM3210E-EVAL & STM3210B-EVAL Set-up
- Connect I2C1 SCL pin (PB.06) to I2C2 SCL pin (PB.10)
- Connect I2C1 SDA pin (PB.07) to I2C2 SDA pin (PB.11)
- Check that a pull-up resistor is connected on one I2C SDA pin
- Check that a pull-up resistor is connected on one I2C SCL pin
The pull-up resitors are already implemented on the STM3210B-EVAL and
STM3210E-EVAL evaluation boards.
How to use it ?
In order to make the program work, you must do the following :
- Create a project and setup all project configuration
- Add the required Library files :
- stm32f10x_i2c.c
- stm32f10x_rcc.c
- stm32f10x_gpio.c
- misc.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity-line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
I2C_SMBus
Example Description
This example provides a description of how to send an ARP command from I2C1 to
I2C2 in SMBus mode.
After configuring the I2C1 and I2C2 as SMBus Host and Device, respectively, both
I2Cs are enabled. The PEC calculation is enabled for both I2Cs.
The ARP capability is enabled for the slave I2C2. Following the start condition
generation, the master I2C1 sends the SMBus default header and I2C2 responds by
setting its SMBDEFAULT flag. The master I2C1 then issues the "Prepare to ARP"
command to the slave I2C2. PEC transfer is then enabled for both I2Cs, and the
PEC value received on I2C2 is stored into the PEC_Value variable.
A correct transmission leads to obtaining the following variable values:
- Status = 0x01 (the flag SMBDEFAULT has been set)
- ReceivedCommand = 0x01 (the Command value has been correctly received)
The communication clock speed is set to 20KHz.
Directory contents
- I2C/SMBus/stm32f10x_conf.h Library Configuration file
- I2C/SMBus/stm32f10x_it.c Interrupt handlers
- I2C/SMBus/stm32f10x_it.h Interrupt handlers header file
- I2C/SMBus/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210E-EVAL (STM32F10x
High-Density) and STM3210B-EVAL (STM32F10x Medium-Density) evaluation boards
and can be easily tailored to any other supported device and development
board.
This example can't be tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity-Line) evaluation board since the I2C2 pins (PB10 and PB11) are
already used by Ethernet PHY module.
- STM3210E-EVAL Set-up
- Connect I2C1 SCL pin (PB.06) to I2C2 SCL pin (PB.10)
- Connect I2C1 SDA pin (PB.07) to I2C2 SDA pin (PB.11)
- Check that a pull-up resistor is connected on one I2C SDA pin
- Check that a pull-up resistor is connected on one I2C SCL pin
- STM3210B-EVAL Set-up
- Connect I2C1 SCL pin (PB.06) to I2C2 SCL pin (PB.10)
- Connect I2C1 SDA pin (PB.07) to I2C2 SDA pin (PB.11)
- Check that a pull-up resistor is connected on one I2C SDA pin
- Check that a pull-up resistor is connected on one I2C SCL pin
note The pull-up resitors are already implemented on the STM3210B-EVAL and
STM3210E-EVAL evaluation boards.
How to use it ?
In order to make the program work, you must do the following :
- Create a project and setup all project configuration
- Add the required Library files :
- stm32f10x_gpio.c
- stm32f10x_i2c.c
- stm32f10x_rcc.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity-line devices are STM32F105xx and STM32F107xx microcontrollers.