【Nucleo心得】+让您学习STM32 Nucleo 更精彩!
STM32 Nucleo板载ST-LINK调试器,同时该调试器扩展扩展虚拟串口,下面通过硬件,软件学习下如何把它利用起来!
1、硬件
找到板子背面SB62,SB63,短路这 2处。
左下角,
焊好后,右上角
硬件说明:USART2-PA2=ST-LINK-RX,USART2-PA3
=ST-LINK-TX
2、软件
打开例程工程:
UART_TwoBoards_ComPolling
stm32cubel0\STM32Cube_FW_L0_V1.1.0\Projects\STM32L053R8-Nucleo\Examples\UART\UART_TwoBoards_ComPolling\MDK-ARM
修改main.h
#define USARTx USART2
#define USARTx_CLK_ENABLE() __USART2_CLK_ENABLE();
#define USARTx_RX_GPIO_CLK_ENABLE() __GPIOA_CLK_ENABLE()
#define USARTx_TX_GPIO_CLK_ENABLE() __GPIOA_CLK_ENABLE()
#define USARTx_FORCE_RESET() __USART2_FORCE_RESET()
#define USARTx_RELEASE_RESET() __USART2_RELEASE_RESET()
/* Definition for USARTx Pins */
#define USARTx_TX_PIN GPIO_PIN_2
#define USARTx_TX_GPIO_PORT GPIOA
#define USARTx_TX_AF GPIO_AF4_USART1
#define USARTx_RX_PIN GPIO_PIN_3
#define USARTx_RX_GPIO_PORT GPIOA
#define USARTx_RX_AF GPIO_AF4_USART1
我想的功能是按下B1按纽就发送一次的功能
直接while(1)一下好了
#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);
while(1)
{
/* 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(&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();
//}
/* Turn LED2 on: Transfer in reception process is correct */
BSP_LED_On(LED2);
}