本文整理汇总了C++中USART_GetFlagStatus函数的典型用法代码示例。如果您正苦于以下问题:C++ USART_GetFlagStatus函数的具体用法?C++ USART_GetFlagStatus怎么用?C++ USART_GetFlagStatus使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了USART_GetFlagStatus函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _USART1_IRQHandler
void _USART1_IRQHandler(void)
{
if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
/* received data */
USART_GetInputString();
}
/* If overrun condition occurs, clear the ORE flag
and recover communication */
if (USART_GetFlagStatus(USART1, USART_FLAG_ORE) != RESET)
{
(void)USART_ReceiveData(USART1);
}
if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
{
/* Write one byte to the transmit data register */
USART_SendBufferData();
}
}
示例2: serialout
void serialout(USART_TypeDef* uart, unsigned int intr)
{
int fd;
char c;
int doread = 1;
mkfifo("/dev/tty0/out", 0);
fd = open("/dev/tty0/out", 0);
while (1) {
if (doread)
read(fd, &c, 1);
doread = 0;
if (USART_GetFlagStatus(uart, USART_FLAG_TXE) == SET) {
USART_SendData(uart, c);
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
doread = 1;
}
interrupt_wait(intr);
USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
}
}
示例3: EVAL_COM2_IRQHandler
void EVAL_COM2_IRQHandler(void)
{
extern int bypass_mode;
if (USART_GetITStatus(EVAL_COM2, USART_IT_RXNE) != RESET)
{
if(bypass_mode)
USART_To_USB_Send_Data();
else
usart_2_rx_buffer(USART_ReceiveData(EVAL_COM2));
}
/* If overrun condition occurs, clear the ORE flag and recover communication */
if (USART_GetFlagStatus(EVAL_COM2, USART_FLAG_ORE) != RESET)
{
(void)USART_ReceiveData(EVAL_COM2);
}
}
示例4: FileFirmwareUpdateLogHook
/************************************************************************************//**
** \brief Callback that gets called each time new log information becomes
** available during a firmware update.
** \param info_string Pointer to a character array with the log entry info.
** \return none.
**
****************************************************************************************/
void FileFirmwareUpdateLogHook(blt_char *info_string)
{
/* write the string to the log file */
if (logfile.canUse == BLT_TRUE)
{
if (f_puts(info_string, &logfile.handle) < 0)
{
logfile.canUse = BLT_FALSE;
f_close(&logfile.handle);
}
}
/* echo all characters in the string on UART */
while(*info_string != '\0')
{
/* write character to transmit holding register */
USART_SendData(USART6, *info_string);
/* wait for tx holding register to be empty */
while(USART_GetFlagStatus(USART6, USART_FLAG_TXE) == RESET);
/* point to the next character in the string */
info_string++;
}
} /*** end of FileFirmwareUpdateLogHook ***/
示例5: USART_ITConfig
size_t USARTSerial::write(uint8_t c)
{
// interrupts are off and data in queue;
if ((USART_GetITStatus(usartMap->usart_peripheral, USART_IT_TXE) == RESET)
&& _tx_buffer.head != _tx_buffer.tail) {
// Get him busy
USART_ITConfig(usartMap->usart_peripheral, USART_IT_TXE, ENABLE);
}
unsigned i = (_tx_buffer.head + 1) % SERIAL_BUFFER_SIZE;
// If the output buffer is full, there's nothing for it other than to
// wait for the interrupt handler to empty it a bit
// no space so or Called Off Panic with interrupt off get the message out!
// make space Enter Polled IO mode
while (i == _tx_buffer.tail || ((__get_PRIMASK() & 1) && _tx_buffer.head != _tx_buffer.tail) ) {
// Interrupts are on but they are not being serviced because this was called from a higher
// Priority interrupt
if (USART_GetITStatus(usartMap->usart_peripheral, USART_IT_TXE) && USART_GetFlagStatus(usartMap->usart_peripheral, USART_FLAG_TXE))
{
// protect for good measure
USART_ITConfig(usartMap->usart_peripheral, USART_IT_TXE, DISABLE);
// Write out a byte
USART_SendData(usartMap->usart_peripheral, _tx_buffer.buffer[_tx_buffer.tail++]);
_tx_buffer.tail %= SERIAL_BUFFER_SIZE;
// unprotect
USART_ITConfig(usartMap->usart_peripheral, USART_IT_TXE, ENABLE);
}
}
_tx_buffer.buffer[_tx_buffer.head] = c;
_tx_buffer.head = i;
transmitting = true;
USART_ITConfig(usartMap->usart_peripheral, USART_IT_TXE, ENABLE);
return 1;
}
示例6: Uart1_IRQHandler
/**
* @brief This function handles USART1 interrupt request.
* @param None
* @retval None
* @global
*/
void Uart1_IRQHandler(void)
{
unsigned char RxByte = 0x00;
if (USART_GetFlagStatus(USART1, USART_FLAG_ORE) != RESET){ // 溢出
// 注意!不能使用if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)来判断
// http://bbs.21ic.com/icview-160999-1-1.html
USART_ReceiveData(USART1);
}
// 接收中断 (接收寄存器非空)
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET){
// Clear the USART1 Receive interrupt
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
// unsigned char com_data = USART1->DR;
// Read one byte from the receive data register
RxByte = USART_ReceiveData(USART1);
if((cmdStart == FALSE) && (RxByte == BYTE_START)){
cmdStart = TRUE;
RxCounter = 0;
cmdLen = RX_BUFFER_SIZE;
}
else if(cmdStart == TRUE){
RxBuf[RxCounter++] = RxByte;
if(RxCounter == 2){
cmdLen = RxByte + 4; // cmd code + parameter number + Xor byte + end byte
}
else if(RxCounter == cmdLen){
RxComplete = TRUE;
}
else if(RxCounter >= 28){ // 目前最多不超过28(写块)个字节
RxCounter = 28;
}
}
}
}
示例7: poll_serial
void poll_serial()
{
uint8_t c;
if(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET)
{return;}
c=USART_ReceiveData(USART2);
if(state<3)
{
*dlc=0;
}
if(state<0)
{
if(c==0xFF)
{
state=0;
}
}
else if(state>=0 && state<*dlc+3)
{
can_frame[state]=c;
state++;
}
else if(state>=*dlc+3)
{
if(c==0xFF)
{
canout();
serial_putstr("OK\r",3);
state=0;
}
else
{
state=-1;
}
}
}
示例8: _Device_Uart_Send_Bytes
unsigned char _Device_Uart_Send_Bytes(unsigned char *sendByte, unsigned int length){
unsigned int i;
//if(Usart_Peripheral_Enable_Flag == DeviceOff){
if((Usart_Peripheral_Flag & fUart_Enable) == 0){
return Func_Fail;
}
#if (_Set_UART_AS_Half_Duplex_Transmission_ == 1)
_Device_Set_Uart_RX_Interrupt(DeviceOff);
#endif
//GPIO_WriteHigh(LED2_PORT, LED2_PIN);
//set TX status
// GPIO_WriteHigh(URAT_TX_Setting_PORT, URAT_TX_Setting_PIN);
// GPIO_WriteHigh(URAT_TX_Setting_PORT, URAT_TX_Setting_PIN); //for delay
for(i = 0; i < length; i++){
USART_SendData8(USART1, (*(sendByte + i)));
SendingWhileTimeOutCount = 0;
//while (USART_GetFlagStatus(USART1, UART2_FLAG_TXE) == RESET){ //Transmit Data Register Empty flag
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){ //Transmission Complete flag
if(SendingWhileTimeOutCount >= SendingTimeOutCycle){
break;
}
SendingWhileTimeOutCount++;
}//while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
}
//disable TX status
// GPIO_WriteLow(URAT_TX_Setting_PORT, URAT_TX_Setting_PIN);
// GPIO_WriteLow(URAT_TX_Setting_PORT, URAT_TX_Setting_PIN); //for delay
//GPIO_WriteLow(LED2_PORT, LED2_PIN);
#if (_Set_UART_AS_Half_Duplex_Transmission_ == 1)
_Device_Set_Uart_RX_Interrupt(DeviceOn);
#endif
return Func_Complete;
}
示例9: Com_USART2_Init
void Com_USART2_Init()
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitTypeStructure;
NVIC_InitTypeStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitTypeStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitTypeStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitTypeStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitTypeStructure);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
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;
USART_Init(USART2, &USART_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
//USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
USART_Cmd(USART2, ENABLE);
USART_SendData(USART2, 0); //dummpy send
while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
}
示例10: OW_Reset
//-----------------------------------------------------------------------------
// осуществляет сброс и проверку на наличие устройств на шине
//-----------------------------------------------------------------------------
uint8_t OW_Reset() {
uint8_t ow_presence;
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 9600;
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_Tx | USART_Mode_Rx;
USART_Init(OW_USART, &USART_InitStructure);
// отправляем 0xf0 на скорости 9600
USART_ClearFlag(OW_USART, USART_FLAG_TC);
USART_SendData(OW_USART, 0xf0);
while (USART_GetFlagStatus(OW_USART, USART_FLAG_TC) == RESET) {
#ifdef OW_GIVE_TICK_RTOS
taskYIELD();
IWDG_ReloadCounter();
#endif
}
ow_presence = USART_ReceiveData(OW_USART);
USART_InitStructure.USART_BaudRate = 115200;
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_Tx | USART_Mode_Rx;
USART_Init(OW_USART, &USART_InitStructure);
if (ow_presence != 0xf0) {
return OW_OK;
}
return OW_NO_DEVICE;
}
示例11: USART_SendBlock
uint32_t USART_SendBlock(USART_TypeDef *USARTPort, uint8_t txbuf, uint8_t buflen)
{
uint8_t bToSend, bSent, timeOut;
bToSend = buflen;
bSent = 0;
while (bToSend)
{
/* if(!(USARTPort->SR & USART_FLAG_TXE))
{
break;
}*/
while(USART_GetFlagStatus(USARTPort, USART_FLAG_TXE))
{
USART_SendData(USARTPort, txbuf++);
bToSend--;
bSent++;
}
}
return bSent;
}
示例12: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
uint16_t v;
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f4xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f4xx.c file
*/
USART_Configuration();
for(v=0;v<257;v++)
data_buf[v]=v;
/*data_buf[0]= 0x04;
data_buf[1]= 0x06;
data_buf[2]=0x02;
data_buf[3]=0x32;
data_buf[4]= 0x06;
data_buf[5]= 0x06;
data_buf[6]= 0x06;
data_buf[7]= 0x06;
*/
config_frame(0, 0, 0,3);//configurin frame preamble,head,tail and dlay
send_frame( data_buf,25); //adding info to frame
delay();
for(v=0;v<=tx_buffer.index;v++)
{
USART_SendData(USART2, tx_buffer.frame_buffer[v]);
while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
if((v%11==0)&&(v!=0))
delay();
}
}
示例13: Test_fgetc
int Test_fgetc(void)
{
uint8_t ch = 0;
while (1)
{
if(ESC(escape)==1)
break;
}
while(DBGU_RxBufferHead == DBGU_RxBufferTail);
ch = DBGU_RxBuffer[DBGU_RxBufferTail];
DBGU_RxBufferTail = (DBGU_RxBufferTail + 1) % DBGU_RX_BUFFER_SIZE;
if (DBGU_RxBufferHead == DBGU_RxBufferTail)
{
DBGU_InputReady = 0;
escape = 0;
}
while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
return ch;
}int ESC(int escape)
示例14: Usart_Configuration
void Usart_Configuration(void) //配置Usart1 Tx->PA9 Rx->PA10
{
GPIO_InitTypeDef GPIO_InitStructure; //GPIO库函数结构体
USART_InitTypeDef USART_InitStructure;//USART库函数结构体
USART_ClockInitTypeDef USART_ClockInitStructure;
//使能串口1,GPIOA,AFIO总线
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO|RCC_APB2Periph_USART1,ENABLE);
/* Configure USART1 Tx (PA9) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//PA9时钟速度50MHz
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用输出
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 Rx (PA10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate =115200; //波特率9600
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //8位数据
USART_InitStructure.USART_StopBits = USART_StopBits_1; //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; //发送、接收使能
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;//空闲时钟为低电平
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;//时钟第二个边沿进行数据捕获
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;//最后一位数据的时钟脉冲不从SCLK输出
//使能串口1接收中断
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ClockInit(USART1, &USART_ClockInitStructure);
USART_Init(USART1, &USART_InitStructure); //初始化结构体
USART_Cmd(USART1, ENABLE); //使能串口1
// USART_ClearFlag(USART1,USART_FLAG_TC);//清除发送完成标志,不然有时可能会有第一个字符发送不出去的情况
USART_GetFlagStatus(USART1, USART_FLAG_TC);//清除发送完成标志,不然有时可能会有第一个字符发送不出去的情况
}
示例15: DMA_Cmd
///////////////////
///串口发送数据
///@param pbuffer 需要发送数据的首地址
///@param size 需要发送的数据的长度
///@retval 发送是否成功 -false:发送失败(队列溢出) -true:发送成功(即将发送)
///////////////////
bool USART::SendData(uint8_t *pbuffer, uint32_t size)
{
//将需要发送的数据放入缓冲区队列
bufferTx.Puts(pbuffer,size);
if(mUseDma && !isBusySend)//使用DMA并且没有忙于发送,则开启发送
{
//断发送队列里是否还存在数据,如果存在,继续发送,否则关闭DMA
if(bufferTx.Size()>0)
{
isBusySend=true; //标记忙于发送
if(bufferTx.Size()<=USART_DMA_TX_BUFFER_SIZE) //队列中的数据长度小于dma缓冲区的最大长度
{
dmaChannelTx->CNDTR = (uint32_t)bufferTx.Size();
bufferTx.Gets(bufferTxDma,bufferTx.Size());//将剩下的数据放到dma缓冲区
}
else
{
dmaChannelTx->CNDTR = USART_DMA_TX_BUFFER_SIZE;
bufferTx.Gets(bufferTxDma,USART_DMA_TX_BUFFER_SIZE);//将数据放到dma缓冲区
}
DMA_Cmd (dmaChannelTx,ENABLE); //使能DMA,开始发送
}
}
if(!mUseDma && !isBusySend)//使用中断发送
{
if(bufferTx.Size()>0)//数据区确实存在数据
{
USART_ClearITPendingBit(usart, USART_IT_TC); //清标记,防止第一个数据发送不出去的情况,一定是要先清再打开
USART_ITConfig(usart, USART_IT_TC, ENABLE);//开启发送中断,然后发送数据
USART_GetFlagStatus(usart, USART_FLAG_TC);//读取sr,清除发送完成标志,不然有时可能会有第一个字符发送不出去的情况
isBusySend=true;
static u8 dataToSend=0;
bufferTx.Get(dataToSend);
USART_SendData(usart,dataToSend);
}
}
return 1;
}