-
The wireless communication EV1527
Let me talk about the format of this data communication protocol, this image I cut in the manual.
- We microcontroller according to the type of calculation period, I was STM32f103vb (4CLK roughly equal to 350um)
- Logic 1 or logic 0 sent in order starting hair DATA after the delay time by the length of the synchronization code higher than the low level transmission
-
The wireless communication transmission mode
- Transmission is very simple, made in accordance with the data format on the line, that is, it varies in data processing. No matter what the want to send data hex decimal finally be converted into binary, 01 is sent, sent from the low to the high.
- Initialization function in the transmit mode.
/ * @Description by high and low output EV1527 protocol @mode or a logic 0. 1 * / void S433_SendBit (U8 MODE) { IF (MODE == . 1 ) { Peout ( . 9 ) = . 1 ; SysTick_Delay_Us ( 350 * . 3 ); Peout ( . 9 ) = 0 ; SysTick_Delay_Us ( 350 ); } the else IF (MODE == 0 ) { Peout ( . 9 ) = . 1 ; SysTick_Delay_Us ( 350 ); Peout ( . 9 ) = 0 ; SysTick_Delay_Us ( 350 * . 3 ); } the else { debug_led ( . 1 , LED_TOGGLE); } } / * @Description synchronization pulse (or called boot) * / // sync pulse. 4: 124 void Sync_Pulse () { Peout ( . 9 ) = . 1 ; SysTick_Delay_Us ( 350 ); Peout ( . 9 ) = 0 ; SysTick_Delay_Us ( 350 * 31 is ); } / * @Description transmission function call code @num 24 bit binary decimal number * / // for transmission over the decimal processed can be changed according to the needs void S433_Send (U32 NUM) { U8 I; U32 Result = 24 , TEMP; TEMP = NUM; Sync_Pulse (); the while (result) { I =% TEMP 2 ; // modulo result of the lowest decimal digit binary number equal S433_SendBit (I); TEMP = TEMP / 2 ; // except disubstituted whole result - ; } }
-
The wireless communication mode receiver
Receiving much more complicated than sending, the idea is to
By triggering the external interrupt handler, the data is detected, rising or falling edge every triggering, remember what time to judge noise segment according to the length of time, synchronous data or wave, receiving the key is determined.
The following paragraph is initialized some initialization values, and IO pins
static volatile unsigned Long Long rx433_previous_time = 0 ; // last time the interrupt into the static volatile unsigned char Sync_Pulse_begin = 0 ; // detecting the integrity of the sync pulse is a sync pulse static volatile unsigned char rx433_begin = 0 ; // synchronization pulse ON flag 1 0 open not open static volatile unsigned Short interval_previous_time = 0 ; // a time interval //////////// static volatile U8 Rx433Cnt = 0; Static volatile U8 Rx433bit [ 30 ] = { 0 }; static volatile U8 rxbit = 0 ; static volatile U8 firstbit = 0 ; static volatile U32 Rx433 [ 64 ] = { 0 }; ///////// // // to initialize the reference pin IO pin ordinary communication void S433_SR_Init () { GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOE, the eNABLE); // enable clock GPIOE // E9 enabled GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init (GPIOE., & GPIO_InitStructure); GPIO_ResetBits (GPIOE., GPIO_Pin_9); // pin low // receiving E7 RCC_APB2PeriphClockCmd ( RCC_APB2Periph_AFIO, the ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; // input is low GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init (GPIOE.,&GPIO_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource7); EXTI_InitStructure.EXTI_Line=EXTI_Line7; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger= EXTI_Trigger_Rising_Falling; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init(&EXTI_InitStructure); NVIC_InitStructure.NVIC_IRQChannel=EXTI9_5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2; NVIC_InitStructure.NVIC_IRQChannelSubPriority=2; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); }
Judging whether the synchronization wave and detecting transmission completion
/ * @Description determine whether the sync pulse before @pre time period the number of @now now time number @return rebit open synchronization success successful synchronization synerror not sync pulses * / U8 Sync_PulseRx (pre U8, U8 now) { IF (! Pein ( 7 ) ) { // each falling edge starts measuring Sync_Pulse_begin = . 1 ; // start synchronizing pulse detecting } the else IF (Sync_Pulse_begin == . 1 && (pre == . 1 ) && (now == 31 is )) { // the condition is determined a time pulse Sync_Pulse_begin = 0 ; // synchronization preamble successfully turned off rx433_begin = . 1 ; //Data transmission started rxbit = 0 ; // data bits cleared firstbit = . 1 ; // set a wait for the next transition started return Success; } the else { Sync_Pulse_begin = 0 ; // not a pulse counter 0 return synerror; } return rxbit; } / * @Description and determination logic 0. 1 @pre period before the number @now number of segments time now @return rxerror received over bit * / U8 RX433_Bit (pre U8, U8 now) { IF (firstbit == . 1 ) { firstbit = 0 ; //This step prevents direct access to the boot completes this function } the else IF (rx433_begin == . 1 && Pein ( . 7 )) { // rising edge detector IF (rxbit> 24 ) { // can be added to a data acquisition instructions 24 to rxbit = 0 ; // zero rx433_begin = 0 ; // zero and prepare for the next group } IF (now == . 3 && pre == . 1 ) { // logic 0 Rx433bit [rxbit] = 0 ; rxbit ++ ; } the else IF (now == 1&&pre==3){//逻辑1 Rx433bit[rxbit]=1; rxbit++; }else{ //跑飞 rx433_begin=0; rxbit=0; return rxerror; } return rxbit-1; } return 0; }
External interrupt handler, often triggered as receive a variety of clutter, but can not enter the critical processing functions.
// first determine sync pulse // If a synchronization pulse, determines the begin opening the case where the data received and determines // If the data received exceeds the expected 24 bits, data bits received excess (state) // If starting from half received, ignoring this period, a period from the start void EXTI9_5_IRQHandler ( void ) { IF (EXTI_GetITStatus (EXTI_Line7) =! the RESET) { unsigned char skip_index = 0 ; // the number of data bits unsigned char skip_pervious_index = 0 ; // before several data bit unsigned Long Long now_time sys_micros = (); // now time unsigned Short= now_time interval_time - rx433_previous_time; // calculate a level of state for the length of time rx433_previous_time = now_time; // to calculate the next time to prepare for a long skip_index = (interval_time / 349 ); // duration obtain a certain level of multiple computing paragraphs a high or low skip_pervious_index = (interval_previous_time / 349 ); // supra, but is a front Sync_PulseRx (skip_pervious_index, skip_index); // synchronization pulse RX433_Bit (skip_pervious_index, skip_index); // data bit IF (interval_time < 45000 ) { interval_previous_time = interval_time; }the else { interval_previous_time = 0 ; } EXTI_ClearITPendingBit (EXTI_Line7); // Clear interrupt pending flag } }