Ejemplo n.º 1
0
int platform_s_uart_recv( unsigned id, s32 timeout )
{
  if( timeout == 0 )
  {
    // Return data only if already available
    if( UART_GetFlagStatus( STR9_UART, UART_FLAG_RxFIFOEmpty ) != SET )
      return UART_ReceiveData( STR9_UART );
    else
      return -1;
  }
  while( UART_GetFlagStatus( STR9_UART, UART_FLAG_RxFIFOEmpty ) == SET );
  return UART_ReceiveData( STR9_UART );
}
Ejemplo n.º 2
0
int platform_s_uart_recv( unsigned id, s32 timeout )
{
  UART_TypeDef* p_uart = ( UART_TypeDef* )uarts[ id ];

  if( timeout == 0 )
  {
    // Return data only if already available
    if( UART_GetFlagStatus( p_uart, UART_FLAG_RxFIFOEmpty ) != SET )
      return UART_ReceiveData( p_uart );
    else
      return -1;
  }
  while( UART_GetFlagStatus( p_uart, UART_FLAG_RxFIFOEmpty ) == SET );
  return UART_ReceiveData( p_uart ); 
}
Ejemplo n.º 3
0
/*----------------------------------------------------------------------------*/
static INT32 HVC_ReceiveHeader(INT32 inTimeOutTime, INT32 *outDataSize, UINT8 *outStatus)
{
    INT32 nRet = 0;
    UINT8 headerData[32];

    /* Get header part */
    nRet = UART_ReceiveData(inTimeOutTime, RECEIVE_HEAD_NUM, headerData);
    if(nRet != RECEIVE_HEAD_NUM){
        return HVC_ERROR_HEADER_TIMEOUT;
    }
    else if((UINT8)0xFE != headerData[RECEIVE_HEAD_SYNCBYTE]){
        /* Different value indicates an invalid result */
        return HVC_ERROR_HEADER_INVALID;
    }

    /* Get data length */
    *outDataSize = headerData[RECEIVE_HEAD_DATALENLL] +
                    (headerData[RECEIVE_HEAD_DATALENLM]<<8) +
                    (headerData[RECEIVE_HEAD_DATALENML]<<16) +
                    (headerData[RECEIVE_HEAD_DATALENMM]<<24);

    /* Get command execution result */
    *outStatus  = headerData[RECEIVE_HEAD_STATUS];
    return 0;
}
Ejemplo n.º 4
0
int main(void)
{
    uint8_t ch;
    //定义串口初始化结构
    UART_InitTypeDef UART_InitStruct1;
    //初始化系统时钟 使用外部50M晶振 PLL倍频到100M
    SystemClockSetup(ClockSource_EX50M,CoreClock_100M);
    DelayInit();
    //初始化LED
    LED_Init(LED_PinLookup_CHKATOM, kNumOfLED);
    //KBI 初始化
    KBI_Init(KBI_PinLookup_CHKATOM, kNumOfKEY);
	
    UART_InitStruct1.UARTxMAP = UART4_RX_C14_TX_C15; //UART4模块 映射引脚:PTC14 PTC15
    UART_InitStruct1.UART_BaudRate = 115200;         //波特率 115200
    UART_Init(&UART_InitStruct1);                    //初始化串口

    while(1)
    {
        //接收成功
        if(UART_ReceiveData(UART4, &ch) == TRUE)
        {
        //echo
        UART_SendData(UART4, ch);
        }
    }
}
Ejemplo n.º 5
0
void UART1_IRQHandler(void)
{
	static uint8_t cnt_rx_byte=0;
	static bool start=false;
	uint8_t tmp=0; 
	
	
	if(UART_GetITStatus(MDR_UART1,UART_IT_RX) == SET)
	{
		UART_ClearITPendingBit(MDR_UART1,UART_IT_RX);
		tmp=UART_ReceiveData(MDR_UART1);
		
		if((tmp==0xAA) && (!start))
		{
			start=true;
		}
		else
		{
			if(start)
			{
				if(!RX_ok)
					ArrayRX_PKBA[cnt_rx_byte]=tmp; 
					
				++cnt_rx_byte;
				if(cnt_rx_byte==RX_FRAME_SIZE)
				{	
					RX_ok=true;
					start=false;
					cnt_rx_byte=0;
				}
			}
		}
	}
	MDR_UART1->RSR_ECR = 0;	
}
Ejemplo n.º 6
0
//#define RX_FRAME_SIZE	3
void UART1_IRQHandler(void)
{
	uint8_t tmp = 0;
	static bool start = false;
	static uint8_t cnt_rx_byte = 0;
	static portBASE_TYPE xTaskWoken;
	
	tmp = UART_ReceiveData(MDR_UART1);
	
	if((tmp == 0xAA) && (!start))
	{
		start = true;
	}
	else
	{
		if(start)
		{
//			if(!RX_Ok)
			RX_MHU[cnt_rx_byte] = tmp; 
//			
			++cnt_rx_byte;
			if(cnt_rx_byte == ARR_RX_MHU)
			{
				xSemaphoreGiveFromISR(xUSART_RX_Semaphore, &xTaskWoken);
				start = false;
				cnt_rx_byte = 0;
			}
		}
	}
}
Ejemplo n.º 7
0
/*******************************************************************************
* Function Name  : UART_To_USB_Send_Data. 
* Description    : send the received data from UART 0 to USB. 
* Input          : None.
* Return         : none.
*******************************************************************************/
void UART_To_USB_Send_Data(void)
{
  buffer_in[count_in] = UART_ReceiveData(UART0);
  count_in++;
  UserToPMABufferCopy(buffer_in,ENDP1_TXADDR, count_in);
  SetEPTxCount(ENDP1,count_in);
  SetEPTxValid(ENDP1);
}
Ejemplo n.º 8
0
// -----------------------------------------------------------------------------
static void ReceiveUBloxData(void)
{
  while (!UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty))
  {
    rx_buffer_head_ = (rx_buffer_head_ + 1) % UBLOX_RX_BUFFER_LENGTH;
    rx_buffer_[rx_buffer_head_] = UART_ReceiveData(UART0);
  }
}
Ejemplo n.º 9
0
Archivo: isr.c Proyecto: oldjohnh/car
void UART4_RX_TX_IRQHandler(void)
{
	uint8_t ch;
	if(UART_ReceiveData(UART4,&ch))
	{
		UART_SendData(UART4,ch+1);
	}
}
Ejemplo n.º 10
0
void UART0_IRQHandler(void)
{
	u8 c;
	// if receive irq (FIFO is over trigger level) or receive timeout irq (FIFO is not empty for longer times) has occured
 	if((UART_GetITStatus(UART0, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART0, UART_IT_ReceiveTimeOut) != RESET) )
 	{
   		UART_ClearITPendingBit(UART0, UART_IT_Receive);			// clear receive interrupt flag
   		UART_ClearITPendingBit(UART0, UART_IT_ReceiveTimeOut);	// clear receive timeout interrupt flag

		// if debug UART is UART0
		if (DebugUART == UART0)
		{	// forward received data to the UART1 tx buffer
		 	while(UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET)
			{
				// wait for space in the tx buffer of the UART1
				while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {};
				// move the byte from the rx buffer of UART0 to the tx buffer of UART1
				UART_SendData(UART1, UART_ReceiveData(UART0));
			}
		}
		else // UART0 is not the DebugUART (normal operation)
		{
			// repeat until no byte is in the RxFIFO
	  		while (UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET)
	  		{  
				c = UART_ReceiveData(UART0); // get byte from rx fifo
				switch(UART0_Muxer)
				{
					case UART0_MKGPS:
						UBX_RxParser(c); // if connected to GPS forward byte to ubx parser
						MKProtocol_CollectSerialFrame(&UART0_rx_buffer, c);	// ckeck for MK-Frames also
						break;
					case UART0_MK3MAG:
						// ignore any byte send from MK3MAG
						break;
					case UART0_UNDEF:
					default:
						// ignore the byte from unknown source
						break;
				} // eof switch(UART0_Muxer)
			} // eof while
		}  // eof UART0 is not the DebugUART
	} // eof receive irq or receive timeout irq
}
Ejemplo n.º 11
0
/**
* @brief This function handles USART1 global interrupt.
*/
void USART1_IRQHandler(void)
{
  uint8_t tmp1,tmp2;
  tmp1 = __HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE);
  tmp2 = __HAL_UART_GET_IT_SOURCE(&huart1, UART_IT_RXNE);
  if((tmp1 != RESET) && (tmp2 != RESET))
  {
    RxBuffer[RxBufferHead] = UART_ReceiveData(&huart1);
    RxBufferHead = (RxBufferHead + 1) % RX_BUFFER_SIZE;
  }
}
Ejemplo n.º 12
0
//==================================================================================
void UART1_send_byte(uint8_t byte)
{
	UART_SendData(MDR_UART1,byte);
	//time_out_byte=0;
	//while(!UART_GetFlagStatus (MDR_UART1,UART_FLAG_RXFF))
	//while(UART_GetFlagStatus (MDR_UART1,UART_FLAG_BUSY) || !UART_GetFlagStatus (MDR_UART1,UART_FLAG_RXFF))
	while(UART_GetFlagStatus (MDR_UART1,UART_FLAG_BUSY))
	{
	}
	UART_ReceiveData (MDR_UART1);
	UART_ClearITPendingBit(MDR_UART1,UART_IT_RX);
}
Ejemplo n.º 13
0
void UART1_IRQHandler(void)
{
	uint8_t ch;
	if(UART_ReceiveData(UART1,&ch) == TRUE)
	{
		UART_SendData(UART1,ch);
		
	}
	
	
	
}
Ejemplo n.º 14
0
void UART4_RX_TX_IRQHandler(void)
{
    uint8_t ch;
    //中断发送处理过程
    UART_SendDataIntProcess(UART4);
    //如果成功接收到了数据
    if(UART_ReceiveData(UART4, &ch))
    {
        //把接收到的信息发送回去 echo
        UART_SendData(UART4,ch);
    }
}
Ejemplo n.º 15
0
uint8_t UART1_receiv_data(void)
{
	uint8_t rec_data=0;
	/* Check RXFF flag */
    while (UART_GetFlagStatus (MDR_UART1, UART_FLAG_RXFF)!= SET)
    {
		__nop();
    }
	rec_data = UART_ReceiveData (MDR_UART1);
	
	return rec_data;
}
Ejemplo n.º 16
0
/*********************************************************************//**
 * @brief		Receive a block of data via UART peripheral
 * @param[in]	UARTx	Selected UART peripheral used to send data,
 * 				should be UART0, UART1, UART2 or UART3.
 * @param[out]	rxbuf 	Pointer to Received buffer
 * @param[in]	buflen 	Length of Received buffer
 * @param[in] 	flag 	Flag mode, should be NONE_BLOCKING or BLOCKING

 * @return 		Number of bytes received
 *
 * Note: when using UART in BLOCKING mode, a time-out condition is used
 * via defined symbol UART_BLOCKING_TIMEOUT.
 **********************************************************************/
uint32_t UART_Receive(UART_TypeDef *UARTx, uint8_t *rxbuf, \
		uint32_t buflen, TRANSFER_BLOCK_Type flag)
{
	uint32_t bToRecv, bRecv, timeOut;
	uint8_t *pChar = rxbuf;

	bToRecv = buflen;

	// Blocking mode
	if (flag == BLOCKING) {
		bRecv = 0;
		while (bToRecv){
			timeOut = UART_BLOCKING_TIMEOUT;
			while (!(UARTx->LSR & UART_LSR_RDR)){
				if (timeOut == 0) break;
				timeOut--;
			}
			// Time out!
			if(timeOut == 0) break;
			// Get data from the buffer
			(*pChar++) = UART_ReceiveData(UARTx);
			bToRecv--;
			bRecv++;
		}
	}
	// None blocking mode
	else {
		bRecv = 0;
		while (bToRecv) {
			if (!(UARTx->LSR & UART_LSR_RDR)) {
				break;
			} else {
				(*pChar++) = UART_ReceiveData(UARTx);
				bRecv++;
				bToRecv--;
			}
		}
	}
	return bRecv;
}
Ejemplo n.º 17
0
/*----------------------------------------------------------------------------*/
static INT32 HVC_ReceiveData(INT32 inTimeOutTime, INT32 inDataSize, UINT8 *outResult)
{
    INT32 nRet = 0;

    if ( inDataSize <= 0 ) return 0;

    /* Receive data */
    nRet = UART_ReceiveData(inTimeOutTime, inDataSize, outResult);
    if(nRet != inDataSize){
        return HVC_ERROR_DATA_TIMEOUT;
    }
    return 0;
}
Ejemplo n.º 18
0
int platform_uart_recv( unsigned id, unsigned timer_id, int timeout )
{
  timer_data_type tmr_start, tmr_crt;
  int res;
    
  if( timeout == 0 )
  {
    // Return data only if already available
    if( UART_GetFlagStatus(STR9_UART, UART_FLAG_RxFIFOEmpty) != SET )
      return UART_ReceiveData( STR9_UART );
    else
      return -1;
  }
  else if( timeout == PLATFORM_UART_INFINITE_TIMEOUT )
  {
    // Wait for data
    while( UART_GetFlagStatus(STR9_UART, UART_FLAG_RxFIFOEmpty) == SET );
    return UART_ReceiveData( STR9_UART );
  }
  else
  {
    // Receive char with the specified timeout
    tmr_start = platform_timer_op( timer_id, PLATFORM_TIMER_OP_START,0 );
    while( 1 )
    {
      if( UART_GetFlagStatus(STR9_UART, UART_FLAG_RxFIFOEmpty) != SET  )
      {
        res = UART_ReceiveData( STR9_UART );
        break;
      }
      else
        res = -1;
      tmr_crt = platform_timer_op( timer_id, PLATFORM_TIMER_OP_READ, 0 );
      if( platform_timer_get_diff_us( timer_id, tmr_crt, tmr_start ) >= timeout )
        break;
    }
    return res;    
  }
}
Ejemplo n.º 19
0
void UART1_Handler(void)
{
    uint8_t ch;
    
    if(UART_GetITStatus(UART1,UART_IT_FLAG_RXI))
    {
        ch = UART_ReceiveData(UART1);
        uart1_rx_cnt++;
    }
    else if(UART_GetITStatus(UART1,UART_IT_FLAG_TXI))
    {
        UART_ClearITPendingBit(UART1,UART_IT_FLAG_TXI);
        uart1_tx_cnt++;
    }
}
Ejemplo n.º 20
0
void INT_UART0_Handler(void)
{
	uint32_t temp_1;

  if (UART_GetITStatusMasked(MDR_UART0, UART_IT_RX) == SET)
  {
		temp_1 = UART_ReceiveData(MDR_UART0);	
		
		UART_ClearITPendingBit(MDR_UART0, UART_IT_RX);

				while (UART_GetFlagStatus (MDR_UART0, UART_FLAG_TXFE)!= SET)
				{
				}
				UART_SendData (MDR_UART0,temp_1);
  }
}
/*******************************************************************************
* Function Name  : ReceiverFunc
* Description    : Receiver interrupt handler.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
static void ReceiverFunc(void)
{
  uint16_t receive_data;

  /* Read data from UART */
  for (receive_data_length = 0; ((UART_GetFlagStatus(UART, UART_FLAG_RXFE) == RESET) && (receive_data_length < BUFFER_LENGTH)); )
  {
    receive_data = UART_ReceiveData(UART);

    if (UART_Flags(receive_data) == 0)
    {
      ReceiveBuffer[receive_data_length++] = UART_Data(receive_data);
    }
  }
  /* Initiate data portion sending via USB */
  USB_CDC_SendData(ReceiveBuffer, receive_data_length);
}
Ejemplo n.º 22
0
Archivo: main.c Proyecto: Wiznet/W7500
int main()
{
	 /*System clock configuration*/
	SystemInit();
//    *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz
    
    /* CLK OUT Set */
//    PAD_AFConfig(PAD_PA,GPIO_Pin_2, PAD_AF2); // PAD Config - CLKOUT used 3nd Function
    /* UART0 and UART1 configuration*/
    UART_StructInit(&UART_InitStructure);
    /* Configure UART0 */
    UART_Init(UART0,&UART_InitStructure);
    /* Configure UART1 */
    UART_Init(UART1,&UART_InitStructure);

    while(TxCounter < TxBufferSize)
    {
        /* Send one byte from UART0 to UART1 */
        UART_SendData(UART0,TxBuffer[TxCounter++]);

        /* Loop until UART0 TX FIFO Register is empty */
        while(UART_GetFlagStatus(UART0,UART_FLAG_TXFE) == RESET)
        {
        } 

        /* Loop until the UART1 Receive FIFO Register is not empty */
        while(UART_GetFlagStatus(UART1,UART_FLAG_RXFE) == SET)
        {
        }
        
        /* Store the received byte in RxBuffer */
        RxBuffer[RxCounter++] = (UART_ReceiveData(UART1) & 0xFF);
    }

    /* Check the received data with the send ones */
    TransferStatus  = Buffercmp(TxBuffer, RxBuffer, TxBufferSize);
    /* 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 */

    while(1)
    {
    } 
}
void UART1_Handler(void)
{
					
				if(UART_GetITStatus(UART1, UART_IT_FLAG_RXI)) {			
					UART_ClearITPendingBit(UART1, UART_IT_FLAG_RXI);

		
									if( (u1rx_wr > u1rx_rd && u1rx_wr-u1rx_rd >= U1RX_BUF_SIZE-1) ||(u1rx_wr < u1rx_rd && u1rx_rd == u1rx_wr+1) )	// Buffer Overflow
									{
													UART_SendData(UART1, (uint8_t)'@');
													return;
									}
									u1rx_buf[u1rx_wr] = (uint8_t)UART_ReceiveData(UART1);
									
									if(u1rx_wr < U1RX_BUF_SIZE-1)
												u1rx_wr++;
									else 
												u1rx_wr = 0;
		}
}
Ejemplo n.º 24
0
void UART1_send_byte(uint8_t byte)
{
	UART_SendData(MDR_UART1,byte);
	time_out_byte = 0;
	/*while(!UART_GetFlagStatus (MDR_UART1,UART_FLAG_RXFF))
	{
		if( time_out_byte>3)
			break;
	}
	UART_ReceiveData (MDR_UART1);
	*/
	
	while(UART_GetFlagStatus (MDR_UART1,UART_FLAG_BUSY) || !UART_GetFlagStatus (MDR_UART1,UART_FLAG_RXFF))
	{
// 		if(time_out_byte>3)
// 			break;
	}
	UART_ReceiveData (MDR_UART1);
	UART_ClearITPendingBit(MDR_UART1,UART_IT_RX);
}
Ejemplo n.º 25
0
Archivo: main.c Proyecto: Wiznet/W7500P
int main()
{
	 /*System clock configuration*/
	SystemInit();
    /* UART0 and UART1 configuration*/
    UART_StructInit(&UART_InitStructure);
    /* Configure UART0 */
    UART_Init(UART0,&UART_InitStructure);
    /* Configure UART1 */
    UART_Init(UART1,&UART_InitStructure);

    while(TxCounter < TxBufferSize)
    {
        /* Send one byte from UART0 to UART1 */
        UART_SendData(UART0,TxBuffer[TxCounter++]);

        /* Loop until UART0 TX FIFO Register is empty */
        while(UART_GetFlagStatus(UART0,UART_FLAG_TXFE) == RESET)
        {
        } 

        /* Loop until the UART1 Receive FIFO Register is not empty */
        while(UART_GetFlagStatus(UART1,UART_FLAG_RXFE) == SET)
        {
        }
        
        /* Store the received byte in RxBuffer */
        RxBuffer[RxCounter++] = (UART_ReceiveData(UART1) & 0xFF);
    }

    /* Check the received data with the send ones */
    TransferStatus  = Buffercmp(TxBuffer, RxBuffer, TxBufferSize);
    /* 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 */

    while(1)
    {
    } 
}
Ejemplo n.º 26
0
void End_Init(void)
{
    P_END_OBJ pEndObj = NULL;
    unsigned char i;
    

    g_EndObject[PC_COM_PORT] = (pvoid)&PC_UART;
    g_EndObject[RS485_COM_PORT] = (pvoid)&RS485_UART;
    g_EndObject[PLC_COM_PORT] = (pvoid)&PLC_UART;

    mem_msg_buffer_init((MSG_INFO *)gShortMsgPool, (P_MSG_INFO *)pShortMsgPool, MAX_MSG_SHORT, sizeof(MSG_SHORT_INFO));

    //alan test  需要暂时注释掉, 不知为啥IIC Start 一调用, MCU 就飞啦.
    for( i = START_COM_PORT; i < MAX_COM_PORT; i++)
    {
        // 找到当前End Object
        pEndObj = g_EndObjectPool + i;

        /* end queue[x] initialize */ /* each end object define '50 block' queue */
        g_EndTxQueue[i] = define_new_queue((queue *)pTxEndQueueBuf[i], END_TX_QUEUE_SIZE);
        g_EndRxQueue[i] = define_new_queue((queue *)pRxEndQueueBuf[i], END_RX_QUEUE_SIZE);
       
        pEndObj->end_recv_buffer = (unsigned char *)pUartRxBuf[i];

        pEndObj->last_receive_len = 0;
        pEndObj->receive_len = 0;

        pEndObj->recv_timeout = 0;

        UART_ReceiveData(i, pEndObj->end_recv_buffer, UART_RECV_BUF_SIZE);

        // 所有串口状态转到REVC STATUS
        pEndObj->end_send_status = END_STATUS_IDLE;

        __HAL_UART_ENABLE_IT((UART_HandleTypeDef *)g_EndObject[i], UART_IT_RXNE);
    }
}
Ejemplo n.º 27
0
/**
 * @brief  Main program.
 * @param  None
 * @retval None
 */
void main ( void )
{
	uint8_t DataByte = 0x00;
	static uint8_t ReciveByte = 0x00;

	/* Enables the HSI clock on PORTD */
	RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTD, ENABLE);

	/* Fill PortInit structure*/
	PortInit.PORT_PULL_UP = PORT_PULL_UP_OFF;
	PortInit.PORT_PULL_DOWN = PORT_PULL_DOWN_OFF;
	PortInit.PORT_PD_SHM = PORT_PD_SHM_OFF;
	PortInit.PORT_PD = PORT_PD_DRIVER;
	PortInit.PORT_GFEN = PORT_GFEN_OFF;
	PortInit.PORT_FUNC = PORT_FUNC_MAIN;
	PortInit.PORT_SPEED = PORT_SPEED_MAXFAST;
	PortInit.PORT_MODE = PORT_MODE_DIGITAL;

	/* Configure PORTD pins 13 (UART2_TX) as output */
	PortInit.PORT_OE = PORT_OE_OUT;
	PortInit.PORT_Pin = PORT_Pin_13;
	PORT_Init(MDR_PORTD, &PortInit);
	/* Configure PORTD pins 14 (UART1_RX) as input */
	PortInit.PORT_OE = PORT_OE_IN;
	PortInit.PORT_Pin = PORT_Pin_14;
	PORT_Init(MDR_PORTD, &PortInit);

	/* Select HSI/2 as CPU_CLK source*/
	RST_CLK_CPU_PLLconfig(RST_CLK_CPU_PLLsrcHSIdiv2, 0);

	/* Enables the CPU_CLK clock on UART2 */
	RST_CLK_PCLKcmd(RST_CLK_PCLK_UART2, ENABLE);

	/* Set the HCLK division factor = 1 for UART2*/
	UART_BRGInit(MDR_UART2, UART_HCLKdiv1 );

	/* Initialize UART_InitStructure */
	UART_InitStructure.UART_BaudRate = 9600;
	UART_InitStructure.UART_WordLength = UART_WordLength8b;
	UART_InitStructure.UART_StopBits = UART_StopBits2;
	UART_InitStructure.UART_Parity = UART_Parity_Even;
	UART_InitStructure.UART_FIFOMode = UART_FIFO_OFF;
	UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_RXE
												| UART_HardwareFlowControl_TXE;

	/* Configure UART2 parameters*/
	UART_Init(MDR_UART2, &UART_InitStructure);
	/* Enables UART2 peripheral */
	UART_Cmd(MDR_UART2, ENABLE);

	while (1) {
		/* Check TXFE flag */
		while (UART_GetFlagStatus(MDR_UART2, UART_FLAG_TXFE) != SET);

		/* Send Data from UART2 */
		UART_SendData(MDR_UART2, DataByte);

		/* Check RXFF flag */
		while (UART_GetFlagStatus(MDR_UART2, UART_FLAG_RXFF) != SET);

		/* Recive data*/
		ReciveByte = UART_ReceiveData(MDR_UART2);

		/* Increment Data */
		DataByte++;
	}
}
Ejemplo n.º 28
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main (void)
{
uint8_t DataByte=0x01;
static uint8_t ReciveByte[16];
uint32_t i;

  /* Enables the HSI clock on PORTB,PORTD */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTB,ENABLE);
  RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTD,ENABLE);

  /* Fill PortInit structure*/
  PortInit.PORT_PULL_UP = PORT_PULL_UP_OFF;
  PortInit.PORT_PULL_DOWN = PORT_PULL_DOWN_OFF;
  PortInit.PORT_PD_SHM = PORT_PD_SHM_OFF;
  PortInit.PORT_PD = PORT_PD_DRIVER;
  PortInit.PORT_GFEN = PORT_GFEN_OFF;
  PortInit.PORT_FUNC = PORT_FUNC_ALTER;
  PortInit.PORT_SPEED = PORT_SPEED_MAXFAST;
  PortInit.PORT_MODE = PORT_MODE_DIGITAL;

  /* Configure PORTB pins 5 (UART1_TX) as output */
  PortInit.PORT_OE = PORT_OE_OUT;
  PortInit.PORT_Pin = PORT_Pin_5;
  PORT_Init(MDR_PORTB, &PortInit);

  /* Configure PORTB pins 6 (UART1_RX) as input */
  PortInit.PORT_OE = PORT_OE_IN;
  PortInit.PORT_Pin = PORT_Pin_6;
  PORT_Init(MDR_PORTB, &PortInit);

  /* Configure PORTD pins 1 (UART2_TX) as output */
  PortInit.PORT_OE = PORT_OE_OUT;
  PortInit.PORT_Pin = PORT_Pin_1;
  PORT_Init(MDR_PORTD, &PortInit);
  /* Configure PORTD pins 0 (UART1_RX) as input */
  PortInit.PORT_OE = PORT_OE_IN;
  PortInit.PORT_Pin = PORT_Pin_0;
  PORT_Init(MDR_PORTD, &PortInit);

  /* Select HSI/2 as CPU_CLK source*/
  RST_CLK_CPU_PLLconfig (RST_CLK_CPU_PLLsrcHSIdiv2,0);

  /* Enables the CPU_CLK clock on UART1,UART2 */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_UART1, ENABLE);
  RST_CLK_PCLKcmd(RST_CLK_PCLK_UART2, ENABLE);

  /* Set the HCLK division factor = 1 for UART1,UART2*/
  UART_BRGInit(MDR_UART1, UART_HCLKdiv1);
  UART_BRGInit(MDR_UART2, UART_HCLKdiv1);

  /* Initialize UART_InitStructure */
  UART_InitStructure.UART_BaudRate                = 115000;
  UART_InitStructure.UART_WordLength              = UART_WordLength8b;
  UART_InitStructure.UART_StopBits                = UART_StopBits1;
  UART_InitStructure.UART_Parity                  = UART_Parity_No;
  UART_InitStructure.UART_FIFOMode                = UART_FIFO_ON;
  UART_InitStructure.UART_HardwareFlowControl     = UART_HardwareFlowControl_RXE | UART_HardwareFlowControl_TXE;

  /* Configure UART1 parameters*/
  UART_Init (MDR_UART1,&UART_InitStructure);

  /* Configure DMA for UART1*/
  UART_DMAConfig (MDR_UART1, UART_IT_FIFO_LVL_12words, UART_IT_FIFO_LVL_12words);
  UART_DMACmd(MDR_UART1, UART_DMA_TXE | UART_DMA_RXE | UART_DMA_ONERR, ENABLE);

  /* Enables UART1 peripheral */
  UART_Cmd(MDR_UART1,ENABLE);

  /* Configure UART2 parameters*/
  UART_Init (MDR_UART2,&UART_InitStructure);

  /* Configure DMA for UART2*/
  UART_DMAConfig (MDR_UART2, UART_IT_FIFO_LVL_12words, UART_IT_FIFO_LVL_12words);
  UART_DMACmd(MDR_UART2, UART_DMA_TXE | UART_DMA_RXE | UART_DMA_ONERR, ENABLE);

  /* Enables UART2 peripheral */
  UART_Cmd(MDR_UART2,ENABLE);

  while (1)
  {
    /* Check TXFE flag */
    while (UART_GetFlagStatus (MDR_UART1, UART_FLAG_TXFE)!= SET)
    {
    }

    /* Send Data from UART1 */
    for (i=0;i<16;i++)
    {
      UART_SendData (MDR_UART1, (uint16_t)(i+16*DataByte));
    }

    /* Check RXFF flag */
    while (UART_GetFlagStatus (MDR_UART2, UART_FLAG_RXFF)!= SET)
    {
    }

    /* Recive data */
    for (i=0;i<16;i++)
    {
      ReciveByte[i] = UART_ReceiveData (MDR_UART2);
    }

    /* Increment Data */
    DataByte++;
  }
}
Ejemplo n.º 29
0
int UART_ReadChar()
{
    return UART_ReceiveData(LPC_UART);
}