Exemple #1
0
void UART_Configuration(TSB_SC_TypeDef * SCx)
{
    UART_InitTypeDef myUART;
    if (SCx == UART0) {
        TSB_PE_CR_PE0C = 1U;
        TSB_PE_FR1_PE0F1 = 1U;
        TSB_PE_FR1_PE1F1 = 1U;
        TSB_PE_IE_PE1IE = 1U;
    } else if (SCx == UART1) {
        TSB_PE_CR_PE4C = 1U;
        TSB_PE_FR1_PE4F1 = 1U;
        TSB_PE_FR1_PE5F1 = 1U;
        TSB_PE_IE_PE5IE = 1U;
    } else if (SCx == UART2) {
        TSB_PF_CR_PF0C = 1U;
        TSB_PF_FR1_PF0F1 = 1U;
        TSB_PF_FR1_PF1F1 = 1U;
        TSB_PF_IE_PF1IE = 1U;
    } else {
        /* Do nothing */
    }
    myUART.BaudRate = 115200U;
    myUART.DataBits = UART_DATA_BITS_8;
    myUART.StopBits = UART_STOP_BITS_1;
    myUART.Parity = UART_NO_PARITY;
    myUART.Mode = UART_ENABLE_TX;
    myUART.FlowCtrl = UART_NONE_FLOW_CTRL;

    UART_Enable(SCx);
    UART_Init(SCx, &myUART);
}
Exemple #2
0
/*******************************************************************************
* Function Name: UART_Start
****************************************************************************//**
*
*  Invokes UART_Init() and UART_Enable().
*  After this function call, the component is enabled and ready for operation.
*  When configuration is set to "Unconfigured SCB", the component must first be
*  initialized to operate in one of the following configurations: I2C, SPI, UART
*  or EZI2C. Otherwise this function does not enable the component.
*
* \globalvars
*  UART_initVar - used to check initial configuration, modified
*  on first function call.
*
*******************************************************************************/
void UART_Start(void)
{
    if (0u == UART_initVar)
    {
        UART_Init();
        UART_initVar = 1u; /* Component was initialized */
    }

    UART_Enable();
}
Exemple #3
0
/**
  * @brief  SIO Configuration Initialize the uart port (SIO0).
  * @param  None
  * @retval None
  */
void SIO_ChInit(void)
{
    UART_InitTypeDef myUART;

    /* configure SIO0 for reception */
    UART_Enable(UART_RETARGET);
    myUART.BaudRate = 115200U;  /* baud rate = 115200 */
    myUART.DataBits = UART_DATA_BITS_8; /* no handshake, 8-bit data, clock by baud rate generator */
    myUART.StopBits = UART_STOP_BITS_1; /* 1-bit stop, LSB,  W-buff enable */
    myUART.Parity = UART_NO_PARITY;
    myUART.Mode = UART_ENABLE_TX;
    myUART.FlowCtrl = UART_NONE_FLOW_CTRL;
    UART_Init(UART_RETARGET, &myUART);
}
Exemple #4
0
void uart_print(void)
{
    TSB_WD_MOD_WDTE = 0U;
    TSB_WD->CR = 0x000000B1;
    SIO_Configuration(UART0);
    myUART.BaudRate = 115200U;
    myUART.DataBits = UART_DATA_BITS_8;
    myUART.StopBits = UART_STOP_BITS_1;
    myUART.Parity = UART_NO_PARITY;
    myUART.Mode = UART_ENABLE_TX;
    myUART.FlowCtrl = UART_NONE_FLOW_CTRL;

    UART_Enable(UART0);
    UART_Init(UART0, &myUART);
		
    UART_Print("Hello World!\n");
}
Exemple #5
0
Fichier : main.c Projet : cmonr/PAL
int main(void)
{
    // Clock (80MHz)
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

    // Init LEDs
    Pin_Init(rLED);
    Pin_Set(rLED, LOW);

    // Init UART0
    UART_Init(UART0);
    UART_Enable(UART0);
    setbuf(stdout, NULL);   // Disable printf internal buffer

    // Init I2C0
    I2C_Init(I2C0);
    I2C_Enable(I2C0);



    // Wait until user presses enter
    UART_ReadChar(UART0);

    // Scan for I2C addresses
    for(i=0; i < (1 << 7); i++)
    {
        printf("x%02x:", i);
        if (I2C_Write(I2C0, i, 0) == true)
            printf("* ");
        else    
            printf("  ");

        Pin_Toggle(rLED);


        if (i % 8 == 7)
            printf("\r\n");
    }

    // Indicator LED off
    Pin_Set(rLED, LOW);
       
    while(1);      
}
Exemple #6
0
void UART_Configuration(TSB_SC_TypeDef * SCx)
{
    UART_InitTypeDef myUART;
    if (SCx == UART0) {
        TSB_PE_CR_PE4C = 1;
        TSB_PE_FR2_PE4F2 = 1;
        TSB_PE_FR2_PE5F2 = 1;
        TSB_PE_IE_PE5IE = 1;
    } else {
		//do nothing
	}
    myUART.BaudRate = 115200U;
    myUART.DataBits = UART_DATA_BITS_8;
    myUART.StopBits = UART_STOP_BITS_1;
    myUART.Parity = UART_NO_PARITY;
    myUART.Mode = UART_ENABLE_TX;
    myUART.FlowCtrl = UART_NONE_FLOW_CTRL;

    UART_Enable(SCx);
    UART_Init(SCx, &myUART);
}
Exemple #7
0
void uart_print(void)
{
    SIO_Configuration(UART);

    myUART.BaudRate = 115200U;
    myUART.DataBits = UART_DATA_BITS_8;
    myUART.StopBits = UART_STOP_BITS_1;
    myUART.Parity = UART_NO_PARITY;
    myUART.Mode = UART_ENABLE_RX | UART_ENABLE_TX;
    myUART.FlowCtrl = UART_NONE_FLOW_CTRL;

    UART_Enable(UART);
    UART_Init(UART, &myUART);

    NVIC_EnableIRQ(INTTX0_IRQn);
    
    UART_SetTxData(UART, (uint32_t) (TxBuffer[TxCounter++]));
    while (1) {
        /* Do nothing */
    }
}
Exemple #8
0
static rt_err_t CME_M7_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
{
    struct CME_M7_uart* uart;
	UART_InitTypeDef init;

    RT_ASSERT(serial != RT_NULL);
    RT_ASSERT(cfg != RT_NULL);

    uart = (struct CME_M7_uart *)serial->parent.user_data;

	init.UART_BaudRate = cfg->baud_rate;
	init.UART_StopBits = UART_StopBits_1;
    init.UART_Parity = UART_Parity_None;
	init.UART_LoopBack = FALSE;
	init.UART_RxEn = TRUE;
	init.UART_CtsEn = FALSE;

    UART_Init(uart->uart_device, &init);
    uart->uart_device->RX_RESET = 1;
	UART_Enable(uart->uart_device, TRUE);
    uart->uart_device->RX_RESET = 0;

    return RT_EOK;
}
Exemple #9
0
/*******************************************************************************
* Function Name: UART_Wakeup
********************************************************************************
*
* Summary:
*  Calls RestoreConfig function fucntion for selected mode.
*
* Parameters:
*  None
*
* Return:
*  None
*
*******************************************************************************/
void UART_Wakeup(void)
{
#if(UART_SCB_MODE_UNCONFIG_CONST_CFG)

    UART_EnableTxPinsInputBuffer();
        
    if(0u != UART_scbEnableWake)
    {
        if(UART_SCB_MODE_I2C_RUNTM_CFG)
        {
            UART_I2CRestoreConfig();
        }
        else if(UART_SCB_MODE_SPI_RUNTM_CFG)
        {
            UART_SpiRestoreConfig();
        }
        else if(UART_SCB_MODE_UART_RUNTM_CFG)
        {
            UART_UartRestoreConfig();
        }
        else if(UART_SCB_MODE_EZI2C_RUNTM_CFG)
        {
            UART_EzI2CRestoreConfig();
        }
        else
        {
            /* Unknown mode: do nothing */
        }
    }
    else
    {    
        /* Restore enable state */
        if(0u != UART_backup.enableState)
        {
            UART_Enable();
        }
    }

#else
    
    UART_EnableTxPinsInputBuffer();
        
    #if defined (UART_I2C_WAKE_ENABLE_CONST) && (UART_I2C_WAKE_ENABLE_CONST)
        UART_I2CRestoreConfig();
        
    #elif defined (UART_SPI_WAKE_ENABLE_CONST) && (UART_SPI_WAKE_ENABLE_CONST)
        UART_SpiRestoreConfig();
        
    #elif defined (UART_UART_WAKE_ENABLE_CONST) && (UART_UART_WAKE_ENABLE_CONST)
        UART_UartRestoreConfig();
        
    #elif defined (UART_EZI2C_WAKE_ENABLE_CONST) && (UART_EZI2C_WAKE_ENABLE_CONST)
        UART_EzI2CRestoreConfig();
    
    #else
        /* Check enable state */
        if(0u != UART_backup.enableState)
        {
            UART_Enable();
        }
        
    #endif /* (UART_I2C_WAKE_ENABLE_CONST) */

#endif /* (UART_SCB_MODE_UNCONFIG_CONST_CFG) */
}
Exemple #10
0
int main(void)
{
    // Clock (50MHz)
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
    
    
    // Init peripherals
    //  UART0/1
    UART_Init(UART0);
    UART_Enable(UART0);

    UART_Init(UART1);
    UART_SetIRQ(UART1, UART_RX_IRQ, &UART1_RX_IRQ);
    UART_IntEnable(UART1, UART_RX_IRQ);
    UART_Enable(UART1);
    setbuf(stdout, NULL);
    u1BufPtr = u1Buf;

    //  I2C0
    I2C_Init(I2C0);
    I2C_Enable(I2C0);

    //  PWM0/1
    PWM_Init(PWM0, 50);
    PWM_Init(PWM1, 1000);
    PWM_Enable(rLED);
    PWM_Enable(gLED);
    PWM_Enable(bLED);
    PWM_Set(rLED, 0);
    PWM_Set(gLED, 0);
    PWM_Set(bLED, 0);
    

    // Init Robotics BoosterPack
    RoboticsBP_Init();

    // NVIC
    IntMasterEnable();

    // As soon as UART1 IRW is enabled, a character is
    //  incorrectly received. Correct the issue by simply
    //  resetting the buffer pointer.
    //  Might be a bug in UART implementation of PAL
    u1BufPtr = u1Buf;
   

    
    // Start parsing commands as they become available
    cmdHead = u1Buf;
    cmdTail = u1Buf;

    while(1)
    {
        // Wait until buffPtr moves
        //  Might be possible to use wfi() here
        if (cmdTail == u1BufPtr)
            continue;
       
        // This is apparently needed, otherwise everything doesn't work...
        printf("%c%d", *cmdTail, *cmdTail == ';');
        
        // Increment pointer
        cmdTail++;

        // If command is complete
        if (*cmdTail == ';')
        {
            printf("\r\n");

            // Fake the end of a string
            *cmdTail = 0;
            
            // Execute command
            parseCmd();
            
            // Update pointers
            //  Check if we need to loop back
            if (cmdTail > u1Buf + 1000)
            {
                // Reset pointers to beginning of buffer
                cmdHead = u1Buf;
                cmdTail = u1Buf;
            }
            else
            {
                // Upadte pointers
                cmdHead = ((unsigned char*) cmdTail) + 1;
                cmdTail = cmdHead;
            }
        }
    }
}
Exemple #11
0
/*******************************************************************************
* Function Name: UART_Wakeup
********************************************************************************
*
* Summary:
*  Prepares the component for the Active mode operation after exiting Deep Sleep.
*  The “Enable wakeup from Sleep Mode” option has an influence on this function
*  implementation.
*  This function should not be called after exiting Sleep.
*
* Parameters:
*  None
*
* Return:
*  None
*
*******************************************************************************/
void UART_Wakeup(void)
{
#if(UART_SCB_MODE_UNCONFIG_CONST_CFG)

    if(UART_SCB_WAKE_ENABLE_CHECK)
    {
        if(UART_SCB_MODE_I2C_RUNTM_CFG)
        {
            UART_I2CRestoreConfig();
        }
        else if(UART_SCB_MODE_EZI2C_RUNTM_CFG)
        {
            UART_EzI2CRestoreConfig();
        }
#if(!UART_CY_SCBIP_V1_I2C_ONLY)
        else if(UART_SCB_MODE_SPI_RUNTM_CFG)
        {
            UART_SpiRestoreConfig();
        }
        else if(UART_SCB_MODE_UART_RUNTM_CFG)
        {
            UART_UartRestoreConfig();
        }
#endif /* (!UART_CY_SCBIP_V1_I2C_ONLY) */
        else
        {
            /* Unknown mode: do nothing */
        }
    }
    else
    {
        if(0u != UART_backup.enableState)
        {
            UART_Enable();
        }
    }

#else

#if (UART_SCB_MODE_I2C_CONST_CFG  && UART_I2C_WAKE_ENABLE_CONST)
    UART_I2CRestoreConfig();

#elif (UART_SCB_MODE_EZI2C_CONST_CFG && UART_EZI2C_WAKE_ENABLE_CONST)
    UART_EzI2CRestoreConfig();

#elif (UART_SCB_MODE_SPI_CONST_CFG && UART_SPI_WAKE_ENABLE_CONST)
    UART_SpiRestoreConfig();

#elif (UART_SCB_MODE_UART_CONST_CFG && UART_UART_WAKE_ENABLE_CONST)
    UART_UartRestoreConfig();

#else

    if(0u != UART_backup.enableState)
    {
        UART_Enable();
    }

#endif /* (UART_I2C_WAKE_ENABLE_CONST) */

#endif /* (UART_SCB_MODE_UNCONFIG_CONST_CFG) */
}