Example description
I2C_EEPROM How to use the I2C to drive an EEPROM memory
Example Description
This firmware provides a basic example of how to use the I2C firmware library and
an associate I2C EEPROM driver to communicate with an I2C EEPROM device (here the
example is interfacing with M24C64 EEPROM)
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 stm322xg_eval.h file. The speed is set to 100kHz and can be configured by
modifying the relative define in stm322xg_eval_i2c_ee.h file.
For M24C64 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 stm322xg_eval_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 waits 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.
All transfers are managed in DMA mode (except when 1-byte read/write operation is
required). Once sEE_ReadBuffer() or sEE_WriteBuffer() function is called, the
use application may perform other tasks in parallel while Read/Write operation is
managed by DMA.
This example provides the possibility to use the STM322xG-EVAL LCD screen for
messages display (transfer status: Ongoing, PASSED, FAILED).
To enable this option uncomment the define ENABLE_LCD_MSG_DISPLAY in the main.c
file.
Directory contents
- I2C/EEPROM/system_stm32f2xx.c STM32F2xx system clock configuration file
- I2C/EEPROM/stm32f2xx_conf.h Library Configuration file
- I2C/EEPROM/stm32f2xx_it.c Interrupt handlers
- I2C/EEPROM/stm32f2xx_it.h Interrupt handlers header file
- I2C/EEPROM/main.c Main program
The "system_stm32f2xx.c" is generated by an automatic clock configuration
tool and can be easily customized to your own configuration.
To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.
Hardware and Software environment
- This example runs on STM32F2xx Devices.
- This example has been tested with STM322xG-EVAL RevB (with no additional
hardware), and can be easily tailored to any other development board.
- STM322xG-EVAL Set-up
- Make sure the jumper JP24 "WP" is fitted on the board.
===============================================================================
I2C_DataExchangeDMA Two boards I2C Communication: Data Exchange using DMA example
Example Description
This is a typical example of how to use the I2C firmware library to ensure the
steps of an I2C communication between slave Receiver/Transmitter and master
Transmitter/Receiver using DMA.
- Hardware Description
To use this example, you need to load it on two STM32 boards (let's call them
Board A and Board B) then connect these two boards through I2C lines and GND.
In the firmware example uncomment the dedicated line in the main.h file to use
the I2C peripheral as STM32 Master device or as STM32 Slave.
*------------------------------------------------------------------------------*
| BOARD A BOARD B |
| ____________________ ____________________ |
| | | | | |
| | | | | |
| | __________ | | __________ | |
| | |I2C Master|____|_______SDA_______|____|I2C Slave | | |
| | | Device |____|_______SCL_______|____| Device | | |
| | |__________| | | |__________| | |
| | O LD1 | | O LD1 | |
| | O LD2 RESET | | O LD2 RESET | |
| | O LD3 _ | | O LD3 _ | |
| | O LD4 |_| | | O LD4 |_| | |
| | | | | |
| | GND O--|-----------------|--O GND | |
| |____________________| |____________________| |
| |
| |
*------------------------------------------------------------------------------*
- Software Description
This example requires two boards(Master and Slave)
- Phase 1:
In master board I2C peripheral is configured in Master Transmitter with DMA
where in Slave board I2C peripheral is configured in Slave Receiver with DMA.
The master will send Data to Slave according to the defined buffer size.
- Phase 2:
In master board I2C peripheral is configured in Master Receiver with DMA,
where in Slave board I2C peripheral is configured in Slave Transmitter with
DMA.
Once the master has initiated the communication (Start condition), the slave
will send the defined data in his TxBuffer to the master.
At the end of the data transfer, a data consistency check will be performed
in master and slave sides. In case of mismatch between sent and received data,
LED2, LED3 and LED4 are OFF. Otherwise LED2, LED3 and LED4 are ON.
As the data transfers is ensured by DMA, the TxBuffer size must be equal
or greater than two bytes.
The File "I2C/I2C_TwoBoards/DataExchangeDMA/main.h" allows different possibilities
of configuration of this example:
- Addressing mode : 7-bit or 10-bit
- I2C speed: Fast mode or Standard mode
The SysTick is configured to generate an interrupt each 10ms. A dedicated counter
inside the SysTick ISR is used to toggle the LED1 each 100ms indicating that the
firmware is running.
A defined communication timeout is insuring that the application will not remain
stuck in case of I2C communication is corrupted.
You can adjust this timeout through the USER_TIMEOUT define inside main.h file
depending on CPU frequency and application conditions (interrupts routines,
number of data to transfer, speed, CPU frequency...).
When a given operation is not finished within the defined timeout, a callback is
made to the function "TimeOut_UserCallback()", this function is used to manage
timeout communication failure. In this example, this callback implements a simple
infinite loop, but user can add his own implementation to manage timeout failure.
Directory contents
- I2C/I2C_TwoBoards/DataExchangeDMA/stm32f2xx_conf.h Library Configuration file
- I2C/I2C_TwoBoards/DataExchangeDMA/stm32f2xx_it.c Interrupt handlers
- I2C/I2C_TwoBoards/DataExchangeDMA/stm32f2xx_it.h Interrupt handlers header file
- I2C/I2C_TwoBoards/DataExchangeDMA/main.c Main program
- I2C/I2C_TwoBoards/DataExchangeDMA/main.h Main Header file
- I2C/I2C_TwoBoards/DataExchangeDMA/system_stm32f2xx.c STM32F2xx system source file
The "system_stm32f2xx.c" is generated by an automatic clock configuration
tool and can be easily customized to your own configuration.
To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.
Hardware and Software environment
- This example runs on STM32F2xx Devices.
- This example has been tested with STM322xG-EVAL RevB (with no additional
hardware), and can be easily tailored to any other development board.
- STM322xG-EVAL Set-up
- Connect I2C1 Master SCL pin (PB.06) to I2C1 Slave SCL (PB.06)
- Connect I2C1 Master SDA pin (PB.09) to I2C1 Slave SDA (PB.09)
- Pull-up resistors should be connected to I2C SCL and SDA Pins in case of
other boards use.
Pull-up resistors are already implemented on the STM322xG-EVAL evaluation
boards.
===============================================================================
I2C_DataExchangeInterrupt Two boards I2C Communication: Data Exchange using Interrupts example
Example Description
This is a typical example of how to use the I2C firmware library to ensure the
steps of an I2C communication between slave Receiver/Transmitter and master
Transmitter/Receiver using interrupts.
- Hardware Description
To use this example, you need to load it on two STM32 boards (let's call them
Board A and Board B) then connect these two boards through I2C lines and GND.
In the firmware example uncomment the dedicated line in the main.h file to use
the I2C peripheral as STM32 Master device or as STM32 Slave .
*------------------------------------------------------------------------------*
| BOARD A BOARD B |
| ____________________ ____________________ |
| | | | | |
| | | | | |
| | __________ | | __________ | |
| | |I2C Master|____|_______SDA_______|____|I2C Slave | | |
| | | Device |____|_______SCL_______|____| Device | | |
| | |__________| | | |__________| | |
| | O LD1 | | O LD1 | |
| | O LD2 RESET | | O LD2 RESET | |
| | O LD3 _ | | O LD3 _ | |
| | O LD4 |_| | | O LD4 |_| | |
| | | | | |
| | GND O--|-----------------|--O GND | |
| |____________________| |____________________| |
| |
| |
*------------------------------------------------------------------------------*
- Software Description
This example requires two boards(Master and Slave)
- Phase 1:
In master board I2C peripheral is configured in Master Transmitter with Interrupt,
where in Slave board I2C peripheral is configured in Slave Receiver with Interrupt.
The master will send Data to Slave according to the defined buffer size.
- Phase 2:
In master board I2C peripheral is configured in Master Receiver with Interrupt,
where in Slave board I2C peripheral is configured in Slave Transmitter with
Interrupt.
Once the master has initiated the communication (Start condition), the slave
will send back the data to the master according to the defined buffer size.
At the end of the data transfer, a data consistency check will be performed
in master and slave sides. In case of mismatch between sent and received data,
all LED's are OFF. Otherwise LED2, LED3 and LED4 are ON.
Communication error are handled in master an slave sides, their occurrence will
be signaled by puting LED3 and LED4 On.
The File "I2C/I2C_TwoBoards/DataExchangeInterrupt/main.h" allows different
possibilities of configuration for this example:
- Addressing mode : 7-bit or 10-bit
- I2C speed: Fast mode or Standard mode
In both boards, the data transfers is managed using I2Cx_EV_IRQHandler
and I2Cx_ER_IRQHandler in stm32f2xx_it.c file.
The SysTick is configured to generate interrupt each 10ms. A dedicated counter
inside the SysTick ISR is used to toggle the LED1 each 100ms indicating that the
firmware is running.
A defined communication timeout is insuring that the application will not remain
stuck in case of I2C communication is corrupted.
You can adjust this timeout through the USER_TIMEOUT define inside main.h file
depending on CPU frequency and application conditions (interrupts routines,
number of data to transfer, speed, CPU frequency...).
When a given operation is not finished within the defined timeout, a callback is
made to the function "TimeOut_UserCallback()", this function is used to manage
timeout communication failure. In this example, this callback implements a simple
infinite loop, but user can add his own implementation to manage timeout failure.
Directory contents
- I2C/I2C_TwoBoards/DataExchangeInterrupt/system_stm32f2xx.c STM32F2xx system clock configuration file
- I2C/I2C_TwoBoards/DataExchangeInterrupt/stm32f2xx_conf.h Library Configuration file
- I2C/I2C_TwoBoards/DataExchangeInterrupt/stm32f2xx_it.c Interrupt handlers
- I2C/I2C_TwoBoards/DataExchangeInterrupt/stm32f2xx_it.h Interrupt handlers header file
- I2C/I2C_TwoBoards/DataExchangeInterrupt/main.c Main program
- I2C/I2C_TwoBoards/DataExchangeInterrupt/main.h Main Header file
The "system_stm32f2xx.c" is generated by an automatic clock configuration
tool and can be easily customized to your own configuration.
To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.
Hardware and Software environment
- This example runs on STM32F2xx Devices.
- This example has been tested with STM322xG-EVAL RevB (with no additional
hardware), and can be easily tailored to any other development board.
- STM322xG-EVAL Set-up
- Connect I2C1 Master SCL pin (PB.06) to I2C1 Slave SCL (PB.06)
- Connect I2C1 Master SDA pin (PB.09) to I2C1 Slave SDA (PB.09)
- Pull-up resistors should be connected to I2C SCL and SDA Pins in case of
other boards use.
Pull-up resistors are already implemented on the STM322xG-EVAL evaluation
boards.
===============================================================================
I2C_MasterReceiverInterrupt I2C Communication between Master in Receiver mode
and slave in Transmitter mode using interrupts example
Example Description
This is a typical example of how to use the I2C firmware library to ensure the
steps of an I2C communication between slave transmitter and master receiver using
interrupt.
- Hardware Description
To use this example, you need to load it on two STM32 boards (let's call them
Board A and Board B) then connect these two boards through I2C lines and GND.
In the firmware example uncomment the dedicated line in the main.h file to use
the I2C peripheral as STM32 Master device or as STM32 Slave .
*------------------------------------------------------------------------------*
| BOARD A BOARD B |
| ____________________ ____________________ |
| | | | | |
| | | | | |
| | __________ | | __________ | |
| | |I2C Master|____|_______SDA_______|____|I2C Slave | | |
| | | Device |____|_______SCL_______|____| Device | | |
| | |__________| | | |__________| | |
| | O LD1 | | O LD1 | |
| | O LD2 RESET | | O LD2 RESET | |
| | O LD3 _ | | O LD3 _ | |
| | O LD4 |_| | | O LD4 |_| | |
| | | | | |
| | GND O--|-----------------|--O GND | |
| |____________________| |____________________| |
| |
| |
*------------------------------------------------------------------------------*
- Software Description
This example requires two boards(Master and Slave)
In master board I2C peripheral is configured in Master Receiver with interrupt,
where in Slave board I2C peripheral is configured in Slave Transmitter with
Interrupt.
Once the master has initiated the communication (Start condition), the slave
will send the defined TxBuffer.
At the end of the data transfer, a data consistency check will be performed
in master side and in case of mismatch between sent and received data, all LED's
are Off. Otherwise LED2, LED3 and LED4 will toggle.
Communication error are handled in master side, their occurrence will be signaled
by puting LED3 and LED4 On.
However, in slave side LED2, LED3 and LED4 will toggle after sending the TxBuffer
without any check.
The File "I2C/I2C_TwoBoards/MasterReceiverInterrupt/main.h" allows different
possibilities of configuration of this example:
- Addressing mode : 7-bit or 10-bit
- I2C speed: Fast mode or Standard mode
In both boards, the data transfers is managed using I2Cx_EV_IRQHandler
and I2Cx_ER_IRQHandler in stm32f2xx_it.c file.
The SysTick is configured to generate interrupt each 10ms. A dedicated counter
inside the SysTick ISR is used to toggle the LED1 each 100ms indicating that the
firmware is running.
These operations are repeated infinitely.
A defined communication timeout is insuring that the application will not remain
stuck if the I2C Master communication is corrupted.
You can adjust this timeout through the USER_TIMEOUT define inside main.h file
depending on CPU frequency and application conditions (interrupts routines,
number of data to transfer, speed, CPU frequency...).
When a given operation is not finished within the defined timeout, a callback is
made to the function "TimeOut_UserCallback()", this function is used to manage
timeout communication failure. In this example, this callback implements a simple
infinite loop, but user can add his own implementation to manage timeout failure.
Directory contents
- I2C/I2C_TwoBoards/MasterReceiverInterrupt/stm32f2xx_conf.h Library Configuration file
- I2C/I2C_TwoBoards/MasterReceiverInterrupt/stm32f2xx_it.c Interrupt handlers
- I2C/I2C_TwoBoards/MasterReceiverInterrupt/stm32f2xx_it.h Interrupt handlers header file
- I2C/I2C_TwoBoards/MasterReceiverInterrupt/main.c Main program
- I2C/I2C_TwoBoards/MasterReceiverInterrupt/main.h Main Header file
- I2C/I2C_TwoBoards/MasterReceiverInterrupt/system_stm32f2xx.c STM32F2xx system source file
The "system_stm32f2xx.c" is generated by an automatic clock configuration
tool and can be easily customized to your own configuration.
To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.
Hardware and Software environment
- This example runs on STM32F2xx Devices.
- This example has been tested with STM322xG-EVAL RevB (with no additional
hardware), and can be easily tailored to any other development board.
- STM322xG-EVAL Set-up
- Connect I2C1 Master SCL pin (PB.06) to I2C1 Slave SCL (PB.06)
- Connect I2C1 Master SDA pin (PB.09) to I2C1 Slave SDA (PB.09)
- Pull-up resistors should be connected to I2C SCL and SDA Pins in case of
other boards use.
Pull-up resistors are already implemented on the STM322xG-EVAL evaluation
boards.
===============================================================================
I2C_MasterTransmitterInterrupt I2C Communication between Master in mode transmitter
and slave in mode Receiver using interrupts example
Example Description
This example provides a small application in which joystick buttons are used
to trigger I2C communication using interrupt and though using I2C firmware library.
- Hardware Description
To use this example, you need to load it in two STM32 boards (let's call them
Board A and Board B) then connect these two boards through I2C lines and GND.
In the firmware example uncomment the dedicated line in the main.h file to use
the I2C peripheral as STM32 Master device or as STM32 Slave .
*------------------------------------------------------------------------------*
| BOARD A BOARD B |
| ____________________ ____________________ |
| | | | | |
| | | | | |
| | __________ | | __________ | |
| | |I2C Master|____|_______SDA_______|____|I2C Slave | | |
| | | Device |____|_______SCL_______|____| Device | | |
| | |__________| | | |__________| | |
| | O LD1 | | O LD1 | |
| | O LD2 Joystick | | O LD2 | |
| | O LD3 _ | | O LD3 | |
| | O LD4 |_| | | O LD4 | |
| | | | | |
| | GND O--|-----------------|--O GND | |
| |____________________| |____________________| |
| |
| |
*------------------------------------------------------------------------------*
- Software Description
This example requires two boards(Master and Slave)
In master board, I2C peripheral is configured as Master Transmitter with Interrupt,
whereas in Slave board, I2C peripheral is configured as Slave Receiver with Interrupt.
According to the pushed joystick button in the master board a specific LED will
be ON in the slave board.
At each joystick position press
- The master sends the defined NumberOfByte from TxBuffer to the slave
- The Slave compares the NumberOfByte received data with the defined ones into TxBuffer
Received data correctness is signaled by LED lightening and though as follow:
- Joystick RIGHT and data correctly received ==> LD2, LD3 ON and LD4 OFF
- Joystick LEFT and data correctly received ==> LD4 ON, LD2 and LD3 are OFF
- Joystick UP and data correctly received ==> LD2 ON, LD3 and LD4 are OFF
- Joystick DOWN and data correctly received ==> LD3 ON, LD2 and LD4 are OFF
- Joystick SEL and data correctly received ==> LD2, LD3 and LD4 are ON
Communication error are handled in both Master and Slave sides, their occurrence
will be signaled respectively by puting LED3 and LED4 On.
The File "I2C/I2C_TwoBoards/MasterTransmitterInterrupt/main.h" allows different
possibilities of configuration of this example:
- Addressing mode : 7-bit or 10-bit
- I2C speed: Fast mode or Standard mode
- Buffer size also can be configured
In both boards, the data transfers is managed using I2Cx_EV_IRQHandler
and I2Cx_ER_IRQHandler in stm32f2xx_it.c file.
The SysTick is configured to generate interrupt each 10ms. A dedicated counter
inside the SysTick ISR is used to toggle the LD1 each 100ms indicating that the
firmware is running.
These operations can be repeated infinitely.
A defined communication timeout is insuring that the application will not remain
stuck if the I2C Master communication is corrupted.
You can adjust this timeout through the USER_TIMEOUT define inside main.h file
depending on CPU frequency and application conditions (interrupts routines,
number of data to transfer, speed, CPU frequency...).
When a given operation is not finished within the defined timeout, a callback is
made to the function "TimeOut_UserCallback()", this function is used to manage
timeout communication failure. In this example, this callback implements a simple
infinite loop, but user can add his own implementation to manage timeout failure.
Directory contents
- I2C/I2C_TwoBoards/MasterTransmitterInterrupt/stm32f2xx_conf.h Library Configuration file
- I2C/I2C_TwoBoards/MasterTransmitterInterrupt/stm32f2xx_it.c Interrupt handlers
- I2C/I2C_TwoBoards/MasterTransmitterInterrupt/stm32f2xx_it.h Interrupt handlers header file
- I2C/I2C_TwoBoards/MasterTransmitterInterrupt/main.c Main program
- I2C/I2C_TwoBoards/MasterTransmitterInterrupt/main.h Main Header file
- I2C/I2C_TwoBoards/MasterTransmitterInterrupt/system_stm32f2xx.c STM32F2xx system source file
The "system_stm32f2xx.c" is generated by an automatic clock configuration
tool and can be easily customized to your own configuration.
To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.
Hardware and Software environment
- This example runs on STM32F2xx Devices.
- This example has been tested with STM322xG-EVAL RevB (with no additional
hardware), and can be easily tailored to any other development board.
- STM322xG-EVAL Set-up
- Connect I2C1 Master SCL pin (PB.06) to I2C1 Slave SCL (PB.06)
- Connect I2C1 Master SDA pin (PB.09) to I2C1 Slave SDA (PB.09)
- Pull-up resistors should be connected to I2C SCL and SDA Pins in case of
other boards use.
Pull-up resistors are already implemented on the STM322xG-EVAL evaluation
boards.
===============================================================================
I2C_IOE Example on how to use the IO Expander
Example Description
This firmware provides an example of configuring and using the IO Expander STMPE811
in order to control input Joystick IOs, output IOs and the Touch Screen feature.
This example provides the elementary steps to control the following modules and
use them in an application:
The IO pins are used for:
- Getting Joystick pins status (Polling and interrupt) only for STM3210C-EVAL.
- The Touch Screen controller is used to get the Touched area detection information
in a single point mode (Polling and interrupt).
The input information can be used either in Polling mode (uncomment the define
#define IOE_POLLING_MODE) or in Interrupt mode (uncomment the define #define
IOE_INTERRUPT_MODE). These defines are in main.h file.
After configuring the IO Expander modules and Interrupts (if needed), the output
IOs are set to their default state. These operations are done by the functions:
IOE_Config() and IOE_ITConfig(). If the IO Expander is not operational (or the
I2C pins are not in the correct level) the IOE_Config() function returns a value
different from 0 and a message is displayed on the LCD screen.
To get the status of an input:
- IOE_JoyStickGetState() function is used for Joystick and returns a JOY_State_TypeDef
value indicating the currently pressed key. This information is used to update
the LCD display (the Joystick pressed key name is displayed).
- IOE_TS_GetState() function is used for Touch Screen and returns a pointer to
a structure holding the Touch Screen status (did a Touch Detection happened,
X, Y, and Z positions). Only detection into the drawn rectangles areas is
considered and used to update the LEDs status and LCD display (corresponding
LED turned ON when its rectangle is touched, and the LED name is displayed on
the LCD screen).
Besides, the examples checks the status of the other Push-Buttons implemented on
the board (Key, Tamper and WakeUp push-buttons). They are checked in parallel
with the IO Expander IOs and the LCD display and LEDs are updated according to
the push buttons state.
Directory contents
- I2C/IOE/system_stm32f2xx.c STM32F2xx system clock configuration file
- I2C/IOE/stm32f2xx_conf.h Library Configuration file
- I2C/IOE/stm32f2xx_it.c Interrupt handlers
- I2C/IOE/stm32f2xx_it.h Interrupt handlers header file
- I2C/IOE/main.c Main program
The "system_stm32f2xx.c" is generated by an automatic clock configuration
tool and can be easily customized to your own configuration.
To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.
Hardware and Software environment
- This example runs on STM32F2xx Devices.
- This example has been tested with STM322xG-EVAL RevB (with no
additional hardware), and can be easily tailored to any other development board.