arm_m3_ppt
TRANSCRIPT
RF無線感測與通訊driver開發RF無線感測與通訊driver開發MIAT STM32F10x Development Kit
WU-YANG姚敦凱Aug 11 2009
浯陽科技有限公司
Technology Co., Ltd. Aug. 11, 2009
Declared VersionTraining Only
Declare
Document Number
Document Version 1.00
Release Date 2009.06.20
Document Title RF Transmitter & Receiver Driver
Exercise Time Lecture 25 minutes Operating 25 minutes
MIAT STM32Platform MIAT_STM32 MIAT_IOB
Peripheral RF Device RS232 Wire USB Wire USB Wire
Author WU-YANG Technology Co., Ltd.
Key Word STM32F10x, RF, EXIT, SPI, UART, RF
2
System ArchitectureyRF Features
Worldwide 2.4GHz ISM band operation
The diagram of the system architecture
2Mbps on air data rates
STM32 Features
SPI Controller1. 18 Mbits/s2. The frame is configurable to 8 bits or 16 bits3. The hardware CRC generation/verification4 Served by the DMA controller4. Served by the DMA controller
GPIO1. Each of the GPIO pins can be configured by
software as output (push-pull or open-drain), as input (with or without pull-up or pull-down) or as peripheral(with or without pull up or pull down) or as peripheral alternate function
2. I/Os on APB2 with up to 18 MHz toggling speed
3
SPI Introduction
浯陽科技有限公司
WU-YANG
浯陽科技有限公司WU-YANG Technology Co., Ltd.
Technology Co., Ltd.
4
SPI Introduction
5
SPI Features
6
I2S Features
7
SPI Protocol
8
SPI Protocol Cont.,,SPI – Read Timing Diagram
SPI – Write Timing Diagramg g
9
SPI Registers
浯陽科技有限公司
WU-YANG
浯陽科技有限公司WU-YANG Technology Co., Ltd.
Technology Co., Ltd.
10
STM32F103CZ SoC Architetcure
APB2 APB1
11
STM32 SPI Bus ControllerSerial Peripheral Interface Bus (SPI)
The SPI bus can operate with a single master
STM32 Architecture Diagram
gdevice and with one or more slave devices
The SPI bus specifies four logic signals
a. SCLK — Serial Clock (output from master)b MOSI/SIMO — Master Output Slave Input Reset and clock control (RCC)
Nested vectored interrupt controller (NVIC)
b. MOSI/SIMO Master Output, Slave Input (output from master)
c. MISO/SOMI — Master Input, Slave Output (output from slave)
d. SS — Slave Select (active low; output from t )
Reset and clock control (RCC)
master)
This work operates SPI controller and nRF24L01 on 8 Mhz
SPI
12
Memory Mapping Tabley pp g
Internal SRAM MemoryyInternal Flash Program Memoryetc.
13
SPI Core Architecture DiagramgAPB1
14
SPI Registers Tableg
15
SPI Control Register 1g
16
SPI Control Register 1 Cont.,g ,
17
SPI Control Register 1 Cont.,g ,
18
SPI Control Register 1 Cont.,g ,
19
SPI Control Register 2g
20
SPI Control Register 2 Cont.,g ,
21
SPI Status Registerg
22
SPI Status Register Cont.,g ,
23
SPI Status Register Cont.,g ,
24
SPI Data Registerg
25
SPI CRC Polynomial Registery g
26
SPI Rx CRC Registerg
27
SPI Tx CRC Registerg
28
SPI Registers Mappingg pp g
29
SPI Standard Driver Library
浯陽科技有限公司
WU-YANG
浯陽科技有限公司WU-YANG Technology Co., Ltd.
Technology Co., Ltd.
30
SPI DeInit Function
31
SPI Initial Function
32
SPI Initial Function Cont.,,
33
SPI Initial Function Cont.,,
34
SPI Initial Function Cont.,,
35
SPI Initial Function Cont.,,
36
SPI Initial Function Cont.,,
37
SPI Initial Function Cont.,,
38
SPI Initial Function Cont.,,
39
SPI Initial Function Cont.,,
40
SPI Initial Function Cont.,,
41
SPI Initial Function Cont.,,
42
SPI Structure Initial Function
43
SPI Structure Initial Function Cont.,,
44
SPI Command Function
45
SPI Interrupt Configure Functionp g
46
SPI Interrupt Configure Function Cont.,p g ,
47
SPI DMA Command Function
48
SPI DMA Command Function Cont.,,
49
SPI Send Data Function
50
SPI Receive Data Function
51
SPI SS Output Command Functionp
52
SPI Data Size Configure Functiong
53
SPI Data Size Configure Function Cont.,g ,
54
SPI Transmit CRC Function
55
SPI Calculate CRC Function
56
SPI Get CRC Function
57
SPI Get CRC Function Cont.,,
58
SPI Get CRC Polynomial Functiony
59
SPI Get Flag Status Functiong
60
SPI Get Flag Status Function Cont.,g ,
61
SPI Clear Flag Functiong
62
SPI Clear Flag Function Cont.,g ,
63
SPI Get Interrupt Status Functionp
64
SPI Get Interrupt Status Function Cont.,p ,
65
SPI Clear Interrupt Pending Bit Functionp g
66
SPI Clear Interrupt Pending Bit Function Cont.,,
67
External Interrupt
浯陽科技有限公司
WU-YANG
浯陽科技有限公司WU-YANG Technology Co., Ltd.
Technology Co., Ltd.
68
EXIT Multiplexerp
69
SPI Interrupt Mask Registerp g
70
Event Mask Registerg
71
Rising Trigger Selection Registerg gg g
72
Falling Trigger Selection Registerg gg g
73
Software Interrupt Event Registerp g
74
Pending Registerg g
75
Registers Mappingg pp g
76
RF Driver Library
浯陽科技有限公司
WU-YANG
浯陽科技有限公司WU-YANG Technology Co., Ltd.
Technology Co., Ltd.
77
RF Initial Structuretypedef struct{
unsigned char AddressWidth;gunsigned char RxAddress[5];unsigned char TxAddress[5];unsigned char DataLengthPipe0;unsigned char Config;unsigned char AutoAck;unsigned char AutoAck;unsigned char RxPipe;unsigned char Retry;unsigned char Channel;unsigned char Setup;
i d h Sunsigned char Status;unsigned char ObserveTx;
}RF_ConfTypeDef;
78
RF Configure Modeg
79
RF Normal Mode
80
RF Flush Transmit Buffer
81
RF Flush Receive Buffer
82
RF Initial
83
RF Transmit Data
84
RF Receive Data
85
RF IRQ Status
86
EXERCISE TIME
87
Lab1 – RF Transmit & Receive Data
Goal
User1: Use RF to transmit 32 bytes data User1: Use RF to transmit 32 bytes data
User2: User RF to receive 32 bytes data
Principle
88
Lab1Transmitter & Receiver Architecture DiagramSystem Architecture
System ResourceSource Bus Function Signal Name EVB Location IOB Location
SPI 1
APB2 SPI SCK PA5 CON2_3
APB2 SPI MISO PA6 CON2_5
APB2 SPI MOSI PA7 CON2_4
GPIO A APB2 GPIO SSn PA4 CON2_2
GPIO E APB2 GPIO CE PE5 CON2_1
EXIT 2 APB2 GPIO IRQn PE2 CON2_6
UART1APB2 UART TX PA9 CON1_19
APB2 UART RX PA10 CON1 20
89
APB2 UART RX PA10 CON1_20
Development FlowpEmbedded Software Side PC Software of transmitter
Connect the EVB and the IOB
Programming
Use the Dubond thread
PC TerminalWait uart to transmit 32 bytes Data
g gBootupSTM32F10x
RCC Configure
NVIC Configure
SPI Configure
PC Terminal
PC Software of Receiver
Wait RF to receive dataSPI Configure
SysTick Configure
GPIO Configure The Transmitter of the STM32F10x will t b bl d t l i t t b t
UART Configure
EXIT Configure
not be enabled external interrupt, but the IRQn of the RF will still work.
Setup RF Device RF Restart
RF Configure
RF Standby
90
RF Standby
Wire Connecting TablegMIAT STM32 Main Board MIAT IO BoardPin Mapping
3V3 JP5 CON1_29
GND JP5 CON1_30
UART TX PA9 CON1_19
UART RX PA10 CON1 20UART RX PA10 CON1_20
SPI CSn PA4 CON2_2
SPI SCK PA5 CON2_3
SPI MISO PA6 CON2_5
SPI MOSI PA7 CON2_4
SPI IRQn PE2 CON2_6
SPI CE PE5 CON2 1SPI CE PE5 CON2_1
91
RCC Configureg/* RCC Configure */RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
92
NVIC Configureg/* NVIC Configure */void NVIC_Configuration(void){
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC SetVectorTable(NVIC VectTab RAM 0x0);NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH *//* Set the Vector Table base location at 0x08000000 */ //NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);NVIC_SetVectorTable(0x08003000, 0x0);
# dif#endif
/* Configure the Priority Group to 1 bits */NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Configure the SysTick handler priority */NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 2, 0);
/* Enable the EXTI2 Interrupt */NVIC InitStructure NVIC IRQChannel = EXTI2 IRQChannel;NVIC_InitStructure.NVIC_IRQChannel EXTI2_IRQChannel;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);
}
93
}
GPIO Configureg/* GPIO Configure */void GPIO_Configuration(void){
GPIO_InitTypeDef GPIO_InitStructure;/* Configure SPI pins: SCK and MOSI ---------------------------------------*/GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO InitStructure GPIO Mode = GPIO Mode AF PP;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;GPIO_Init(GPIOA, &GPIO_InitStructure);/* Configure SPI pins: MISO ---------------------------------------*/GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;G O i S G O d G O dGPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;GPIO_Init(GPIOA, &GPIO_InitStructure);/* Configure SPI pins: CSN ---------------------------------------*/GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;_ _ _ _GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_Init(GPIOA, &GPIO_InitStructure);/* Configure PE.02 as input floating (EXTI Line 2) */GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;GPIO InitStructure GPIO Speed = GPIO Speed 50MHz;GPIO_InitStructure.GPIO_Speed GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOE, &GPIO_InitStructure);/*for RF_CE*/GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;GPIO I itSt t GPIO M d GPIO M d O t PP
94
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOE, &GPIO_InitStructure);
}
SPI Configureg/* SPI Configure */void SPI_Configuration(void){
SPI_InitTypeDef SPI_InitStructure;/* 1st phase: SPI1 Master *//* SPI1 Config -------------------------------------------------------------*/SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;SPI InitStructure SPI Mode = SPI Mode Master;SPI_InitStructure.SPI_Mode = SPI_Mode_Master;SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;SPI_InitStructure.SPI_CPHA = SPI_CPHA_1EdgeSPI_InitStructure.SPI_NSS = SPI_NSS_Soft;S i S S d l S d l 8SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;SPI_InitStructure.SPI_CRCPolynomial = 7;SPI_Init(SPI1, &SPI_InitStructure);
/* Enable SPI1 */SPI_Cmd(SPI1, ENABLE);
}
95
EXIT Configureg/* EXIT Configure */void EXIT_Configuration(void){
EXTI_InitTypeDef EXTI_InitStructure;/* Connect EXTI Line2 to PE.02 */GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource2);EXTI_InitStructure.EXTI_Line = EXTI_Line2;EXTI InitStructure EXTI Mode = EXTI Mode Interrupt;EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;EXTI_InitStructure.EXTI_LineCmd = ENABLE;EXTI_Init(&EXTI_InitStructure);
/* G f i i l f lli d li d li 2 *//* Generate software interrupt: simulate a falling edge applied on EXTI line 2 */EXTI_GenerateSWInterrupt(EXTI_Line2);
}
96
User Programg/* User Program */RF_ConfTypeDef rfInitConfigure;RF ConfigureMode();_ gRF_FlushTxBuf();RF_FlushRxBuf();
rfInitConfigure.AddressWidth = 3; // Setuo Rx/Tx address widthrfInitConfigure RxAddress[0] = 0xE7; // Rx AddressrfInitConfigure.RxAddress[0] = 0xE7; // Rx AddressrfInitConfigure.RxAddress[1] = 0xE7; rfInitConfigure.RxAddress[2] = 0xE7;rfInitConfigure.RxAddress[3] = 0xE7;rfInitConfigure.RxAddress[4] = 0xE7;f i C fi dd [0] 0 7 // ddrfInitConfigure.TxAddress[0] = 0xE7; // Tx Address
rfInitConfigure.TxAddress[1] = 0xE7;rfInitConfigure.TxAddress[2] = 0xE7;rfInitConfigure.TxAddress[3] = 0xE7;rfInitConfigure.TxAddress[4] = 0xE7;rfInitConfigure.DataLengthPipe0 = 32;rfInitConfigure.Config = 0x0f; // PWR_UP | CRC(2Byte) | Prim TxrfInitConfigure.AutoAck = 0x01; // Auto AckrfInitConfigure.RxPipe = 0x01; // Enable pipe0rfInitConfigure Retry = 0x0a; // 10 retransrfInitConfigure.Retry 0x0a; // 10 retransrfInitConfigure.Channel = 0x09; // ChannelrfInitConfigure.Setup = 0x0f; // Tx_PWR: 0dbm | DataRate: 2Mbps | LAN: HCURRrfInitConfigure.Status = 0x70; // Read Status | Clear IRQ FlagrfInitConfigure.ObserveTx = 0x00;RF I it(& fI itC fi )
97
RF_Init(&rfInitConfigure);
RF_NormalMode();
EXIT2 IRQ Handler/* EXIT IrqHandler */void EXTI2_IRQHandler(void){
int i; extern u8 rfrx_payload[32];
if(EXTI_GetITStatus(EXTI_Line2) != RESET){switch(RF IrqStatus()){switch(RF_IrqStatus()){
case 0x00:break;
case 0x10:break;0 20case 0x20:
break; case 0x40:
RF_ReceiveData(rfrx_payload);printf("[STM32F103] RF Received: ");for(i=0;i<32;i++) printf("%x ", rfrx_payload[i]);printf("\n\r");
break;}}
EXTI_ClearITPendingBit(EXTI_Line2);}
}
98
RF Transmitter – Uart Terminal
Set Uart Baudrate, and connect to the uart of the STM32F10x
When the terminal prints “Wait UART Data”, we can click the “Send File” buttonclick the Send File button
99
RF Receiver – Uart Terminal
Set Uart Baudrate, and connect to the uart of the STM32F10x
When the uart terminal prints “RF Receiver ServiceWhen the uart terminal prints “RF Receiver Service Ready”, the transmitter can transmit the data.
100
Example Document StructurepDocument Structure
Folder File DescriptionFolder File Description
project Project.Uv2 Keil RVMDK project file
source main.c Main function
stm32f10x_it.c Interrupt handle
content stm32f10x_conf.h Stm32f10x register mapping define
stm32f10x_it.h Interrupt handle header file
init_sys.h Initial function header file
ti d l h D l f ti h d filtimedelay.h Delay function header file
rf_ctrl.h Rf device driver header file
demo termv19b.exe Uart terminal program
transmit.dat Data file
image stm32rfrx.dfu Image file
stm32rftx.dfu Image file
101
Lab1.2 – RF Transmit & Receive Stringg
Goal
User1: Use RF to transmit string User1: Use RF to transmit string
User2: User RF to receive string
Principle
PutChar();d ANSI Code
102
Lab1.3 – RF Transmit & Receive String to LCDg
Goal
User1: Use RF to transmit string User1: Use RF to transmit string
User2: User RF to receive string
Display to LCD
Principle
h () PutChar(); ANSI Code
103