这篇教程C++ Buffercmp函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中Buffercmp函数的典型用法代码示例。如果您正苦于以下问题:C++ Buffercmp函数的具体用法?C++ Buffercmp怎么用?C++ Buffercmp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了Buffercmp函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: main//.........这里部分代码省略......... BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO); /* Wait for User push-button press before starting the Communication */ while (BSP_PB_GetState(BUTTON_USER) != GPIO_PIN_RESET) { } /* Wait for User push-button release before starting the Communication */ while (BSP_PB_GetState(BUTTON_USER) != GPIO_PIN_SET) { } /* The board sends the message and expects to receive it back */ /*##-2- Start the transmission process #####################################*/ /* While the I2C in reception process, user can transmit data through "aTxBuffer" buffer */ /* Timeout is set to 10S */ while(HAL_I2C_Master_Transmit(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 10000)!= HAL_OK) { /* Error_Handler() function is called when Timeout error occurs. When Acknowledge failure occurs (Slave don't acknowledge its address) Master restarts communication */ if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF) { Error_Handler(); } } /* Turn LED2 on: Transfer in Transmission process is correct */ BSP_LED_On(LED2); /* Wait for User push-button press before starting the Communication */ while (BSP_PB_GetState(BUTTON_USER) != GPIO_PIN_RESET) { } /* Wait for User push-button release before starting the Communication */ while (BSP_PB_GetState(BUTTON_USER) != GPIO_PIN_SET) { } /*##-3- Put I2C peripheral in reception process ############################*/ /* Timeout is set to 10S */ while(HAL_I2C_Master_Receive(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t *)aRxBuffer, RXBUFFERSIZE, 10000) != HAL_OK) { /* Error_Handler() function is called when Timeout error occurs. When Acknowledge failure occurs (Slave don't acknowledge it's address) Master restarts communication */ if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF) { Error_Handler(); } } /* Turn LED2 off: Transfer in reception process is correct */ BSP_LED_Off(LED2); #else /* The board receives the message and sends it back */ /*##-2- Put I2C peripheral in reception process ############################*/ /* Timeout is set to 10S */ if(HAL_I2C_Slave_Receive(&I2cHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE, 10000) != HAL_OK) { /* Transfer error in reception process */ Error_Handler(); } /* Turn LED2 on: Transfer in reception process is correct */ BSP_LED_On(LED2); /*##-3- Start the transmission process #####################################*/ /* While the I2C in reception process, user can transmit data through "aTxBuffer" buffer */ /* Timeout is set to 10S */ if(HAL_I2C_Slave_Transmit(&I2cHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 10000)!= HAL_OK) { /* Transfer error in transmission process */ Error_Handler(); } /* Turn LED2 off: Transfer in transmission process is correct */ BSP_LED_Off(LED2); #endif /* MASTER_BOARD */ /*##-4- Compare the sent and received buffers ##############################*/ if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,RXBUFFERSIZE)) { /* Processing Error */ Error_Handler(); } /* Infinite loop */ while (1) { }}
开发者ID:afconsult-south,项目名称:dragonfly-fcb,代码行数:101,
示例2: main//.........这里部分代码省略......... UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; UartHandle.Init.Mode = UART_MODE_TX_RX; UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if(HAL_UART_DeInit(&UartHandle) != HAL_OK) { Error_Handler(); } if(HAL_UART_Init(&UartHandle) != HAL_OK) { Error_Handler(); } #ifdef TRANSMITTER_BOARD /* The board sends the message and expects to receive it back */ /* DMA is programmed for reception before starting the transmission, in order to be sure DMA Rx is ready when board 2 will start transmitting */ /*##-2- Program the Reception process #####################################*/ if(HAL_UART_Receive_DMA(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK) { Error_Handler(); } /*##-3- Start the transmission process #####################################*/ /* While the UART in reception process, user can transmit data through "aTxBuffer" buffer */ if(HAL_UART_Transmit_DMA(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK) { Error_Handler(); } /*##-4- Wait for the end of the transfer ###################################*/ while (UartReady != SET) { } /* Reset transmission flag */ UartReady = RESET; #else /* The board receives the message and sends it back */ /*##-2- Put UART peripheral in reception process ###########################*/ if(HAL_UART_Receive_DMA(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK) { Error_Handler(); } /*##-3- Wait for the end of the transfer ###################################*/ /* While waiting for message to come from the other board, LED3 is blinking according to the following pattern: a double flash every half-second */ while (UartReady != SET) { BSP_LED_On(LED3); HAL_Delay(100); BSP_LED_Off(LED3); HAL_Delay(100); BSP_LED_On(LED3); HAL_Delay(100); BSP_LED_Off(LED3); HAL_Delay(500); } /* Reset transmission flag */ UartReady = RESET; BSP_LED_Off(LED3); /*##-4- Start the transmission process #####################################*/ /* While the UART in reception process, user can transmit data through "aTxBuffer" buffer */ if(HAL_UART_Transmit_DMA(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK) { Error_Handler(); } #endif /* TRANSMITTER_BOARD */ /*##-5- Wait for the end of the transfer ###################################*/ while (UartReady != SET) { } /* Reset transmission flag */ UartReady = RESET; /*##-6- Compare the sent and received buffers ##############################*/ if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,RXBUFFERSIZE)) { Error_Handler(); } /* Turn on LED3 if test passes then enter infinite loop */ BSP_LED_On(LED3); /* Infinite loop */ while (1) { }}
开发者ID:NjordCZ,项目名称:stm32cubef0,代码行数:101,
示例3: main/** * @brief Main program * @param None * @retval None */int main(void){ /* STM32F4xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches - Configure the Systick to generate an interrupt each 1 msec - Set NVIC Group Priority to 4 - Global MSP (MCU Support Package) initialization */ HAL_Init(); /* Configure the system clock to 180 MHz */ SystemClock_Config(); /* Configure LED1, LED2, LED3 and LED4 */ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); /* WAKEUP button (EXTI_Line0) will be used to wakeup the system from STOP mode */ BSP_PB_Init(BUTTON_WAKEUP, BUTTON_MODE_EXTI); /* Configure Key Button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); /*##-1- Configure the SDRAM device #########################################*/ /* SDRAM device configuration */ BSP_SDRAM_Init(); /*##-2- SDRAM memory write access ##########################################*/ /* Fill the buffer to write */ Fill_Buffer(aTxBuffer, BUFFER_SIZE, 0xA244250F); /* Write data to the SDRAM memory */ BSP_SDRAM_WriteData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR, aTxBuffer, BUFFER_SIZE); /* Wait for TAMPER/KEY to be pushed to enter stop mode */ while(BSP_PB_GetState(BUTTON_TAMPER) != RESET) { } /*##-3- Issue self-refresh command to SDRAM device #########################*/ SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_SELFREFRESH_MODE; SDRAMCommandStructure.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1; SDRAMCommandStructure.AutoRefreshNumber = 1; SDRAMCommandStructure.ModeRegisterDefinition = 0; if(BSP_SDRAM_Sendcmd(&SDRAMCommandStructure) != HAL_OK) { /* Command send Error */ Error_Handler(); } /*##-4- Enter CPU power stop mode ##########################################*/ /* Put LED4 on to indicate entering to STOP mode */ BSP_LED_On(LED4); /* Request to enter STOP mode */ HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI); /*##-5- Wakeup CPU from power stop mode ###################################*/ /* Configure the system clock after wakeup from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ SystemClock_Config(); /*##-6- SDRAM memory read back access ######################################*/ SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_NORMAL_MODE; if(BSP_SDRAM_Sendcmd(&SDRAMCommandStructure) != HAL_OK) { /* Command send Error */ Error_Handler(); } /* Read back data from the SDRAM memory */ BSP_SDRAM_ReadData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR, aRxBuffer, BUFFER_SIZE); /*##-7- Checking data integrity ############################################*/ uwWriteReadStatus = Buffercmp(aTxBuffer, aRxBuffer, BUFFER_SIZE); if (uwWriteReadStatus != PASSED) { /* KO */ /* Turn on LED2 */ BSP_LED_On(LED2); } else { /* OK */ /* Turn on LED1 */ BSP_LED_On(LED1); } /* Infinite loop */ while (1)//.........这里部分代码省略.........
开发者ID:PaxInstruments,项目名称:STM32CubeF4,代码行数:101,
示例4: main/** * @brief Main program. * @param None * @retval None */int main(void){ /* STM32F0xx HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Low Level Initialization */ HAL_Init(); /* Configure LED2 */ BSP_LED_Init(LED2); /* Configure the system clock to 48 MHz */ SystemClock_Config(); /*##-1- Configure the SPI peripheral #######################################*/ /* Set the SPI parameters */ SpiHandle.Instance = SPIx; SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256; SpiHandle.Init.Direction = SPI_DIRECTION_2LINES; SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE; SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW; SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; SpiHandle.Init.CRCPolynomial = 7; SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT; SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB; SpiHandle.Init.NSS = SPI_NSS_SOFT; SpiHandle.Init.TIMode = SPI_TIMODE_DISABLE; SpiHandle.Init.NSSPMode = SPI_NSS_PULSE_DISABLE; SpiHandle.Init.CRCLength = SPI_CRC_LENGTH_8BIT;#ifdef MASTER_BOARD SpiHandle.Init.Mode = SPI_MODE_MASTER;#else SpiHandle.Init.Mode = SPI_MODE_SLAVE;#endif /* MASTER_BOARD */ if(HAL_SPI_Init(&SpiHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } #ifdef MASTER_BOARD /* Configure User push-button */ BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO); /* Wait for User push-button press before starting the Communication */ while (BSP_PB_GetState(BUTTON_USER) != GPIO_PIN_RESET) { BSP_LED_Toggle(LED2); HAL_Delay(40); } BSP_LED_Off(LED2);#endif /* MASTER_BOARD */ /*##-2- Start the Full Duplex Communication process ########################*/ /* While the SPI in TransmitReceive process, user can transmit data through "aTxBuffer" buffer & receive data through "aRxBuffer" */ if(HAL_SPI_TransmitReceive_IT(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE) != HAL_OK) { /* Transfer error in transmission process */ Error_Handler(); } /*##-3- Wait for the end of the transfer ###################################*/ /* Before starting a new communication transfer, you need to check the current state of the peripheral; if it’s busy you need to wait for the end of current transfer before starting a new one. For simplicity reasons, this example is just waiting till the end of the transfer, but application may perform other tasks while transfer operation is ongoing. */ while (HAL_SPI_GetState(&SpiHandle) != HAL_SPI_STATE_READY) { } /*##-4- Compare the sent and received buffers ##############################*/ if(Buffercmp((uint8_t*)aTxBuffer, (uint8_t*)aRxBuffer, BUFFERSIZE)) { /* Processing Error */ Error_Handler(); } /* Infinite loop */ while (1) { }}
开发者ID:jmoyerman,项目名称:stm32f0_cube,代码行数:96,
示例5: main/** * @brief Main program. * @param None * @retval None */int main(void){ /* STM32F0xx HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Low Level Initialization */ HAL_Init(); /* Configure LED2 */ BSP_LED_Init(LED2); /* Configure the system clock to 48 MHz */ SystemClock_Config(); /*##-1- Configure the SPI peripheral #######################################*/ /* Set the SPI parameters */ SpiHandle.Instance = SPIx; SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256; SpiHandle.Init.Direction = SPI_DIRECTION_2LINES; SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE; SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW; SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; SpiHandle.Init.CRCPolynomial = 7; SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT; SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB; SpiHandle.Init.NSS = SPI_NSS_SOFT; SpiHandle.Init.TIMode = SPI_TIMODE_DISABLED; SpiHandle.Init.NSSPMode = SPI_NSS_PULSE_DISABLED; SpiHandle.Init.CRCLength = SPI_CRC_LENGTH_8BIT;#ifdef MASTER_BOARD SpiHandle.Init.Mode = SPI_MODE_MASTER;#else SpiHandle.Init.Mode = SPI_MODE_SLAVE;#endif /* MASTER_BOARD */ if(HAL_SPI_Init(&SpiHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); }#ifdef MASTER_BOARD /* Configure User push-button */ BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO); /* Wait for User push-button press before starting the Communication */ while (BSP_PB_GetState(BUTTON_USER) != GPIO_PIN_RESET) { BSP_LED_Toggle(LED2); HAL_Delay(100); } BSP_LED_Off(LED2);#endif /* MASTER_BOARD */ /*##-2- Start the Full Duplex Communication process ########################*/ /* While the SPI in TransmitReceive process, user can transmit data through "aTxBuffer" buffer & receive data through "aRxBuffer" */ /* Timeout is set to 5S */ switch(HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE, 5000)) { case HAL_OK: /* Communication is completed ___________________________________________ */ /* Compare the sent and received buffers */ if (Buffercmp((uint8_t *)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE)) { /* Transfer error in transmission process */ Error_Handler(); } /* Turn LED2 on: Transfer in transmission/Reception process is correct */ BSP_LED_On(LED2); break; case HAL_TIMEOUT: /* An Error Occur ______________________________________________________ */ case HAL_ERROR: /* Call Timeout Handler */ Error_Handler(); break; default: break; } /* Infinite loop */ while (1) { }}
开发者ID:GreyCardinalRus,项目名称:stm32-cube,代码行数:98,
示例6: main/******************************************************************************** Function Name : main* Description : Main program* Input : None* Output : None* Return : None*******************************************************************************/int main(void){ #ifdef DEBUG debug();#endif SCU_MCLKSourceConfig(SCU_MCLK_OSC); /*Use OSC as the default clock source*/ SCU_PCLKDivisorConfig(SCU_PCLK_Div1); /* ARM Peripheral bus clokdivisor = 1*/ /* SCU configuration */ SCU_Configuration(); /* GPIO pins configuration */ GPIO_Configuration(); /* VIC configuration */ VIC_Configuration(); /*I2C0 & I2C1 reset */ I2C_DeInit(I2C0); I2C_DeInit(I2C1); /* Enable I2C0, I2C1 */ I2C_Cmd(I2C0, ENABLE); I2C_Cmd(I2C1, ENABLE); /* Configure GPIO2, I2C0 and I2C1 */ /* I2C0 Configuration */ I2C_Struct.I2C_GeneralCall = I2C_GeneralCall_Disable; I2C_Struct.I2C_Ack = I2C_Ack_Enable; I2C_Struct.I2C_CLKSpeed = 400000; I2C_Struct.I2C_OwnAddress = I2C0OwnAddr; I2C_Init(I2C0, &I2C_Struct); /* I2C1 Configuration */ /* we keep the same config as I2C0 for the other I2C_Struct members */ /* We change just the address*/ I2C_Struct.I2C_OwnAddress = I2C1OwnAddr; I2C_Init(I2C1, &I2C_Struct); Direction = I2C_MODE_TRANSMITTER; Fill_Buffer(I2C1_Buffer_Tx, 0x1); I2C_ITConfig(I2C1, ENABLE); I2C_ITConfig(I2C0, ENABLE); I2C_GenerateStart(I2C1, ENABLE); while (Tx_Idx < BUFFER_SIZE+1); /* Check if the transmitted data is read correctly */ TransferStatus1 = Buffercmp(I2C0_Buffer_Rx, I2C1_Buffer_Tx, BUFFER_SIZE); /* TransferStatus = PASSED, if the transmitted from I2C1 and received data by the I2C0 are the same */ /* TransferStatus = FAILED, if the transmitted from I2C1 and received data by the I2C0 are different */ /*--------------------------------------------------*/ /* Delay between transmission and reception --------*/ /*--------------------------------------------------*/ Delay(100000); /*--------------------------------------------------*/ /* Reception Phase----------------------------------*/ /*--------------------------------------------------*/ /*reset counters*/ Tx_Idx = Rx_Idx = 0; Direction = I2C_MODE_RECEIVER; Fill_Buffer(I2C0_Buffer_Tx, 0x5); I2C_GenerateStart(I2C1, ENABLE); while (Tx_Idx < BUFFER_SIZE+1); /* Check if the transmitted data is read correctly */ TransferStatus2 = Buffercmp(I2C1_Buffer_Rx, I2C0_Buffer_Tx, BUFFER_SIZE); /* TransferStatus = PASSED, if the transmitted from I2C0 and received data by the I2C1 are the same */ /* TransferStatus = FAILED, if the transmitted from I2C0 and received data by the I2C1 are different */ while(1);}
开发者ID:LupusDei,项目名称:8LU-DSP,代码行数:80,
示例7: main/** * @brief Main program * @param None * @retval None */int main(void){ /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* System clocks configuration ---------------------------------------------*/ RCC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); /* SPI1 configuration ------------------------------------------------------*/ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI1, &SPI_InitStructure); /* SPI2 configuration ------------------------------------------------------*/ SPI_InitStructure.SPI_Mode = SPI_Mode_Slave; SPI_Init(SPI2, &SPI_InitStructure); /* Enable SPI1 CRC calculation */ SPI_CalculateCRC(SPI1, ENABLE); /* Enable SPI2 CRC calculation */ SPI_CalculateCRC(SPI2, ENABLE); /* Enable SPI1 */ SPI_Cmd(SPI1, ENABLE); /* Enable SPI2 */ SPI_Cmd(SPI2, ENABLE); /* Transfer procedure */ while (TxIdx < BufferSize - 1) { /* Wait for SPI1 Tx buffer empty */ while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); /* Send SPI2 data */ SPI_I2S_SendData(SPI2, SPI2_Buffer_Tx[TxIdx]); /* Send SPI1 data */ SPI_I2S_SendData(SPI1, SPI1_Buffer_Tx[TxIdx++]); /* Wait for SPI2 data reception */ while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET); /* Read SPI2 received data */ SPI2_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPI2); /* Wait for SPI1 data reception */ while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); /* Read SPI1 received data */ SPI1_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI1); } /* Wait for SPI1 Tx buffer empty */ while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); /* Wait for SPI2 Tx buffer empty */ while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); /* Send last SPI2_Buffer_Tx data */ SPI_I2S_SendData(SPI2, SPI2_Buffer_Tx[TxIdx]); /* Enable SPI2 CRC transmission */ SPI_TransmitCRC(SPI2); /* Send last SPI1_Buffer_Tx data */ SPI_I2S_SendData(SPI1, SPI1_Buffer_Tx[TxIdx]); /* Enable SPI1 CRC transmission */ SPI_TransmitCRC(SPI1); /* Wait for SPI1 last data reception */ while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); /* Read SPI1 last received data */ SPI1_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPI1); /* Wait for SPI2 last data reception */ while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET); /* Read SPI2 last received data */ SPI2_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPI2); /* Wait for SPI1 data reception: CRC transmitted by SPI2 */ while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); /* Wait for SPI2 data reception: CRC transmitted by SPI1 */ while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET); /* Check the received data with the send ones */ TransferStatus1 = Buffercmp(SPI2_Buffer_Rx, SPI1_Buffer_Tx, BufferSize); TransferStatus2 = Buffercmp(SPI1_Buffer_Rx, SPI2_Buffer_Tx, BufferSize); /* TransferStatus1, TransferStatus2 = PASSED, if the data transmitted and received are correct */ /* TransferStatus1, TransferStatus2 = FAILED, if the data transmitted and received//.........这里部分代码省略.........
开发者ID:0x00f,项目名称:STM32F1-workarea,代码行数:101,
示例8: main//.........这里部分代码省略......... /* The board sends the message and expects to receive it back */ /*##-2- Start the transmission process #####################################*/ /* While the UART in reception process, user can transmit data through "aTxBuffer" buffer */ if(HAL_UART_Transmit_DMA(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK) { Error_Handler(); } /*##-3- Wait for the end of the transfer ###################################*/ while (UartReady != SET) { } /* Reset transmission flag */ UartReady = RESET; /*##-4- Put UART peripheral in reception process ###########################*/ if(HAL_UART_DeInit(&UartHandle) != HAL_OK) { Error_Handler(); } if(HAL_UART_Init(&UartHandle) != HAL_OK) { Error_Handler(); } if(HAL_UART_Receive_DMA(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK) { Error_Handler(); }#else /* The board receives the message and sends it back */ /*##-2- Put UART peripheral in reception process ###########################*/ if(HAL_UART_Receive_DMA(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK) { Error_Handler(); } /*##-3- Wait for the end of the transfer ###################################*/ /* While waiting for message to come from the other board, LED2 is blinking according to the following pattern: a double flash every half-second */ while (UartReady != SET) { BSP_LED_On(LED2); HAL_Delay(100); BSP_LED_Off(LED2); HAL_Delay(100); BSP_LED_On(LED2); HAL_Delay(100); BSP_LED_Off(LED2); HAL_Delay(500); } /* Reset transmission flag */ UartReady = RESET; BSP_LED_Off(LED2); /*##-4- Start the transmission process #####################################*/ /* While the UART in reception process, user can transmit data through "aTxBuffer" buffer */ if(HAL_UART_DeInit(&UartHandle) != HAL_OK) { Error_Handler(); } if(HAL_UART_Init(&UartHandle) != HAL_OK) { Error_Handler(); } if(HAL_UART_Transmit_DMA(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK) { Error_Handler(); } #endif /* TRANSMITTER_BOARD */ /*##-5- Wait for the end of the transfer ###################################*/ while (UartReady != SET) { } /* Reset transmission flag */ UartReady = RESET; /*##-6- Compare the sent and received buffers ##############################*/ if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,RXBUFFERSIZE)) { Error_Handler(); } /* Infinite loop */ while (1) { }}
开发者ID:Lembed,项目名称:STM32CubeF4-mirrors,代码行数:101,
示例9: main//.........这里部分代码省略......... TimeOut_UserCallback(); } /* Transfer complete or time out */ TimeOut = USER_TIMEOUT; while ((DMA_GetFlagStatus(I2Cx_DMA_STREAM_RX,I2Cx_RX_DMA_TCFLAG)==RESET)&&(TimeOut != 0x00)) {} if(TimeOut == 0) { TimeOut_UserCallback(); } /* Send I2Cx STOP Condition */ I2C_GenerateSTOP(I2Cx, ENABLE); /* Disable DMA RX Channel */ DMA_Cmd(I2Cx_DMA_STREAM_RX, DISABLE); /* Wait until I2Cx_DMA_STREAM_RX disabled or time out */ TimeOut = USER_TIMEOUT; while ((DMA_GetCmdStatus(I2Cx_DMA_STREAM_RX)!= DISABLE)&&(TimeOut != 0x00)) {} if(TimeOut == 0) { TimeOut_UserCallback(); } /* Disable I2C DMA request */ I2C_DMACmd(I2Cx,DISABLE); /* Clear any pending flag on Rx Stream */ DMA_ClearFlag(I2Cx_DMA_STREAM_RX, I2Cx_RX_DMA_TCFLAG | I2Cx_RX_DMA_FEIFLAG | I2Cx_RX_DMA_DMEIFLAG | / I2Cx_RX_DMA_TEIFLAG | I2Cx_RX_DMA_HTIFLAG); if (Buffercmp(TxBuffer, RxBuffer, RXBUFFERSIZE) == PASSED) { /* LED2, LED3 and LED4 Toggle */ STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); } else { /* ED2, LED3 and LED4 On */ STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); } #endif /* I2C_MASTER */ /**********************************Slave Code**********************************/#if defined (I2C_SLAVE) /* Initialize I2C peripheral */ /* I2C Init */ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DUTYCYCLE; I2C_InitStructure.I2C_OwnAddress1 = SLAVE_ADDRESS; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED; #ifndef I2C_10BITS_ADDRESS I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;#else I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_10bit;#endif /* I2C_10BITS_ADDRESS */
开发者ID:agb861,项目名称:STM32F,代码行数:66,
示例10: main/** * @brief Main program * @param None * @retval None */int main(void){ /* STM32F4xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches - Configure the Systick to generate an interrupt each 1 msec - Set NVIC Group Priority to 4 - Global MSP (MCU Support Package) initialization */ HAL_Init(); /* Configure LED3, LED4, LED5 and LED6 */ BSP_LED_Init(LED3); BSP_LED_Init(LED4); BSP_LED_Init(LED5); BSP_LED_Init(LED6); /* Configure the system clock to 84 MHz */ SystemClock_Config(); /*##-1- Configure the SPI peripheral #######################################*/ /* Set the SPI parameters */ SpiHandle.Instance = SPIx; SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; SpiHandle.Init.Direction = SPI_DIRECTION_2LINES; SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE; SpiHandle.Init.CLKPolarity = SPI_POLARITY_HIGH; SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; SpiHandle.Init.CRCPolynomial = 7; SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT; SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB; SpiHandle.Init.NSS = SPI_NSS_SOFT; SpiHandle.Init.TIMode = SPI_TIMODE_DISABLE; #ifdef MASTER_BOARD SpiHandle.Init.Mode = SPI_MODE_MASTER;#else SpiHandle.Init.Mode = SPI_MODE_SLAVE;#endif /* MASTER_BOARD */ if(HAL_SPI_Init(&SpiHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } #ifdef MASTER_BOARD /* Configure Tamper push button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); /* Wait for Tamper Button press before starting the Communication */ while (BSP_PB_GetState(BUTTON_KEY) != 1) { BSP_LED_Toggle(LED3); HAL_Delay(40); } BSP_LED_Off(LED3);#endif /* MASTER_BOARD */ /*##-2- Start the Full Duplex Communication process ########################*/ /* While the SPI in TransmitReceive process, user can transmit data through "aTxBuffer" buffer & receive data through "aRxBuffer" */ if(HAL_SPI_TransmitReceive_DMA(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE) != HAL_OK) { /* Transfer error in transmission process */ Error_Handler(); } /*##-3- Wait for the end of the transfer ###################################*/ /* Before starting a new communication transfer, you need to check the current state of the peripheral; if it’s busy you need to wait for the end of current transfer before starting a new one. For simplicity reasons, this example is just waiting till the end of the transfer, but application may perform other tasks while transfer operation is ongoing. */ while (HAL_SPI_GetState(&SpiHandle) != HAL_SPI_STATE_READY) { } /*##-4- Compare the sent and received buffers ##############################*/ if(Buffercmp((uint8_t*)aTxBuffer, (uint8_t*)aRxBuffer, BUFFERSIZE)) { /* Transfer error in transmission process */ Error_Handler(); } /* Infinite loop */ while (1) { }}
开发者ID:matianfu,项目名称:stm32f4cube,代码行数:97,
示例11: main/** * @brief Main program * @param None * @retval None */int main(void){ /* STM32F103xB HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Set NVIC Group Priority to 4 - Low Level Initialization */ HAL_Init(); /* Configure the system clock to 64 MHz */ SystemClock_Config(); /* Configure LED2, LED2 and LED2 */ BSP_LED_Init(LED2); /*##-1- Configure the SPI peripheral #######################################*/ /* Set the SPI parameters */ SpiHandle.Instance = SPIx; SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; SpiHandle.Init.Direction = SPI_DIRECTION_2LINES; SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE; SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW; SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT; SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB; SpiHandle.Init.TIMode = SPI_TIMODE_DISABLE; SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; SpiHandle.Init.CRCPolynomial = 7; SpiHandle.Init.NSS = SPI_NSS_SOFT;#ifdef MASTER_BOARD SpiHandle.Init.Mode = SPI_MODE_MASTER;#else SpiHandle.Init.Mode = SPI_MODE_SLAVE;#endif /* MASTER_BOARD */ if(HAL_SPI_Init(&SpiHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); }#ifdef MASTER_BOARD /* SPI block is enabled prior calling SPI transmit/receive functions, in order to get CLK signal properly pulled down. Otherwise, SPI CLK signal is not clean on this board and leads to errors during transfer */ __HAL_SPI_ENABLE(&SpiHandle); /* Configure User push-button */ BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO); /* Wait for User push-button press before starting the Communication */ while (BSP_PB_GetState(BUTTON_USER) != GPIO_PIN_RESET) { BSP_LED_Toggle(LED2); HAL_Delay(100); } BSP_LED_Off(LED2);#endif /* MASTER_BOARD */ /*##-2- Start the Full Duplex Communication process ########################*/ /* While the SPI in TransmitReceive process, user can transmit data through "aTxBuffer" buffer & receive data through "aRxBuffer" */ if(HAL_SPI_TransmitReceive_DMA(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE) != HAL_OK) { /* Transfer error in transmission process */ Error_Handler(); } /*##-3- Wait for the end of the transfer ###################################*/ /* Before starting a new communication transfer, you must wait the callback call to get the transfer complete confirmation or an error detection. For simplicity reasons, this example is just waiting till the end of the transfer, but application may perform other tasks while transfer operation is ongoing. */ while (wTransferState == TRANSFER_WAIT) { } switch(wTransferState) { case TRANSFER_COMPLETE : /*##-4- Compare the sent and received buffers ##############################*/ if(Buffercmp((uint8_t*)aTxBuffer, (uint8_t*)aRxBuffer, BUFFERSIZE)) { /* Processing Error */ Error_Handler(); } break; default : Error_Handler(); break; }//.........这里部分代码省略.........
开发者ID:dazuo78,项目名称:TBall,代码行数:101,
示例12: main/** * @brief Main program * @param None * @retval None*/int main(void){ /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32l1xx_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ #ifdef ENABLE_LCD_MSG_DISPLAY /* Initialize the LCD screen for information display */#ifdef USE_STM32L152D_EVAL STM32L152D_LCD_Init();#else STM32L152_LCD_Init();#endif LCD_Clear(LCD_COLOR_BLUE); LCD_SetBackColor(LCD_COLOR_BLUE); LCD_SetTextColor(LCD_COLOR_WHITE); LCD_DisplayStringLine(LCD_LINE_0, "SMT32L1xx FW Library"); LCD_DisplayStringLine(LCD_LINE_1, " EEPROM Example ");#endif /* ENABLE_LCD_MSG_DISPLAY */ /* Initialize the I2C EEPROM driver ----------------------------------------*/ sEE_Init(); /* First write in the memory followed by a read of the written data --------*/ /* Write on I2C EEPROM from sEE_WRITE_ADDRESS1 */ sEE_WriteBuffer(Tx1_Buffer, sEE_WRITE_ADDRESS1, BUFFER_SIZE1); /* Wait for EEPROM standby state */ sEE_WaitEepromStandbyState(); /* Set the Number of data to be read */ NumDataRead = BUFFER_SIZE1; /* Read from I2C EEPROM from sEE_READ_ADDRESS1 */ sEE_ReadBuffer(Rx1_Buffer, sEE_READ_ADDRESS1, (uint16_t *)(&NumDataRead)); /* Starting from this point, if the requested number of data is higher than 1, then only the DMA is managing the data transfer. Meanwhile, CPU is free to perform other tasks: // Add your code here: //... //... For simplicity reasons, this example is just waiting till the end of the transfer. */ #ifdef ENABLE_LCD_MSG_DISPLAY LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 Ongoing ");#endif /* ENABLE_LCD_MSG_DISPLAY */ /* Wait till DMA transfer is compelete (Tranfer complete interrupt handler resets the variable holding the number of data to be read) */ while (NumDataRead > 0) {} /* Check if the data written to the memory is read correctly */ TransferStatus1 = Buffercmp(Tx1_Buffer, Rx1_Buffer, BUFFER_SIZE1); /* TransferStatus1 = PASSED, if the transmitted and received data to/from the EEPROM are the same */ /* TransferStatus1 = FAILED, if the transmitted and received data to/from the EEPROM are different */#ifdef ENABLE_LCD_MSG_DISPLAY if (TransferStatus1 == PASSED) { LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 PASSED "); } else { LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 FAILED "); } #endif /* ENABLE_LCD_MSG_DISPLAY */ /* Second write in the memory followed by a read of the written data -------*/ /* Write on I2C EEPROM from sEE_WRITE_ADDRESS2 */ sEE_WriteBuffer(Tx2_Buffer, sEE_WRITE_ADDRESS2, BUFFER_SIZE2); /* Wait for EEPROM standby state */ sEE_WaitEepromStandbyState(); /* Set the Number of data to be read */ NumDataRead = BUFFER_SIZE2; /* Read from I2C EEPROM from sEE_READ_ADDRESS2 */ sEE_ReadBuffer(Rx2_Buffer, sEE_READ_ADDRESS2, (uint16_t *)(&NumDataRead)); /* Starting from this point, if the requested number of data is higher than 1, then only the DMA is managing the data transfer. Meanwhile, CPU is free to perform other tasks: //.........这里部分代码省略.........
开发者ID:jongtao,项目名称:stm32l-dev-chain,代码行数:101,
示例13: main/** * @brief Main program * @param None * @retval None */int main(void){ /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s) before to branch to application main. */ /* SPI configuration */ SPI_Config(); /* SysTick configuration */ SysTickConfig(); /* LEDs configuration */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); #ifdef SPI_MASTER /* Master board configuration */ /* Initializes the SPI communication */ SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_Init(SPIx, &SPI_InitStructure); /* The Data transfer is performed in the SPI interrupt routine */ /* Configure the Tamper Button */ STM_EVAL_PBInit(BUTTON_TAMPER,BUTTON_MODE_GPIO); /* Wait until Tamper Button is pressed */ while (STM_EVAL_PBGetState(BUTTON_TAMPER)); /* Enable the SPI peripheral */ SPI_Cmd(SPIx, ENABLE); /* Initialize Buffer counters */ ubTxIndex = 0; ubRxIndex = 0; /* Enable the Rx buffer not empty interrupt */ SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_RXNE, ENABLE); /* Enable the Tx buffer empty interrupt */ SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_TXE, ENABLE); #endif /* SPI_MASTER */ #ifdef SPI_SLAVE /* Slave board configuration */ /* Initializes the SPI communication */ SPI_InitStructure.SPI_Mode = SPI_Mode_Slave; SPI_Init(SPIx, &SPI_InitStructure); /* The Data transfer is performed in the SPI interrupt routine */ /* Initialize Buffer counters */ ubTxIndex = 0; ubRxIndex = 0; /* Enable the Rx buffer not empty interrupt */ SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_RXNE, ENABLE); /* Enable the Tx empty interrupt */ SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_TXE, ENABLE); /* Enable the SPI peripheral */ SPI_Cmd(SPIx, ENABLE); #endif /* SPI_SLAVE */ /* Waiting the end of Data transfer */ while ((ubTxIndex < BUFFERSIZE) && (ubRxIndex < BUFFERSIZE)) { } /* Disable the Rx buffer not empty interrupt */ SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_RXNE, DISABLE); /* Disable the Tx empty interrupt */ SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_TXE, DISABLE); /* Disable the SPI peripheral */ SPI_Cmd(SPIx, DISABLE); if (Buffercmp(aTxBuffer, aRxBuffer, BUFFERSIZE) != FAILED) { /* Turn ON LED1 and LED3 */ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOn(LED3); /* Turn OFF LED2 and LED4 */ STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED4); } else {//.........这里部分代码省略.........
开发者ID:Haensi2000,项目名称:ECSE426G7,代码行数:101,
示例14: main/** * @brief Main program. * @param None * @retval None */int main(void){ /* System Clocks Configuration */ RCC_Configuration(); /* FSMC for SRAM and SRAM pins configuration */ FSMC_SRAM_Init(); /* Write to FSMC -----------------------------------------------------------*/ /* DMA2 channel5 configuration */ DMA_DeInit(DMA2_Channel5); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SRC_Const_Buffer; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Bank1_SRAM3_ADDR; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 32; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Enable; DMA_Init(DMA2_Channel5, &DMA_InitStructure); /* Enable DMA2 channel5 */ DMA_Cmd(DMA2_Channel5, ENABLE); /* Check if DMA2 channel5 transfer is finished */ while(!DMA_GetFlagStatus(DMA2_FLAG_TC5)); /* Clear DMA2 channel5 transfer complete flag bit */ DMA_ClearFlag(DMA2_FLAG_TC5); /* Read from FSMC ----------------------------------------------------------*/ /* Destination buffer initialization */ for(Idx=0; Idx<128; Idx++) DST_Buffer[Idx]=0; /* DMA1 channel3 configuration */ DMA_DeInit(DMA1_Channel3); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)Bank1_SRAM3_ADDR; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)DST_Buffer; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 128; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Enable; DMA_Init(DMA1_Channel3, &DMA_InitStructure); /* Enable DMA1 channel3 */ DMA_Cmd(DMA1_Channel3, ENABLE); /* Check if DMA1 channel3 transfer is finished */ while(!DMA_GetFlagStatus(DMA1_FLAG_TC3)); /* Clear DMA1 channel3 transfer complete flag bit */ DMA_ClearFlag(DMA1_FLAG_TC3); /* Check if the transmitted and received data are equal */ TransferStatus = Buffercmp(SRC_Const_Buffer, (uint32_t*)DST_Buffer, BufferSize); /* TransferStatus = PASSED, if the transmitted and received data are the same */ /* TransferStatus = FAILED, if the transmitted and received data are different */ while (1) { }}
开发者ID:phungyen,项目名称:stm32f10x_stdperiph_lib,代码行数:77,
示例15: SD_demo/** * @brief SD Demo * @param None * @retval None */void SD_demo (void){ uint8_t SD_state = MSD_OK; __IO uint8_t prev_status = 0; SD_SetHint(); SD_state = BSP_SD_Init(); /* Check if the SD card is plugged in the slot */ if(BSP_SD_IsDetected() == SD_PRESENT) { BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"SD Connected ", LEFT_MODE); } else { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"SD Not Connected", LEFT_MODE); } BSP_LCD_SetTextColor(LCD_COLOR_BLACK); if(SD_state != MSD_OK) { BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD INITIALIZATION : FAIL.", LEFT_MODE); BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD Test Aborted.", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD INITIALIZATION : OK.", LEFT_MODE); BSP_SD_GetCardInfo(&CardInfo); if(SD_state != MSD_OK) { BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD GET CARD INFO : FAIL.", LEFT_MODE); BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD Test Aborted.", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD GET CARD INFO : OK.", LEFT_MODE); SD_state = BSP_SD_Erase(BLOCK_START_ADDR, (BLOCKSIZE * NUM_OF_BLOCKS)); /* Verify that SD card is ready to use after the Erase */ SD_state |= BSP_SD_GetStatus(); if(SD_state != MSD_OK) { BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD ERASE : FAILED.", LEFT_MODE); BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD Test Aborted.", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD ERASE : OK.", LEFT_MODE); /* Fill the buffer to write */ Fill_Buffer(aTxBuffer, BUFFER_WORDS_SIZE, 0x22FF); SD_state = BSP_SD_WriteBlocks((uint32_t *)aTxBuffer, BLOCK_START_ADDR, BLOCKSIZE, NUM_OF_BLOCKS); if(SD_state != MSD_OK) { BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD WRITE : FAILED.", LEFT_MODE); BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD Test Aborted.", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD WRITE : OK.", LEFT_MODE); SD_state = BSP_SD_ReadBlocks((uint32_t *)aRxBuffer, BLOCK_START_ADDR, BLOCKSIZE, NUM_OF_BLOCKS); if(SD_state != MSD_OK) { BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD READ : FAILED.", LEFT_MODE); BSP_LCD_DisplayStringAt(20, 175, (uint8_t *)"SD Test Aborted.", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD READ : OK.", LEFT_MODE); if(Buffercmp(aTxBuffer, aRxBuffer, BUFFER_WORDS_SIZE) > 0) { BSP_LCD_DisplayStringAt(20, 175, (uint8_t *)"SD COMPARE : FAILED.", LEFT_MODE); BSP_LCD_DisplayStringAt(20, 190, (uint8_t *)"SD Test Aborted.", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, 175, (uint8_t *)"SD TEST : OK.", LEFT_MODE); } } } } } } while (1) { /* Check if the SD card is plugged in the slot *///.........这里部分代码省略.........
开发者ID:acrepina,项目名称:STM32F7_serverWEB,代码行数:101,
示例16: main//.........这里部分代码省略......... while ((SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_TXE) == RESET)&&(TimeOut != 0x00)) {} if(TimeOut == 0) { TimeOut_UserCallback(); } TimeOut = USER_TIMEOUT; while ((SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_BSY) == SET)&&(TimeOut != 0x00)) {} if(TimeOut == 0) { TimeOut_UserCallback(); } /* Clear DMA1 global flags */ DMA_ClearFlag(TIMx_CHANNEL_DMA_FLAG_GL); DMA_ClearFlag(SPIx_RX_DMA_FLAG_GL); /* Disable the DMA channels */ DMA_Cmd(SPIx_RX_DMA_CHANNEL, DISABLE); DMA_Cmd(TIMx_CHANNEL_DMA_CHANNEL, DISABLE); /* Disable the SPI Rx and Tx DMA requests */ SPI_I2S_DMACmd(SPIx, SPI_I2S_DMAReq_Rx, DISABLE); /* TIM disable counter */ TIM_Cmd(TIMx, DISABLE); switch (NumberOfByte) { /* CMD_RIGHT command received */ case CMD_RIGHT_SIZE: if ((Buffercmp(TxBuffer, RxBuffer, CMD_RIGHT_SIZE, SPI_DATAMASK) != FAILED) && (CommandReceived == CMD_ACK)) { /* Turn ON LED2 and LED3 */ STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); /* Turn OFF LED4 */ STM_EVAL_LEDOff(LED4); } break; /* CMD_LEFT command received */ case CMD_LEFT_SIZE: if ((Buffercmp(TxBuffer, RxBuffer, CMD_LEFT_SIZE, SPI_DATAMASK) != FAILED) && (CommandReceived == CMD_ACK)) { /* Turn ON LED4 */ STM_EVAL_LEDOn(LED4); /* Turn OFF LED2 and LED3 */ STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); } break; /* CMD_UP command received */ case CMD_UP_SIZE: if ((Buffercmp(TxBuffer, RxBuffer, CMD_UP_SIZE, SPI_DATAMASK) != FAILED) && (CommandReceived == CMD_ACK)) { /* Turn ON LED2 */ STM_EVAL_LEDOn(LED2); /* Turn OFF LED3 and LED4 */ STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); } break; /* CMD_DOWN command received */ case CMD_DOWN_SIZE:
开发者ID:Azizou,项目名称:stm32f0_devel,代码行数:67,
示例17: main/** * @brief Main program * @param None * @retval None */int main(void){ /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* Initialize Leds mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); /* Initialize the SPI FLASH driver */ sFLASH_Init(); /* Get SPI Flash ID */ FlashID = sFLASH_ReadID(); /* Check the SPI Flash ID */ if (FlashID == sFLASH_ID) { /* OK: Turn on LD1 */ STM_EVAL_LEDOn(LED1); /* Perform a write in the Flash followed by a read of the written data */ /* Erase SPI FLASH Sector to write on */ sFLASH_EraseSector(FLASH_SectorToErase); /* Write Tx_Buffer data to SPI FLASH memory */ sFLASH_WriteBuffer(Tx_Buffer, FLASH_WriteAddress, BufferSize); /* Read data from SPI FLASH memory */ sFLASH_ReadBuffer(Rx_Buffer, FLASH_ReadAddress, BufferSize); /* Check the correctness of written dada */ TransferStatus1 = Buffercmp(Tx_Buffer, Rx_Buffer, BufferSize); /* TransferStatus1 = PASSED, if the transmitted and received data by SPI1 are the same */ /* TransferStatus1 = FAILED, if the transmitted and received data by SPI1 are different */ /* Perform an erase in the Flash followed by a read of the written data */ /* Erase SPI FLASH Sector to write on */ sFLASH_EraseSector(FLASH_SectorToErase); /* Read data from SPI FLASH memory */ sFLASH_ReadBuffer(Rx_Buffer, FLASH_ReadAddress, BufferSize); /* Check the correctness of erasing operation dada */ for (Index = 0; Index < BufferSize; Index++) { if (Rx_Buffer[Index] != 0xFF) { TransferStatus2 = FAILED; } } /* TransferStatus2 = PASSED, if the specified sector part is erased */ /* TransferStatus2 = FAILED, if the specified sector part is not well erased */ } else { /* Error: Turn on LD2 */ STM_EVAL_LEDOn(LED2); } while (1) {}}
开发者ID:Joe-Merten,项目名称:Stm32,代码行数:74,
示例18: main//.........这里部分代码省略......... if(HAL_UART_Init(&UartHandle) != HAL_OK) { Error_Handler(); } #ifdef TRANSMITTER_BOARD /* Configure Button Key */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); /* Toggle led2 waiting for user to press button */ BSP_LED_On(LED2); /* Wait for Button Key press before starting the Communication */ while (BSP_PB_GetState(BUTTON_KEY) == RESET) { } /* Wait for Button Key to be release before starting the Communication */ while (BSP_PB_GetState(BUTTON_KEY) == SET) { } /* Turn led2 off */ BSP_LED_Off(LED2); /* The board sends the message and expects to receive it back */ /*##-2- Start the transmission process #####################################*/ /* While the UART in reception process, user can transmit data through "aTxBuffer" buffer */ if(HAL_UART_Transmit_IT(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK) { Error_Handler(); } /*##-3- Wait for the end of the transfer ###################################*/ while (UartReady != SET) { } /* Reset transmission flag */ UartReady = RESET; /*##-4- Put UART peripheral in reception process ###########################*/ if(HAL_UART_Receive_IT(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK) { Error_Handler(); }#else /* The board receives the message and sends it back */ /*##-2- Put UART peripheral in reception process ###########################*/ if(HAL_UART_Receive_IT(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK) { Error_Handler(); } /*##-3- Wait for the end of the transfer ###################################*/ while (UartReady != SET) { } /* Reset transmission flag */ UartReady = RESET; /*##-4- Start the transmission process #####################################*/ /* While the UART in reception process, user can transmit data through "aTxBuffer" buffer */ if(HAL_UART_Transmit_IT(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK) { Error_Handler(); } #endif /* TRANSMITTER_BOARD */ /*##-5- Wait for the end of the transfer ###################################*/ while (UartReady != SET) { } /* Reset transmission flag */ UartReady = RESET; /*##-6- Compare the sent and received buffers ##############################*/ if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,RXBUFFERSIZE)) { Error_Handler(); } /* Turn LED2 on: Transfer process is correct */ BSP_LED_On(LED2); /* Infinite loop */ while (1) { }}
开发者ID:shjere,项目名称:common,代码行数:101,
示例19: main/** * @brief Main program * @param None * @retval None */int main(void){ /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* System Clocks Configuration */ RCC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration();/* USARTy and USARTz configuration -------------------------------------------*/ /* USARTy and USARTz configured as follow: - BaudRate = 230400 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 230400; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* Configure USARTy */ USART_Init(USARTy, &USART_InitStructure); /* Configure USARTz */ USART_Init(USARTz, &USART_InitStructure); /* Enable the USARTy */ USART_Cmd(USARTy, ENABLE); /* Enable the USARTz */ USART_Cmd(USARTz, ENABLE); /* Enable USARTy Half Duplex Mode*/ USART_HalfDuplexCmd(USARTy, ENABLE); /* Enable USARTz Half Duplex Mode*/ USART_HalfDuplexCmd(USARTz, ENABLE); while(NbrOfDataToRead2--) { /* Wait until end of transmit */ while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } /* Write one byte in the USARTy Transmit Data Register */ USART_SendData(USARTy, TxBuffer1[TxCounter1++]); /* Wait the byte is entirtly received by USARTz */ while(USART_GetFlagStatus(USARTz, USART_FLAG_RXNE) == RESET) { } /* Store the received byte in the RxBuffer2 */ RxBuffer2[RxCounter2++] = USART_ReceiveData(USARTz); } /* Clear the USARTy Data Register */ USART_ReceiveData(USARTy); while(NbrOfDataToRead1--) { /* Wait until end of transmit */ while(USART_GetFlagStatus(USARTz, USART_FLAG_TXE)== RESET) { } /* Write one byte in the USARTz Transmit Data Register */ USART_SendData(USARTz, TxBuffer2[TxCounter2++]); /* Wait the byte is entirtly received by USARTy */ while(USART_GetFlagStatus(USARTy,USART_FLAG_RXNE) == RESET) { } /* Store the received byte in the RxBuffer1 */ RxBuffer1[RxCounter1++] = USART_ReceiveData(USARTy); } /* Check the received data with the send ones */ TransferStatus1 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1); /* TransferStatus = PASSED, if the data transmitted from USARTy and received by USARTz are the same */ /* TransferStatus = FAILED, if the data transmitted from USARTy and received by USARTz are different */ TransferStatus2 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2); /* TransferStatus = PASSED, if the data transmitted from USARTz and received by USARTy are the same */ /* TransferStatus = FAILED, if the data transmitted from USARTz and received by USARTy are different *///.........这里部分代码省略.........
开发者ID:WaelG,项目名称:Thinner-Client,代码行数:101,
示例20: main/******************************************************************************** Function Name : main* Description : Main program* Input : None* Output : None* Return : None*******************************************************************************/int main(void){#ifdef DEBUG debug();#endif /* System clocks configuration ---------------------------------------------*/ RCC_Configuration(); /* NVIC configuration ------------------------------------------------------*/ NVIC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); /* 1st phase: SPI1 Master and SPI2 Slave */ /* SPI1 Config -------------------------------------------------------------*/ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; 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_2Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI1, &SPI_InitStructure); /* SPI2 Config -------------------------------------------------------------*/ SPI_InitStructure.SPI_Mode = SPI_Mode_Slave; SPI_Init(SPI2, &SPI_InitStructure); /* Enable SPI1 */ SPI_Cmd(SPI1, ENABLE); /* Enable SPI2 */ SPI_Cmd(SPI2, ENABLE); /* Transfer procedure */ while (TxIdx < BufferSize) { /* Wait for SPI1 Tx buffer empty */ while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); /* Send SPI2 data */ SPI_I2S_SendData(SPI2, SPI2_Buffer_Tx[TxIdx]); /* Send SPI1 data */ SPI_I2S_SendData(SPI1, SPI1_Buffer_Tx[TxIdx++]); /* Wait for SPI2 data reception */ while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET); /* Read SPI2 received data */ SPI2_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPI2); /* Wait for SPI1 data reception */ while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); /* Read SPI1 received data */ SPI1_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI1); } /* Check the corectness of written dada */ TransferStatus1 = Buffercmp(SPI2_Buffer_Rx, SPI1_Buffer_Tx, BufferSize); TransferStatus2 = Buffercmp(SPI1_Buffer_Rx, SPI2_Buffer_Tx, BufferSize); /* TransferStatus1, TransferStatus2 = PASSED, if the transmitted and received data are equal */ /* TransferStatus1, TransferStatus2 = FAILED, if the transmitted and received data are different */ /* 2nd phase: SPI1 Slave and SPI2 Master */ /* SPI1 Re-configuration ---------------------------------------------------*/ SPI_InitStructure.SPI_Mode = SPI_Mode_Slave; SPI_Init(SPI1, &SPI_InitStructure); /* SPI2 Re-configuration ---------------------------------------------------*/ SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_Init(SPI2, &SPI_InitStructure); /* Reset TxIdx, RxIdx indexes and receive tables values */ TxIdx = 0; RxIdx = 0; for (k = 0; k < BufferSize; k++) SPI2_Buffer_Rx[k] = 0; for (k = 0; k < BufferSize; k++) SPI1_Buffer_Rx[k] = 0; /* Transfer procedure */ while (TxIdx < BufferSize) { /* Wait for SPI2 Tx buffer empty */ while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); /* Send SPI1 data */ SPI_I2S_SendData(SPI1, SPI1_Buffer_Tx[TxIdx]); /* Send SPI2 data */ SPI_I2S_SendData(SPI2, SPI2_Buffer_Tx[TxIdx++]); /* Wait for SPI1 data reception */ while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); /* Read SPI1 received data */ SPI1_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPI1); /* Wait for SPI2 data reception *///.........这里部分代码省略.........
开发者ID:AkeelAli,项目名称:microprocessorsystems,代码行数:101,
示例21: main//.........这里部分代码省略.........#else/* initialize the User push-button in Interrupt mode */ BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI); /* Wait for User push-button press before starting the test. In the meantime, LED3 is blinking */ while(UserButtonStatus == 0) { /* Toggle LED3 */ BSP_LED_Toggle(LED3); HAL_Delay(100); } /*##-2- Send the wake-up from stop mode first trigger ######################*/ /* (RXNE flag setting) */ BSP_LED_On(LED3); if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aWakeUpTrigger1, COUNTOF(aWakeUpTrigger1)-1, 5000)!= HAL_OK) { Error_Handler(); } /* Put UART peripheral in reception process to wait for other board wake up confirmation */ if(HAL_UART_Receive(&UartHandle, (uint8_t *)aRxBuffer, COUNTOF(aTxBuffer1)-1, 10000) != HAL_OK) { Error_Handler(); } BSP_LED_Off(LED3); /* Compare the expected and received buffers */ if(Buffercmp((uint8_t*)aTxBuffer1,(uint8_t*)aRxBuffer,COUNTOF(aTxBuffer1)-1)) { Error_Handler(); } /* wait for two seconds before test second step */ HAL_Delay(2000); /*##-3- Send the wake-up from stop mode second trigger #####################*/ /* (start Bit detection) */ BSP_LED_On(LED3); if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aWakeUpTrigger2, COUNTOF(aWakeUpTrigger2)-1, 5000)!= HAL_OK) { Error_Handler(); } /* Put UART peripheral in reception process to wait for other board wake up confirmation */ if(HAL_UART_Receive(&UartHandle, (uint8_t *)aRxBuffer, COUNTOF(aTxBuffer2)-1, 10000) != HAL_OK) { Error_Handler(); } BSP_LED_Off(LED3); /* Compare the expected and received buffers */ if(Buffercmp((uint8_t*)aTxBuffer2,(uint8_t*)aRxBuffer,COUNTOF(aTxBuffer2)-1)) { Error_Handler(); } /* wait for two seconds before test third step */ HAL_Delay(2000);
开发者ID:jmoyerman,项目名称:stm32f0_cube,代码行数:66,
示例22: main/** * @brief Main program * @param None * @retval None */int main(void){ /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* USART configuration -----------------------------------------------------*/ USART_Config(); /* SysTick configuration ---------------------------------------------------*/ SysTickConfig(); /* LEDs configuration ------------------------------------------------------*/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3);#ifdef USART_TRANSMITTER /* Tamper Button Configuration ---------------------------------------------*/ STM_EVAL_PBInit(BUTTON_TAMPER,BUTTON_MODE_GPIO); /* Enable DMA USART TX Stream */ DMA_Cmd(USARTx_TX_DMA_STREAM,ENABLE); /* Wait until Tamper Button is pressed */ while (STM_EVAL_PBGetState(BUTTON_TAMPER)); /* Enable USART DMA TX Requsts */ USART_DMACmd(USARTx, USART_DMAReq_Tx, ENABLE); /* Waiting the end of Data transfer */ while (USART_GetFlagStatus(USARTx,USART_FLAG_TC)==RESET); while (DMA_GetFlagStatus(USARTx_TX_DMA_STREAM,USARTx_TX_DMA_FLAG_TCIF)==RESET); /* Clear DMA Transfer Complete Flags */ DMA_ClearFlag(USARTx_TX_DMA_STREAM,USARTx_TX_DMA_FLAG_TCIF); /* Clear USART Transfer Complete Flags */ USART_ClearFlag(USARTx,USART_FLAG_TC);#endif /* USART_TRANSMITTER */#ifdef USART_RECEIVER /* Enable DMA USART RX Stream */ DMA_Cmd(USARTx_RX_DMA_STREAM,ENABLE); /* Enable USART DMA RX Requsts */ USART_DMACmd(USARTx, USART_DMAReq_Rx, ENABLE); /* Waiting the end of Data transfer */ while (USART_GetFlagStatus(USARTx,USART_FLAG_TC)==RESET); while (DMA_GetFlagStatus(USARTx_RX_DMA_STREAM,USARTx_RX_DMA_FLAG_TCIF)==RESET); /* Clear DMA Transfer Complete Flags */ DMA_ClearFlag(USARTx_RX_DMA_STREAM,USARTx_RX_DMA_FLAG_TCIF); /* Clear USART Transfer Complete Flags */ USART_ClearFlag(USARTx,USART_FLAG_TC); if (Buffercmp(aTxBuffer, aRxBuffer, BUFFERSIZE) != FAILED) { /* Turn ON LED2 */ STM_EVAL_LEDOn(LED2); } else { /* Turn ON LED3 */ STM_EVAL_LEDOn(LED3); }#endif /* USART_RECEIVER */ while (1) { }}
开发者ID:szymon2103,项目名称:Stm32,代码行数:85,
示例23: main/** * @brief Main program * @param None * @retval None */int main(void){ /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* System Clocks Configuration */ RCC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); /* Configure the DMA */ DMA_Configuration();/* USARTy and USARTz configuration ------------------------------------------------------*/ /* USARTy and USARTz configured as follow: - BaudRate = 230400 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 230400; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* Configure USARTy */ USART_Init(USARTy, &USART_InitStructure); /* Configure USARTz */ USART_Init(USARTz, &USART_InitStructure); /* Enable USARTy DMA Rx and TX request */ USART_DMACmd(USARTy, USART_DMAReq_Rx | USART_DMAReq_Tx, ENABLE); /* Enable USARTz DMA Rx and TX request */ USART_DMACmd(USARTz, USART_DMAReq_Rx | USART_DMAReq_Tx, ENABLE); /* Enable USARTy TX DMA1 Channel */ DMA_Cmd(USARTy_Tx_DMA_Channel, ENABLE); /* Enable USARTy RX DMA1 Channel */ DMA_Cmd(USARTy_Rx_DMA_Channel, ENABLE); /* Enable USARTz TX DMA1 Channel */ DMA_Cmd(USARTz_Tx_DMA_Channel, ENABLE); /* Enable USARTz RX DMA1 Channel */ DMA_Cmd(USARTz_Rx_DMA_Channel, ENABLE); /* Enable the USARTy */ USART_Cmd(USARTy, ENABLE); /* Enable the USARTz */ USART_Cmd(USARTz, ENABLE); /* Wait until USARTy TX DMA1 Channel Transfer Complete */ while (DMA_GetFlagStatus(USARTy_Tx_DMA_FLAG) == RESET) { } /* Wait until USARTy RX DMA1 Channel Transfer Complete */ while (DMA_GetFlagStatus(USARTy_Rx_DMA_FLAG) == RESET) { } /* Wait until USARTz TX DMA1 Channel Transfer Complete */ while (DMA_GetFlagStatus(USARTz_Tx_DMA_FLAG) == RESET) { } /* Wait until USARTz RX DMA1 Channel Transfer Complete */ while (DMA_GetFlagStatus(USARTz_Rx_DMA_FLAG) == RESET) { } /* Check the received data with the send ones */ TransferStatus1 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2); /* TransferStatus1 = PASSED, if the data transmitted from USARTz and received by USARTy are the same */ /* TransferStatus1 = FAILED, if the data transmitted from USARTz and received by USARTy are different */ TransferStatus2 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1); /* TransferStatus2 = PASSED, if the data transmitted from USARTy and received by USARTz are the same */ /* TransferStatus2 = FAILED, if the data transmitted from USARTy and received by USARTz are different */ while (1) { }}
开发者ID:szymon2103,项目名称:Stm32,代码行数:98,
示例24: main//.........这里部分代码省略......... /* Configure the system clock to 48 MHz */ SystemClock_Config(); /*##-1- Configure the UART peripheral ######################################*/ /* Put the USART peripheral in the Asynchronous mode (UART Mode) */ /* UART configured as follows: - Word Length = 8 Bits - Stop Bit = One Stop bit - Parity = None - BaudRate = 9600 baud - Hardware flow control disabled (RTS and CTS signals) */ UartHandle.Instance = USARTx; UartHandle.Init.BaudRate = 9600; UartHandle.Init.WordLength = UART_WORDLENGTH_8B; UartHandle.Init.StopBits = UART_STOPBITS_1; UartHandle.Init.Parity = UART_PARITY_NONE; UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; UartHandle.Init.Mode = UART_MODE_TX_RX; UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if(HAL_UART_DeInit(&UartHandle) != HAL_OK) { Error_Handler(); } if(HAL_UART_Init(&UartHandle) != HAL_OK) { Error_Handler(); } #ifdef TRANSMITTER_BOARD /* Configure User push-button in Interrupt mode */ BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI); /* Wait for User push-button press before starting the Communication. In the meantime, LED2 is blinking */ while(UserButtonStatus == 0) { /* Toggle LED2*/ BSP_LED_Toggle(LED2); HAL_Delay(100); } BSP_LED_Off(LED2); /* The board sends the message and expects to receive it back */ /*##-2- Start the transmission process #####################################*/ /* While the UART in reception process, user can transmit data through "aTxBuffer" buffer */ if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 5000)!= HAL_OK) { Error_Handler(); } /*##-3- Put UART peripheral in reception process ###########################*/ if(HAL_UART_Receive(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE, 5000) != HAL_OK) { Error_Handler(); } #else /* The board receives the message and sends it back */ /*##-2- Put UART peripheral in reception process ###########################*/ if(HAL_UART_Receive(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE, 0x1FFFFFF) != HAL_OK) { Error_Handler(); } /*##-3- Start the transmission process #####################################*/ /* While the UART in reception process, user can transmit data through "aTxBuffer" buffer */ if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 5000)!= HAL_OK) { Error_Handler(); } #endif /* TRANSMITTER_BOARD */ /*##-4- Compare the sent and received buffers ##############################*/ if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,RXBUFFERSIZE)) { Error_Handler(); } /* Turn on LED2 if test passes then enter infinite loop */ BSP_LED_On(LED2); /* Infinite loop */ while (1) { }}
开发者ID:GreyCardinalRus,项目名称:stm32-cube,代码行数:101,
示例25: main//.........这里部分代码省略......... /* Before starting a new communication transfer, you need to check the current state of the peripheral; if it’s busy you need to wait for the end of current transfer before starting a new one. For simplicity reasons, this example is just waiting till the end of the transfer, but application may perform other tasks while transfer operation is ongoing. */ while (HAL_I2C_GetState(&I2cHandle) != HAL_I2C_STATE_READY) { } /*##-7- Master receives aRxBuffer from slave #############################*/ while(HAL_I2C_Master_Receive_IT(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t*)aRxBuffer, RXBUFFERSIZE)!= HAL_OK) { /* Error_Handler() function is called when Timout error occurs. When Acknowledge failure ocucurs (Slave don't acknowledge it's address) Master restarts communication */ if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF) { Error_Handler(); } } /* Before starting a new communication transfer, you need to check the current state of the peripheral; if it’s busy you need to wait for the end of current transfer before starting a new one. For simplicity reasons, this example is just waiting till the end of the transfer, but application may perform other tasks while transfer operation is ongoing. */ while (HAL_I2C_GetState(&I2cHandle) != HAL_I2C_STATE_READY) { } /* Check correctness of received buffer ##################################*/ if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,hRxNumData)) { /* Processing Error */ Error_Handler(); } /* Flush Rx buffers */ Flush_Buffer((uint8_t*)aRxBuffer,RXBUFFERSIZE); /* Toggle LED1 */ BSP_LED_Toggle(LED1); /* This delay permit the key to see LED3 toggling */ HAL_Delay(25); }#else while(1) { /* Initialize number of data variables */ hTxNumData = 0; hRxNumData = 0; /*##-2- Slave receive request from master ################################*/ while(HAL_I2C_Slave_Receive_IT(&I2cHandle, (uint8_t*)&bTransferRequest, 1)!= HAL_OK) { } /* Before starting a new communication transfer, you need to check the current state of the peripheral; if it’s busy you need to wait for the end of current transfer before starting a new one. For simplicity reasons, this example is just waiting till the end of the transfer, but application may perform other tasks while transfer operation is ongoing. */
开发者ID:PaxInstruments,项目名称:STM32CubeF3,代码行数:67,
示例26: main//.........这里部分代码省略......... in his TxBuffer */ /* DMA channel Rx of USART Configuration */ DMA_DeInit(USARTx_RX_DMA_CHANNEL); DMA_InitStructure.DMA_PeripheralBaseAddr = USARTx_RDR_ADDRESS; DMA_InitStructure.DMA_BufferSize = (uint16_t)CmdBuffer[0x01]; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) RxBuffer; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_Priority = DMA_Priority_Low; DMA_Init(USARTx_RX_DMA_CHANNEL, &DMA_InitStructure); USART_DMACmd(USARTx, USART_DMAReq_Rx , ENABLE); /* Enable the DMA channel */ DMA_Cmd(USARTx_RX_DMA_CHANNEL, ENABLE); /* Wait the USART DMA Rx transfer complete or time out */ TimeOut = USER_TIMEOUT; while ((DMA_GetFlagStatus(USARTx_RX_DMA_FLAG_TC) == RESET)&&(TimeOut != 0x00)) { } if(TimeOut == 0) { TimeOut_UserCallback(); } /* Clear DMA1 global flags */ DMA_ClearFlag(USARTx_TX_DMA_FLAG_GL); DMA_ClearFlag(USARTx_RX_DMA_FLAG_GL); /* Disable the DMA channels */ DMA_Cmd(USARTx_RX_DMA_CHANNEL, DISABLE); /* Disable the USART Rx DMA requests */ USART_DMACmd(USARTx, USART_DMAReq_Rx, DISABLE); switch (CmdBuffer[0x01]) { /* CMD_RIGHT command received */ case CMD_RIGHT_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_RIGHT_SIZE) != FAILED) { /* Turn ON LED2 and LED3 */ STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); /* Turn OFF LED4 */ STM_EVAL_LEDOff(LED4); } break; /* CMD_LEFT command received */ case CMD_LEFT_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_LEFT_SIZE) != FAILED) { /* Turn ON LED4 */ STM_EVAL_LEDOn(LED4); /* Turn OFF LED2 and LED3 */ STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); } break; /* CMD_UP command received */ case CMD_UP_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_UP_SIZE) != FAILED) { /* Turn ON LED2 */ STM_EVAL_LEDOn(LED2); /* Turn OFF LED3 and LED4 */ STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); } break; /* CMD_DOWN command received */ case CMD_DOWN_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_DOWN_SIZE) != FAILED) { /* Turn ON LED3 */ STM_EVAL_LEDOn(LED3); /* Turn OFF LED2 and LED4 */ STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED4); } break; /* CMD_SEL command received */ case CMD_SEL_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_SEL_SIZE) != FAILED) { /* Turn ON all LED2, LED3 and LED4 */ STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); } break; default: break; } CmdBuffer[0x00] = 0x00; } }}
开发者ID:beattie,项目名称:FreeRTOS-Nucleo-f091rc,代码行数:101,
示例27: main//.........这里部分代码省略......... while(HAL_I2C_Master_Transmit_IT(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK) { /* Error_Handler() function is called when Timeout error occurs. When Acknowledge failure occurs (Slave don't acknowledge its address) Master restarts communication */ if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF) { Error_Handler(); } } /*##-3- Wait for the end of the transfer ###################################*/ /* Before starting a new communication transfer, you need to check the current state of the peripheral; if it’s busy you need to wait for the end of current transfer before starting a new one. For simplicity reasons, this example is just waiting till the end of the transfer, but application may perform other tasks while transfer operation is ongoing. */ while (HAL_I2C_GetState(&I2cHandle) != HAL_I2C_STATE_READY) { } /* Wait for Key push-button press before starting the Communication */ while (BSP_PB_GetState(BUTTON_KEY) != GPIO_PIN_RESET) { } /* Wait for Key push-button release before starting the Communication */ while (BSP_PB_GetState(BUTTON_KEY) != GPIO_PIN_SET) { } /*##-4- Put I2C peripheral in reception process ###########################*/ while(HAL_I2C_Master_Receive_IT(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK) { /* Error_Handler() function is called when Timeout error occurs. When Acknowledge failure occurs (Slave don't acknowledge it's address) Master restarts communication */ if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF) { Error_Handler(); } }#else /* The board receives the message and sends it back */ /*##-2- Put I2C peripheral in reception process ###########################*/ if(HAL_I2C_Slave_Receive_IT(&I2cHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK) { /* Transfer error in reception process */ Error_Handler(); } /*##-3- Wait for the end of the transfer ###################################*/ /* Before starting a new communication transfer, you need to check the current state of the peripheral; if it’s busy you need to wait for the end of current transfer before starting a new one. For simplicity reasons, this example is just waiting till the end of the transfer, but application may perform other tasks while transfer operation is ongoing. */ while (HAL_I2C_GetState(&I2cHandle) != HAL_I2C_STATE_READY) { } /*##-4- Start the transmission process #####################################*/ /* While the I2C in reception process, user can transmit data through "aTxBuffer" buffer */ if(HAL_I2C_Slave_Transmit_IT(&I2cHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK) { /* Transfer error in transmission process */ Error_Handler(); } #endif /* MASTER_BOARD */ /*##-5- Wait for the end of the transfer ###################################*/ /* Before starting a new communication transfer, you need to check the current state of the peripheral; if it’s busy you need to wait for the end of current transfer before starting a new one. For simplicity reasons, this example is just waiting till the end of the transfer, but application may perform other tasks while transfer operation is ongoing. */ while (HAL_I2C_GetState(&I2cHandle) != HAL_I2C_STATE_READY) { } /*##-6- Compare the sent and received buffers ##############################*/ if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,RXBUFFERSIZE)) { /* Processing Error */ Error_Handler(); } /* Infinite loop */ while (1) { }}
开发者ID:Lembed,项目名称:STM32CubeF1-mirrors,代码行数:101,
示例28: main//.........这里部分代码省略......... UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; UartHandle.Init.Mode = UART_MODE_TX_RX; UartHandle.Init.OverSampling = UART_OVERSAMPLING_16; if(HAL_UART_Init(&UartHandle) != HAL_OK) { Error_Handler(); } #ifdef TRANSMITTER_BOARD /* Configure USER Button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); /* Wait for USER Button press before starting the Communication */ while (BSP_PB_GetState(BUTTON_KEY) == RESET) { } /* The board sends the message and expects to receive it back */ /*##-2- Start the transmission process #####################################*/ /* While the UART in reception process, user can transmit data through "aTxBuffer" buffer */ if(HAL_UART_Transmit_DMA(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK) { Error_Handler(); } /*##-3- Wait for the end of the transfer ###################################*/ while (UartReady != SET) { } /* Reset transmission flag */ UartReady = RESET; /* Turn LED3 Off */ BSP_LED_Off(LED3); /*##-4- Put UART peripheral in reception process ###########################*/ if(HAL_UART_Receive_DMA(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK) { Error_Handler(); }#else /* The board receives the message and sends it back */ /*##-2- Put UART peripheral in reception process ###########################*/ if(HAL_UART_Receive_DMA(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK) { Error_Handler(); } /*##-3- Wait for the end of the transfer ###################################*/ while (UartReady != SET) { } /* Reset transmission flag */ UartReady = RESET; /* Turn LED3 Off */ BSP_LED_Off(LED3); /*##-4- Start the transmission process #####################################*/ /* While the UART in reception process, user can transmit data through "aTxBuffer" buffer */ if(HAL_UART_Transmit_DMA(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK) { Error_Handler(); } #endif /* TRANSMITTER_BOARD */ /*##-5- Wait for the end of the transfer ###################################*/ while (UartReady != SET) { } /* Reset transmission flag */ UartReady = RESET; /*##-6- Compare the sent and received buffers ##############################*/ if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,RXBUFFERSIZE)) { Error_Handler(); } /* Infinite loop */ while (1) { /* Toggle LED3 */ BSP_LED_Toggle(LED3); /* Wait for 40ms */ HAL_Delay(40); }}
开发者ID:z80,项目名称:stm32f429,代码行数:101,
示例29: main//.........这里部分代码省略......... while (HAL_SPI_GetState(&SpiHandle) != HAL_SPI_STATE_READY) {} /* Check if Master requiring data read or write */ if(addrcmd == ADDRCMD_MASTER_READ) { /* Synchronization between Master and Slave */ Slave_Synchro(); /* Send data to Master */ if(HAL_SPI_Transmit_IT(&SpiHandle, aTxSlaveBuffer, DATA_LENGTH) != HAL_OK) { Error_Handler(); } while (HAL_SPI_GetState(&SpiHandle) != HAL_SPI_STATE_READY) {} /* Synchronization between Master and Slave */ Slave_Synchro(); /* Receive acknowledgement from Master */ ackbyte = 0; if(HAL_SPI_Receive_IT(&SpiHandle, (uint8_t *)&ackbyte, sizeof(ackbyte)) != HAL_OK) { Error_Handler(); } while (HAL_SPI_GetState(&SpiHandle) != HAL_SPI_STATE_READY) {} /* Check acknowledgement */ if(ackbyte != SPI_ACK_BYTES) { Error_Handler(); } } else if(addrcmd == ADDRCMD_MASTER_WRITE) { /* Synchronization between Master and Slave */ Slave_Synchro(); /* Receive data from Master */ if(HAL_SPI_Receive_IT(&SpiHandle, aRxBuffer, DATA_LENGTH) != HAL_OK) { Error_Handler(); } while (HAL_SPI_GetState(&SpiHandle) != HAL_SPI_STATE_READY) {} /* Synchronization between Master and Slave */ Slave_Synchro(); /* Send acknowledgement to Master */ ackbyte = SPI_ACK_BYTES; if(HAL_SPI_Transmit_IT(&SpiHandle, (uint8_t *)&ackbyte, sizeof(ackbyte)) != HAL_OK) { Error_Handler(); } while (HAL_SPI_GetState(&SpiHandle) != HAL_SPI_STATE_READY) {} /* In case, Master has sent data, compare received buffer with one expected */ if(Buffercmp((uint8_t*)aTxMasterBuffer, (uint8_t*)aRxBuffer, DATA_LENGTH)) { /* Transfer error in transmission process */ Error_Handler(); } else { /* Toggle LED6 on: Reception is correct */ BSP_LED_Toggle(LED6); } } } else { /* Synchronization between Master and Slave */ Slave_Synchro(); /* Send acknowledgement to Master */ ackbyte = SPI_NACK_BYTES; if(HAL_SPI_Transmit_IT(&SpiHandle, (uint8_t *)&ackbyte, sizeof(ackbyte)) != HAL_OK) { Error_Handler(); } while (HAL_SPI_GetState(&SpiHandle) != HAL_SPI_STATE_READY) {} Error_Handler(); } /* Flush Rx buffer for next transmission */ Flush_Buffer(aRxBuffer, DATA_LENGTH); }}
开发者ID:PaxInstruments,项目名称:STM32CubeF4,代码行数:101,
注:本文中的Buffercmp函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ Build函数代码示例 C++ BufferNew函数代码示例 |