/**
@page SPI_DataExchangeDMA SPI Communication Boards Data Exchange using DMA example
@verbatim
******************** (C) COPYRIGHT 2012 STMicroelectronics *******************
* @file SPI/SPI_TwoBoards/DataExchangeDMA/readme.txt
* @author MCD Application Team
* @version V1.0.0
* @date 18-May-2012
* @brief Description of the SPI Communication Boards Data Exchange using
* DMA example.
******************************************************************************
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
@endverbatim
@par Example Description
This example provides a small application in which joystick buttons are used
to trigger SPI communications using DMA and though using SPI firmware library.
- 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 SPI lines and GND.
In the STM32 master board (Board A), connect the timer output capture compare
channel into NSS line.
In the firmware example uncomment the dedicated line in the main.h file to use
the SPI peripheral as STM32 Master device or as STM32 Slave.
@verbatim
*------------------------------------------------------------------------------*
| BOARD A BOARD B |
| ____________________ ____________________ |
| | | | | |
| | | | | |
| | __________ ____|_______SCK_______|____ __________ | |
| | |SPI Master|____|_______MOSI______|____|SPI Slave | | |
| | | Device |____|_______MISO______|____| Device | | |
| | |__________|____|_______NSS_______|____|__________| | |
| | | | | | |
| | O LD1 TIM_CHx O__|___| | O LD1 | |
| | O LD2 Joystick | | O LD2 Joystick | |
| | O LD3 _ | | O LD3 _ | |
| | O LD4 |_| | | O LD4 |_| | |
| | | | | |
| | GND O--|-----------------|--O GND | |
| |____________________| |____________________| |
| |
| |
*------------------------------------------------------------------------------*
@endverbatim
@note
- The connection between the pins should use a short wires and a common Ground.
- Software Description
In master board, SPI peripheral is configured as Master full duplex with DMA
and NSS hardware mode.
The TIM2 is configured to generate 4KHz PWM signal with 50% duty cycle on TIM2_CH2
pin (PA.01), this signal is used as DMA trigger and as NSS signal input to latch
the SPI data transfers. Whereas in Slave board, SPI peripheral is configured as
Slave Full duplex with DMA and NSS hardware mode.
At each joystick buttons press:
- The Master sends the specific command to the Slave using the TIM2_CH2 DMA
request (DMA1_Channel3)(the command contains the transaction code (CMD_RIGHT,
CMD_LEFT, CMD_UP, CMD_DOWN or CMD_SEL) and receives the ACK command from the
Slave using SPI_Rx DMA request(DMA1_Channel2)
- The Slave receives the command using SPI_Rx DMA request(DMA1_Channel2) and sends
the ACK command using the SPI_Tx DMA request (DMA1_Channel3).
- The Master sends the defined NumberOfByte from TxBuffer using the TIM2_CH2 DMA
request (DMA1_Channel3) to the Slave and receives NumberOfByte from the Slave
using SPI_Rx DMA request(DMA1_Channel2) into Rxbuffer.
- The Slave sends the defined NumberOfByte from Txbuffer using the SPI_Tx DMA
request (DMA1_Channel3) to the Master and receives NumberOfByte from the Master
using SPI_Rx DMA request(DMA1_Channel2) into Rxbuffer.
- The Master compares the NumberOfByte received data with the defined ones into
TxBuffer and check the ACK command, received data correctness is signaled by LD
lightening and though as follow:
- Joystick JOY_RIGHT and data correctly received ==> LD2 and LD3 ON and LD4 OFF
- Joystick JOY_LEFT and data correctly received ==> LD4 ON, LD2 and LD3 are OFF
- Joystick JOY_UP and data correctly received ==> LD2 ON, LD3 and LD4 are OFF
- Joystick JOY_DOWN and data correctly received ==> LD3 ON, LD2 and LD4 are OFF
- Joystick JOY_SEL and data correctly received ==> LD2, LD3 and LD4 leds ON
- The Slave compares the NumberOfByte received data with the defined ones into
TxBuffer and check the received command,Received data correctness is signaled
by LED lightening and though as follow:
- Received command CMD_RIGHT and data correctly received ==> LD2 and LD3 ON and LD4 OFF
- Received command CMD_LEFT and data correctly received ==> LD2 ON, LD3 and LD4 are OFF
- Received command CMD_UP and data correctly received ==> LD2 ON, LD3 and LD4 are OFF
- Received command CMD_DOWN and data correctly received ==> LD3 ON, LD2 and LD4 are OFF
- Received command CMD_SEL and data correctly received ==> LD2, LD3 and LD4 leds ON
In both boards, the SPI is configured to use the slave hardware management to
manage the NSS pin.
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.
A defined communication timeout is insuring that the application will not remain
stuck if the SPI 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, baudrate, CPU frequency...).
These operations can be repeated infinitely.
@par Directory contents
- SPI/SPI_TwoBoards/DataExchangeDMA/stm32f0xx_conf.h Library Configuration file
- SPI/SPI_TwoBoards/DataExchangeDMA/stm32f0xx_it.c Interrupt handlers
- SPI/SPI_TwoBoards/DataExchangeDMA/stm32f0xx_it.h Interrupt handlers header file
- SPI/SPI_TwoBoards/DataExchangeDMA/main.c Main program
- SPI/SPI_TwoBoards/DataExchangeDMA/main.h Main program header file
- SPI/SPI_TwoBoards/DataExchangeDMA/system_stm32f0xx.c STM32F0xx system source file
@note The "system_stm32f0xx.c" is generated by an automatic clock configuration
tool and can be easily customized to meet user application requirements.
To select different clock setup, use the "STM32F0xx_Clock_Configuration_VX.Y.Z.xls"
provided with the AN4055 package available on <a href="http://www.st.com/internet/mcu/class/1734.jsp"> ST Microcontrollers </a>
@par Hardware and Software environment
- This example runs on STM32F0xx Devices.
- This examp
没有合适的资源?快使用搜索试试~ 我知道了~
STM32F0系列参考例程
共1148个文件
c:277个
h:251个
txt:122个
4星 · 超过85%的资源 需积分: 49 1.5k 下载量 97 浏览量
2012-08-30
09:48:45
上传
评论 8
收藏 20.13MB ZIP 举报
温馨提示
该例程不是官方开发板的例程,而是我买的开发板赠送的。包括了IO口,SPI,DMA,USART等。基本上每个模块都有了。学习STM32的同学拿去。该开发板为STM32F051,凡是STM32F0xx系列的都行。
资源推荐
资源详情
资源评论
收起资源包目录
STM32F0系列参考例程 (1148个子文件)
stm320518_eval_i2c_tsensor_cpal.__i 774B
stm320518_eval_i2c_ee_cpal.__i 754B
stm32f0xx_i2c_cpal_usercallback.__i 732B
stm320518_eval.__i 706B
Project.uvgui.Administrator 135KB
USART_Printf.uvgui.Administrator 135KB
IOToggle.uvgui.Administrator 134KB
TimeStamp.uvgui.Administrator 134KB
HyperTerminal_Interrupt.uvgui.Administrator 133KB
cstart_thumb2.asm 4KB
cstart_thumb2.asm 4KB
cstart_thumb2.asm 4KB
cstart_thumb2.asm 4KB
cstart_thumb2.asm 4KB
cstart_thumb2.asm 4KB
cstart_thumb2.asm 4KB
cstart_thumb2.asm 4KB
cstart_thumb2.asm 4KB
STM320518-EVAL.axf 196KB
I2C_EEPROM.uvgui_XIN.bak 136KB
SPI_MSD.uvgui_XIN.bak 135KB
USART_Printf.uvgui_Administrator.bak 134KB
IOToggle.uvgui_Administrator.bak 134KB
Project.uvgui_Administrator.bak 134KB
TimeStamp.uvgui_Administrator.bak 134KB
USART_Printf.uvgui_XIN.bak 134KB
HyperTerminal_Interrupt.uvgui_Administrator.bak 133KB
HyperTerminal_Interrupt.uvgui_XIN.bak 131KB
I2C_TwoBoards.uvgui_XIN.bak 73KB
Project.uvgui_XIN.bak 72KB
I2C_TSENSO.uvgui_XIN.bak 70KB
IOToggle.uvgui_XIN.bak 67KB
TimeStamp_uvopt.bak 22KB
Project_uvproj.bak 22KB
Project_uvproj.bak 22KB
Project_uvproj.bak 22KB
Project_uvproj.bak 22KB
Project_uvproj.bak 22KB
Project_uvproj.bak 22KB
Project_uvproj.bak 22KB
SPI_MSD_uvproj.bak 21KB
I2C_EEPROM_uvproj.bak 21KB
IOToggle_uvproj.bak 21KB
Project_uvproj.bak 21KB
USART_Printf_uvproj.bak 21KB
HyperTerminal_Interrupt_uvproj.bak 21KB
I2C_TSENSO_uvproj.bak 21KB
I2C_TwoBoards_uvproj.bak 21KB
TimeStamp_uvproj.bak 21KB
Project_uvopt.bak 20KB
Project_uvopt.bak 20KB
Project_uvopt.bak 20KB
Project_uvopt.bak 20KB
Project_uvopt.bak 20KB
Project_uvopt.bak 20KB
Project_uvopt.bak 20KB
Project_uvopt.bak 20KB
SPI_MSD_uvopt.bak 20KB
I2C_EEPROM_uvopt.bak 20KB
HyperTerminal_Interrupt_uvopt.bak 20KB
I2C_TSENSO_uvopt.bak 19KB
IOToggle_uvopt.bak 19KB
USART_Printf_uvopt.bak 19KB
I2C_TwoBoards_uvopt.bak 19KB
Project.cspy.bat 935B
logo.bmp 7KB
stm32f0xx_tim.c 123KB
stm32f0xx_rtc.c 88KB
stm32f0xx_usart.c 80KB
stm32f0xx_i2c_cpal.c 73KB
stm32f0xx_rcc.c 58KB
stm320518_eval_cec.c 58KB
stm320518_eval_lcd.c 57KB
stm32f0xx_i2c.c 55KB
stm32f0xx_spi.c 50KB
fonts.c 46KB
stm32f0xx_adc.c 45KB
stm32f0xx_flash.c 39KB
main.c 29KB
stm32f0xx_dma.c 28KB
stm320518_eval_spi_sd.c 25KB
stm32f0xx_cec.c 24KB
stm320518_eval_i2c_ee.c 22KB
stm32f0xx_i2c_cpal_hal.c 22KB
main.c 22KB
stm320518_eval.c 22KB
stm320518_eval_i2c_tsensor.c 21KB
stm320518_eval_i2c_ee_cpal.c 21KB
stm32f0xx_pwr.c 19KB
stm32f0xx_dac.c 19KB
stm32f0xx_gpio.c 18KB
main.c 17KB
main.c 17KB
stm32f0xx_comp.c 15KB
stm320518_eval_i2c_tsensor_cpal.c 15KB
main.c 14KB
main.c 14KB
main.c 13KB
main.c 13KB
main.c 13KB
共 1148 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
nianhua120
- 粉丝: 4
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页