コード例 #1
0
/*!
 * @brief Check send/receive polling functionality
 *
 */
int main(void)
{
    uint8_t  rxChar          = 0;
    uint32_t byteCountBuff   = 0;
    uint32_t uartSourceClock = 0;
    UART_Type * baseAddr     = BOARD_DEBUG_UART_BASEADDR;

    // Enable clock for PORTs, setup board clock source, config pin
    hardware_init();

    // Initialize the uart module with base address and config structure
    CLOCK_SYS_EnableUartClock(BOARD_DEBUG_UART_INSTANCE);

    // Get working uart clock
    uartSourceClock = CLOCK_SYS_GetUartFreq(BOARD_DEBUG_UART_INSTANCE);

    // Initialize UART baud rate, bit count, parity and stop bit
    UART_HAL_SetBaudRate(baseAddr, uartSourceClock, BOARD_DEBUG_UART_BAUD);
    UART_HAL_SetBitCountPerChar(baseAddr, kUart8BitsPerChar);
    UART_HAL_SetParityMode(baseAddr, kUartParityDisabled);
#if FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
    UART_HAL_SetStopBitCount(baseAddr, kUartOneStopBit);
#endif

    // Enable the UART transmitter and receiver
    UART_HAL_EnableTransmitter(baseAddr);
    UART_HAL_EnableReceiver(baseAddr);

    // Inform to start polling example
    byteCountBuff = sizeof(buffStart);
    UART_HAL_SendDataPolling(baseAddr, buffStart, byteCountBuff);

    // Inform user of what to do
    byteCountBuff = sizeof(bufferData1);
    UART_HAL_SendDataPolling(baseAddr, bufferData1, byteCountBuff);

    while(true)
    {
        // Wait to receive input data
        if (kStatus_UART_Success == UART_HAL_ReceiveDataPolling(baseAddr, &rxChar, 1u))
        {
            // Send any character that received
            UART_HAL_SendDataPolling(baseAddr, &rxChar, 1u);
        }
    }

}
コード例 #2
0
ファイル: main.c プロジェクト: Andrew1066/Splinter-bringup
/*lint -save  -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */
	   uint8_t  rxChar          = 0;
	    uint32_t byteCountBuff   = 0;
	    uint32_t uartSourceClock = 0;
	    UART_Type * baseAddr     = UART2_BASE; // was BOARD_DEBUG_UART_BASEADDR;

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */
  /* For example: for(;;) { } */
  // Initialize the uart module with base address and config structure
   CLOCK_SYS_EnableUartClock(BOARD_DEBUG_UART_INSTANCE);

   // Get working uart clock
   uartSourceClock = CLOCK_SYS_GetUartFreq(BOARD_DEBUG_UART_INSTANCE);

   // Initialize UART baud rate, bit count, parity and stop bit
   UART_HAL_SetBaudRate(baseAddr, uartSourceClock, 9600); // was BOARD_DEBUG_UART_BAUD
   UART_HAL_SetBitCountPerChar(baseAddr, kUart8BitsPerChar);
   UART_HAL_SetParityMode(baseAddr, kUartParityDisabled);
#if FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
   UART_HAL_SetStopBitCount(baseAddr, kUartOneStopBit);
#endif

   // Enable the UART transmitter and receiver
   UART_HAL_EnableTransmitter(baseAddr);
   UART_HAL_EnableReceiver(baseAddr);

   // Inform to start polling example
   byteCountBuff = sizeof(buffStart);
   UART_HAL_SendDataPolling(baseAddr, buffStart, byteCountBuff);

   // Inform user of what to do
   byteCountBuff = sizeof(bufferData1);
   UART_HAL_SendDataPolling(baseAddr, bufferData1, byteCountBuff);

   while(true)
   {
       // Wait to receive input data
       if (kStatus_UART_Success == UART_HAL_ReceiveDataPolling(baseAddr, &rxChar, 1u))
       {
           // Send any character that received
           UART_HAL_SendDataPolling(baseAddr, &rxChar, 1u);
       }
   }

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/