Example description
I2S_Interrupt
Example Description
This example provides a description of how to set a communication between two
SPIs in I2S mode using interrupts and performing a transfer from Master to Slave.
In the first step, I2S3 is configured as master transmitter and I2S2 as slave
reciever and both are in Phillips standard configuration with 16bit extended to
32 bit data packet and 48KHz audio frequnecy.
The I2S3 transmit interrupt and the I2S2 receive interrupt are both enabled. And
in these interrupts subroutines, the I2S3_Buffer_Tx is transmitted and the received
values are loaded in the I2S2_Buffer_Rx buffer. Only the significant 16 MSBs are
sent and received, while the 32 packet remaining 16 LSBs are filled with 0 values
and don't generate any interrupt.
Once the transfer is completed a comparison is done and TransferStatus1 gives the
data transfer status where it is PASSED if transmitted and received data are the
same otherwise it is FAILED.
In the second step both peripherals are configured in I2S Phillips standard 24 bits
data length in 32 bits packets and 16KHz audio frequency. The interrupts are
enabled and the transfer is performed from the I2S3 master to the I2S2 slave.
The 24 bits are transmited then the 8 remaining LSBs are filled automatically
with 0 values.
Once the transfer is completed a comparison is done (on the 24 MSBs only, the 8
LSBs are replaced by 0) and TransferStatus2 gives the data transfer status where
it is PASSED if transmitted and received data are the same otherwise it is FAILED.
Directory contents
- I2S/Interrupt/stm32f10x_conf.h Library Configuration file
- I2S/Interrupt/stm32f10x_it.c Interrupt handlers
- I2S/Interrupt/stm32f10x_it.h Header for stm32f10x_it.c
- I2S/Interrupt/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x High-Density and STM32F10x Connectivity-Line
Devices.
- This example has been tested with STMicroelectronics STM3210E-EVAL (STM32F10x
High-Density) and STM3210E-EVAL (STM32F10x Coneectivity-Line) evaluation boards
and can be easily tailored to any other supported device and development board.
- STM3210C-EVAL Set-up
- Connect I2S2 WS (PB.12) pin to I2S3 WS (PA.04) pin
- Connect I2S2 CK (PB.13) pin to I2S3 CK (PC.10) pin
- Connect I2S2 SD (PB.15) pin to I2S3 SD (PC.12) pin
- STM3210E-EVAL Set-up
- Connect I2S2 WS (PB.12) pin to I2S3 WS (PA.15) pin
- Connect I2S2 CK (PB.13) pin to I2S3 CK (PB.03) pin
- Connect I2S2 SD (PB.15) pin to I2S3 SD (PB.05) pin
Since some SPI3/I2S3 pins are shared with JTAG pins (SPI3_NSS/I2S3_WS with JTDI
and SPI3_SCK/I2S3_CK with JTDO), they are not controlled by the I/O controller
and are reserved for JTAG usage (after each Reset).
For this purpose prior to configure the SPI3/I2S3 pins:
- For STM32F10x High-Density devices, the user has to disable the JTAG and use
the SWD interface (when debugging the application), or disable both JTAG/SWD
interfaces (for standalone application).
- For STM32F10x Connectivity-Line devices, the user can use the solution above
(SWD or disable bothe JTAG and SWD), or it is possible to remap the SPI3 pins
on {PC10, PC11, PC12, PA4} GPIO pins in order to avoid the conflict with JTAG
pins (and it is possible in this case to use JTAG interface). This remap is
used for STM3210C-EVAL evaluation boards in this example.
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:
- misc.c
- stm32f10x_flash.c
- stm32f10x_spi.c
- stm32f10x_rcc.c
- stm32f10x_gpio.c
- misc.c
- Edit stm32f10x.h file to select the device you are working on (#define
STM32F10X_HD or #define STM32F10X_CL in this case).
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.
- High-density devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
I2S_SPI_I2S_Switch
Example Description
This example provides a description of how to set a communication between two
SPIs in I2S mode, and how to switch between SPI and I2S modes, performing a
transfer from Master to Slave in I2S modes then a transfer from master to slave
in SPI mode and finally a transfer from Slave to Master in I2S mode.
I2S2 is configured as master transmitter and I2S3 as slave reciever and both are
in Phillips standard configuration with 16bit data size in 32bit packet length
and 48KHz audio frequnecy.
In the first phase, the master I2S2 starts the I2S2_Buffer_Tx transfer while the
slave I2S3 receieves and loads the values in I2S3_Buffer_Rx. Once the transfer is
completed a comparison is done and TransferStatus1 gives the data transfer status
where it is PASSED if transmitted and received data are the same otherwise it is
FAILED.
In the second step, both preripherals are configured in SPI modes (simplex
communication) and SPI2_Buffer_Tx transfer is performed in simplex mode from SPI2 to
SPI3.Once the transfer is completed a comparison is done and TransferStatus2 gives
the data transfer status where it is PASSED if transmitted and received data are
the same otherwise it is FAILED.
As the master/slave mode is managed by software (the master is the clock (CK and WS)
generator), this allows to I2S2 to become slave transmitter and I2S3 to become master
receiver whithout hardware modification.
In the third step, the slave I2S2 prepares the first data to be sent before the
master is enabled. Once the master is enabled, the clocks are released from the
master and the data are released on the slave. Once the transfer is completed
a comparison is done and TransferStatus3 gives the data transfer status where it
is PASSED if transmitted and received data are the same otherwise it is FAILED.
Directory contents
- I2S/SPI_I2S_Switch/stm32f10x_conf.h Library Configuration file
- I2S/SPI_I2S_Switch/stm32f10x_it.c Interrupt handlers
- I2S/SPI_I2S_Switch/stm32f10x_it.h Header for stm32f10x_it.c
- I2S/SPI_I2S_Switch/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x High-Density and STM32F10x Connectivity-Line
Devices.
- This example has been tested with STMicroelectronics STM3210E-EVAL (STM32F10x
High-Density) and STM3210E-EVAL (STM32F10x Coneectivity-Line) evaluation boards
and can be easily tailored to any other supported device and development board.
- STM3210C-EVAL Set-up
- Connect I2S2 WS (PB.12) pin to I2S3 WS (PA.04) pin
- Connect I2S2 CK (PB.13) pin to I2S3 CK (PC.10) pin
- Connect I2S2 SD (PB.15) pin to I2S3 SD (PC.12) pin
- STM3210E-EVAL Set-up
- Connect I2S2 WS (PB.12) pin to I2S3 WS (PA.15) pin
- Connect I2S2 CK (PB.13) pin to I2S3 CK (PB.03) pin
- Connect I2S2 SD (PB.15) pin to I2S3 SD (PB.05) pin
Since some SPI3/I2S3 pins are shared with JTAG pins (SPI3_NSS/I2S3_WS with JTDI
and SPI3_SCK/I2S3_CK with JTDO), they are not controlled by the I/O controller
and are reserved for JTAG usage (after each Reset).
For this purpose prior to configure the SPI3/I2S3 pins:
- For STM32F10x High-Density devices, the user has to disable the JTAG and use
the SWD interface (when debugging the application), or disable both JTAG/SWD
interfaces (for standalone application).
- For STM32F10x Connectivity-Line devices, the user can use the solution above
(SWD or disable bothe JTAG and SWD), or it is possible to remap the SPI3 pins
on {PC10, PC11, PC12, PA4} GPIO pins in order to avoid the conflict with JTAG
pins (and it is possible in this case to use JTAG interface). This remap is
used for STM3210C-EVAL evaluation boards in this example.
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:
- misc.c
- stm32f10x_flash.c
- stm32f10x_spi.c
- stm32f10x_rcc.c
- stm32f10x_gpio.c
- system_stm32f10x.c
- Edit stm32f10x.h file to select the device you are working on (#define
STM32F10X_HD or #define STM32F10X_CL in this case).
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.
- High-density devices are STM32F105xx and STM32F107xx microcontrollers.