/*上传STM32串口接收发送子程序,调试验证OK,供参考*/
#include
static UART_HandleTypeDef* pstm32uart_entry = NULL;
int STM32_SendBuffer(const char* pcmd);
const char* STM32_GetBuffer(void);
#define UART__TIMEOUT 500
void WaitSTM32UartReady()
{
HAL_UART_StateTypeDef status;
do
{
status = HAL_UART_GetState(pstm32uart_entry);
}while(status != HAL_UART_STATE_READY);
}
int uart_putc(int c)
{
while (!__HAL_UART_GET_FLAG(pstm32uart_entry, UART_FLAG_TXE));
pstm32uart_entry->Instance->TDR = (c & 0xff); // for f030c8
return 0;
}
int uart_getc(void)
{
while (!__HAL_UART_GET_FLAG(pstm32uart_entry, UART_FLAG_RXNE));
return pstm32uart_entry->Instance->RDR & 0xff;
}
int STM32_SendBuffer(const char* pcmd)
{
while(*pcmd != '\n')
uart_putc(*pcmd++);
return SUCCESS;
}
static char STM32_Buf[32];
const char* STM32_GetBuffer()
{
int i = 0;
if(pstm32uart_entry == NULL)return NULL;
while(1)
{
char szchar = uart_getc();
if(szchar == '\n')
break;
else STM32_Buf[i++] = szchar;
};
if(i == 1)STM32_Buf[0] = 0x00;
else STM32_Buf[i+1] = 0x00;
// DBGSTR("STM32_GetBuffer : %s",&STM32_Buf[0]);
return &STM32_Buf[0];
}
Previous article:STM32 serial port receives dust sensor data
Next article:stm32F103 state machine matrix keyboard
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- CircuitPython controlled snowy Christmas tree
- When replying, just press CTRL+Enter to post directly. Details determine success or failure. You must be like Master Qiao.
- This circuit can adjust the voltage under no-load condition, but the voltage is only about 2V after the load is installed.
- Tmall Murata official flagship store, spend 1000-200, get a gift! What do you want to buy this Double 11?
- Understanding of op amp parameters
- How to adjust the minimum spacing
- Celebrate National Day, play with Guoxin! Jiefa invites you to try out the AC7801x motor demo board for free
- 7 must-know PCB design tips for engineers
- A problem with TL431 peripheral capacitors
- Briefly talk about car fuses