本文整理汇总了C++中USART_ReceiveData函数的典型用法代码示例。如果您正苦于以下问题:C++ USART_ReceiveData函数的具体用法?C++ USART_ReceiveData怎么用?C++ USART_ReceiveData使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了USART_ReceiveData函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: usart3_irq_handler
void usart3_irq_handler(void)
{
/* input (RX) handler */
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET){
data_buf = USART_ReceiveData(USART3);
if(!gpc_handle_byte(data_buf)){
LED_GREEN_TOGGLE();
}else{
LED_RED_ON();
}
}
/* output (TX) handler */
if(USART_GetITStatus(USART3, USART_IT_TXE) != RESET){
if((data_buf = gpc_pickup_byte()) >= 0){
USART_SendData(USART3, data_buf);
LED_GREEN_TOGGLE();
}else{
usart_disable_send();
}
}
}
示例2: main
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
USART1_Configuration();
LED_Initialization();
USART1_puts("Hello World!\r\n");
USART1_puts("Just for STM32F429I Discovery verify USART1 with USB TTL Cable\r\n");
while(1)
{
LED3_Toggle();
if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) != RESET)
{
char t = USART_ReceiveData(USART1);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, t);
}
}
while(1); // Don't want to exit
}
示例3: usart_irq_handler
static inline void usart_irq_handler(struct uart_periph* p) {
if(USART_GetITStatus(p->reg_addr, USART_IT_TXE) != RESET){
// check if more data to send
if (p->tx_insert_idx != p->tx_extract_idx) {
USART_SendData(p->reg_addr,p->tx_buf[p->tx_extract_idx]);
p->tx_extract_idx++;
p->tx_extract_idx %= UART_TX_BUFFER_SIZE;
}
else {
p->tx_running = FALSE; // clear running flag
USART_ITConfig(p->reg_addr, USART_IT_TXE, DISABLE);
}
}
if(USART_GetITStatus(p->reg_addr, USART_IT_RXNE) != RESET){
uint16_t temp = (p->rx_insert_idx + 1) % UART_RX_BUFFER_SIZE;;
p->rx_buf[p->rx_insert_idx] = USART_ReceiveData(p->reg_addr);
// check for more room in queue
if (temp != p->rx_extract_idx)
p->rx_insert_idx = temp; // update insert index
}
}
示例4: USART1_IRQHandler
void USART1_IRQHandler(void)
{
if(SET == USART_GetITStatus(USART1, USART_IT_TXE))
{
USART_ClearITPendingBit(USART1, USART_IT_TXE);
if (m_SendBuff.len > 0 )
{
USART_SendData(USART1, m_SendBuff.buf[m_SendBuff.ind++]);
m_SendBuff.len--;
}
else
{
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
USART_ITConfig(USART1, USART_IT_TC, ENABLE);
}
}
else if (USART_GetITStatus(USART1, USART_IT_TC) != RESET)
{
USART_ClearITPendingBit(USART1, USART_IT_TC);
USART_ITConfig(USART1, USART_IT_TC, DISABLE);
m_SendBuff.len = 0;
eTXIdle = TRUE;
}
else if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
u8 ch;
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
ch = USART_ReceiveData(USART1);
ReceOneChar(ch); //IAP
// if (receChar != NULL)
// (*receChar)(ch);
}
}
示例5: USART1_IRQHandler
//------------------------------------------------------
void USART1_IRQHandler(void)
{
uint8_t i;
if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
{
USART_SendData(USART1, UartBuf_RD(&UartTxbuf)); //环形数据缓存发送
if(UartBuf_Cnt(&UartTxbuf)==0)
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);//假如缓冲空了,就关闭串口发送中断
}
else if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit(USART1, USART_IT_RXNE);//清除接收中断标志
//此种环形缓冲数组串口接收方式,适用于解包各种数据,很方便。对数据的要求是:
//发送方必须要求有数据包头,以便解决串口数据无地址的问题
Udatatmp = (uint8_t) USART_ReceiveData(USART1); //临时数据赋值
UartBuf_WD(&UartRxbuf,Udatatmp); //写串口接收缓冲数组
// if(UartBuf_Cnt(&UartRxbuf)==0) USART_SendData(USART1, '');//串口接收数组长度等于0时,发送接收数组空标志
// if(UartBuf_Cnt(&UartRxbuf)==UartRxbuf.Mask) USART_SendData(USART1, '');//串口接收数组长度等于掩码时,发送接收缓冲满标志
//#if(BT_SRC==APP)
#ifdef BT_SRC_APP
CommApp(Udatatmp);//UartBuf_RD(&UartRxbuf));
#endif
#ifdef BT_SRC_PC
CommPC(Udatatmp);
#endif
}
}
示例6: UART5_IRQHandler
void UART5_IRQHandler( void )
{
uint8_t ch;
rt_interrupt_enter( );
if( USART_GetITStatus( UART5, USART_IT_RXNE ) != RESET )
{
ch = USART_ReceiveData( UART5 );
if( ( ch == 0x0a ) && ( last_ch == 0x0d ) ) /*遇到0d 0a 表明结束*/
{
uart5_rxbuf.body[uart5_rxbuf.wr++] = ch;
if( uart5_rxbuf.wr < 124 )
{
rt_mq_send( &mq_gps, (void*)&uart5_rxbuf, uart5_rxbuf.wr + 2 );
}
uart5_rxbuf.wr = 0;
}else
{
// 1. get head char
if(ch=='$')
uart5_rxbuf.wr = 0;
// 2. judge head char
if(uart5_rxbuf.body[0]!='$') // add later
uart5_rxbuf.wr = 0;
// 3. rx data
uart5_rxbuf.body[uart5_rxbuf.wr++] = ch;
if( uart5_rxbuf.wr == UART5_RX_SIZE )
{
uart5_rxbuf.wr = 0;
}
uart5_rxbuf.body[uart5_rxbuf.wr] = 0;
}
last_ch = ch;
USART_ClearITPendingBit( UART5, USART_IT_RXNE );
}
rt_interrupt_leave( );
}
示例7: vUARTInterruptHandler
void vUARTInterruptHandler( void )
{
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
char cChar;
if( USART_GetITStatus( USART1, USART_IT_TXE ) == SET ) {
/* The interrupt was caused by the THR becoming empty. Are there any
more characters to transmit? */
if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE ) {
/* A character was retrieved from the queue so can be sent to the
THR now. */
USART_SendData( USART1, cChar );
} else {
USART_ITConfig( USART1, USART_IT_TXE, DISABLE );
}
}
if( USART_GetITStatus( USART1, USART_IT_RXNE ) == SET ) {
cChar = USART_ReceiveData( USART1 );
xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
}
portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
}
示例8: UsartReceive
/**
* @brief UsartReceive 串口接收中断服务函数,用来控制音量
* @param 无
* @retval 无
*/
void UsartReceive(void)
{
//char text[40];
vu16 i=0;
if(USART_GetFlagStatus(USART1,USART_IT_RXNE)==SET)
{
USART_ClearFlag(USART1, USART_FLAG_RXNE | USART_FLAG_ORE);
//读数据并清 RXNE、ORE位
i = USART_ReceiveData(USART1);
printf("%c",i);
if(i == '+')
{
Volume_Add();
//printf("+");
}else if(i == '-')
{
Volume_Dec();
//printf("-");
}
}
}
示例9: USART1_IRQHandler
void USART1_IRQHandler(void)
{
static u16 receiveCounter = 0;
static u8 temp,flagStart = 0;
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
temp = USART_ReceiveData(USART1);
if(flagStart == 1)
{
receiveBuffer[receiveCounter] = temp;
receiveCounter ++;
if(receiveCounter == receiveBuffer[3])
{
flagStart = 0;
receiveCounter = 0;
uartDecode();
}
/* 最长的报文长度为12 */
else if (receiveCounter > 12)
{
receiveCounter = 0;
flagStart = 0;
}
}
else if(temp == 0x7f)
{
flagStart = 1;
receiveBuffer[receiveCounter] = temp;
receiveCounter ++;
}
}
}
示例10: USART2_IRQHandler
void USART2_IRQHandler(void)
{
uint16_t SR = USART2->SR;
//if (USART_GetITStatus(USART2, USART_IT_RXNE) == SET) {
if (SR & USART_IT_RXNE) {
if (uart2Callback)
uart2Callback(USART_ReceiveData(USART2));
}
//while(USART_GetITStatus(USART2, USART_IT_TXE) == RESET);
//if (USART_GetITStatus(USART2, USART_IT_TXE) == SET) {
if (SR & USART_FLAG_TXE) {
if (tx2BufferTail != tx2BufferHead) {
USART2->DR = tx2Buffer[tx2BufferTail];
tx2BufferTail = (tx2BufferTail + 1) % UART2_BUFFER_SIZE;
} else {
USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
}
}
/*if (USART_GetITStatus(USART2, USART_IT_TC) != RESET)
{
// ќчищаем флаг прерывани¤
USART_ClearITPendingBit(USART2, USART_IT_TC);
// ќтправл¤ем байт данных
USART_SendData(USART2, tx2Buffer[tx2BufferTail]);
// ”величиваем счетчик отправленных байт
tx2BufferTail = (tx2BufferTail + 1) % UART2_BUFFER_SIZE;
}*/
}
示例11: USART2_IRQHandler
void USART2_IRQHandler(void)
{
unsigned char RxData;
// uint32_t idx = 1;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
/* Read one byte from the receive data register */
RxData = USART_ReceiveData(USART2);
usart_irq_my(1, RxData);
}
/*
// 处理接收到的数据
while (USART_GetFlagStatus(USART2, USART_IT_RXNE) != RESET)
{
//STM_EVAL_LEDToggle(LED4);
RxData = USART_ReceiveData(USART2);
usart_irq_my(1, RxData);
}
*/
}
示例12: usart3_irq_handler
void usart3_irq_handler(void) {
if(USART_GetITStatus(USART3, USART_IT_TXE) != RESET){
// check if more data to send
if (uart3_tx_insert_idx != uart3_tx_extract_idx) {
USART_SendData(USART3,uart3_tx_buffer[uart3_tx_extract_idx]);
uart3_tx_extract_idx++;
uart3_tx_extract_idx %= UART3_TX_BUFFER_SIZE;
}
else {
uart3_tx_running = FALSE; // clear running flag
USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
}
}
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET){
uint16_t temp = (uart3_rx_insert_idx + 1) % UART3_RX_BUFFER_SIZE;;
uart3_rx_buffer[uart3_rx_insert_idx] = USART_ReceiveData(USART3);
// check for more room in queue
if (temp != uart3_rx_extract_idx)
uart3_rx_insert_idx = temp; // update insert index
}
}
示例13: USART1_IRQHandler
void USART1_IRQHandler(void) //ÖжÏÒì²½½ÓÊÕÉÏλ»ú·¢ËÍÊý¾Ý
{
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //δ¸´Î»
{
USART_ClearITPendingBit(USART1,USART_IT_RXNE); //ÇåÖжÏ
Uart1_Rbuf[Uart1_count]=USART_ReceiveData(USART1);
Uart1_count++;
if(Uart1_count>2)
{
Uart1_flag=1; //ÓÐЧÊý¾Ý¿ªÊ¼
}
if(Uart1_count>(UART1_Buf_Num-1))
{
Uart1_count=0;
}
}
}
示例14: UsartGet
// 从串口接受数据
uint8_t UsartGet(void)
{
while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
return (uint8_t)USART_ReceiveData(USART2);
}
示例15: enable_usart1
//.........这里部分代码省略.........
.DMA_FIFOThreshold = DMA_FIFOThreshold_Full,
.DMA_MemoryBurst = DMA_MemoryBurst_Single,
.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
.DMA_MemoryInc = DMA_MemoryInc_Enable,
.DMA_Mode = DMA_Mode_Normal,
.DMA_PeripheralBaseAddr = (uint32_t)(&(USART2->DR)),
.DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
.DMA_PeripheralInc = DMA_PeripheralInc_Disable,
.DMA_Priority = DMA_Priority_Medium,
/* Configure TX DMA */
.DMA_Channel = DMA_Channel_4,
.DMA_DIR = DMA_DIR_MemoryToPeripheral,
.DMA_Memory0BaseAddr = (uint32_t)s
};
DMA_Init(DMA1_Stream6, &DMA_InitStructure);
DMA_Cmd(DMA1_Stream6, ENABLE);
USART_DMACmd(USART2, USART_DMAReq_Tx, ENABLE);
}
int _write(int fd, char *ptr, int len)
{
/* Write "len" of char from "ptr" to file id "fd"
* Return number of char written.
* Need implementing with UART here. */
int i = 0;
fd=fd;
for (i = 0; i < len ; i++) {
USART_SendData(PRINTF_USART, (uint8_t) *ptr);
/* Loop until USART2 DR register is empty */
while (USART_GetFlagStatus(PRINTF_USART, USART_FLAG_TXE) == RESET);
ptr++;
}
return len;
}
xSemaphoreHandle serial_tx_wait_sem = NULL;
xQueueHandle serial_rx_queue = NULL;
xQueueHandle gps_serial_queue = NULL;
void USART3_IRQHandler(void)
{
long lHigherPriorityTaskWoken = pdFALSE;
serial_msg rx_msg;
if (USART_GetITStatus(USART3, USART_IT_TXE) != RESET) {
xSemaphoreGiveFromISR(serial_tx_wait_sem, &lHigherPriorityTaskWoken);
USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
}
if (USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) {
rx_msg.ch = USART_ReceiveData(USART3);
if (!xQueueSendToBackFromISR(serial_rx_queue, &rx_msg, &lHigherPriorityTaskWoken))
portEND_SWITCHING_ISR(lHigherPriorityTaskWoken);
}
portEND_SWITCHING_ISR(lHigherPriorityTaskWoken);
}
char usart3_read(void)
{
serial_msg msg;
while (!xQueueReceive(serial_rx_queue, &msg, portMAX_DELAY));
return msg.ch;
}
void usart3_send(char str)
{
while (!xSemaphoreTake(serial_tx_wait_sem, portMAX_DELAY));
USART_SendData(USART3, (uint16_t)str);
USART_ITConfig(USART3, USART_IT_TXE, ENABLE);
}
void uart8_puts(uint8_t *ptr)
{
while(*ptr!='\0'){
USART_SendData(PRINTF_USART, (uint8_t) *ptr);
/* Loop until USART8 DR register is empty */
while (USART_GetFlagStatus(PRINTF_USART, USART_FLAG_TXE) == RESET);
ptr++;
}
}