Пример #1
0
//*****************************************************************************
//
//! \brief something should do before the test execute of xpwm002 test.
//!
//! \return None.
//
//*****************************************************************************
static void xpwm002Setup(void)
{
   
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_PWMA);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_PWMB);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_PWMC);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_PWMD);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_PWME);
    //
    // GPIO pin function set as pwm output
    //
    xSPinTypeTimer(TIM1CH1, PA8);
    xSPinTypeTimer(TIM1CH2, PE11);
    xSPinTypeTimer(TIM1CH3, PA10);
    xSPinTypeTimer(TIM1CH4, PA11);
    xSPinTypeTimer(TIM2CH1, PA0);
    xSPinTypeTimer(TIM2CH2, PA1);
    xSPinTypeTimer(TIM2CH3, PA2);
    xSPinTypeTimer(TIM2CH4, PA3);
    xSPinTypeTimer(TIM3CH1, PA6);
    xSPinTypeTimer(TIM3CH2, PA7);
    xSPinTypeTimer(TIM3CH3, PB0);
    xSPinTypeTimer(TIM3CH4, PB1);
    xSPinTypeTimer(TIM4CH1, PB6);
    xSPinTypeTimer(TIM4CH2, PB7);
    xSPinTypeTimer(TIM4CH3, PB8);
    xSPinTypeTimer(TIM4CH4, PB9);
}
Пример #2
0
void LCDShield(void)
{
    int key;
	
    xSysCtlClockSet(12000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ);
    xSysCtlDelay(1000);
	
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0);	
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(sD13));   
    xSysCtlPeripheralClockSourceSet(xSYSCTL_UART0_MAIN, 1);
	
    LCDShieldInit();
	
    //
    // Enable Peripheral SPI0
    //
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_ADC);
	  
    xSPinTypeADC(ADC0, sA0);
	  
    //
    // ADC Channel0 convert once, Software tirgger.
    //
    xADCConfigure(xADC0_BASE, xADC_MODE_SCAN_CONTINUOUS, ADC_TRIGGER_PROCESSOR);  
	  
    //
    // Enable the channel0
    //
    xADCStepConfigure(xADC0_BASE, 0, xADC_CTL_CH0); 
    
    //
    // Enable the adc
    //
    xADCEnable(xADC0_BASE);
		
    //
    // start ADC convert
    //
    xADCProcessorTrigger( xADC0_BASE );
		
    LCDShieldLocationSet(0, 0);
    LCDShieldDisplayString("Hello Nuvoton!");
    LCDShieldLocationSet(0, 1);
    LCDShieldDisplayString("Hello CooCox! ");
		
    xSysCtlDelay(1000000);

    while(1)
    {
        key = LCDShieldButtonGet();
        if(key != -1)
        {
            LCDShieldDisplayClear();
            LCDShieldLocationSet(0, 0);
            LCDShieldDisplayString("The key is: ");
            LCDShieldLocationSet(0, 1);
            LCDShieldDisplayString(&cKey[key][0]);
        }
    }
}
Пример #3
0
void SensorExample(void)
{
	int ADValue;
	char buf[4];
	//
    // Initionalize system clock.
    //
    xSysCtlClockSet(72000000,  xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);
    xSysCtlDelay(100000);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);
    xSysCtlPeripheralEnable2(sUART_BASE);
    xUARTConfigSet(sUART_BASE, 115200, (xUART_CONFIG_WLEN_8 |
									     xUART_CONFIG_STOP_1 |
									     xUART_CONFIG_PAR_NONE));
    xUARTEnable(sUART_BASE, (xUART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX));
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    sPinTypeUART(sUART_BASE);

	SensorShieldInit();

    while(1){
        ADValue = ADCValueGet(SENSOR_SHIELD_AI2);
        buf[0] = ADValue/1000 + 0x30;
        buf[1] = ADValue/100%10 + 0x30;
        buf[2] = ADValue/10%10 + 0x30;
        buf[3] = ADValue%10 + 0x30;
	    SensorShieldUARTBufferPut(sUART_BASE, buf, 4);
    }
}
Пример #4
0
//*****************************************************************************
//
//! \brief print some data to terminal.
//!
//! \param None
//!
//! \return None.
//
//*****************************************************************************
void UartPrintf(void)
{
    unsigned long i;
    //
    //Set System Clock
    //
    xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);

    xSysCtlDelay(10000);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOD);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);

      xSPinTypeUART(UART1TX,PA9);
    

    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART1);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART1);

    xUARTConfigSet(USART1_BASE, 115200, (UART_CONFIG_WLEN_8 |
                                         UART_CONFIG_STOP_ONE | 
                                         UART_CONFIG_PAR_NONE));

    xUARTEnable(USART1_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX));

    for(i = 0; i < sizeof("STM32F1xx.UART Example of CoX \r\n"); i++)
    {
        xUARTCharPut(USART1_BASE, ucData[i]);
    }
}
Пример #5
0
void DeltaAngleGet()
{
	tLPR5150ALData g_XYAxisCurrentVoltage;
	tLPR5150ALData g_XYAxisNullVoltage;
	tLPR5150ALData g_XYAxisAngle;
	tLPR5150ALData g_XYAxisRate;

    xSysCtlClockSet(12000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ);
    xSysCtlDelay(1000);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0);
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(sD13));
    xSysCtlPeripheralClockSourceSet(xSYSCTL_UART0_MAIN, 1);

    sPinTypeUART(sUART_DBG_BASE);
    xUARTConfigSet(sUART_DBG_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    xUARTEnable(sUART_DBG_BASE, (UART_BLOCK_UART | UART_BLOCK_RX));

    //automatically added by CoIDE
	//ADConvert();


    xSysCtlClockSet(12000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ);

    LPR5150ALInit();

	while(1)
    {
		g_XYAxisAngle = LPR5150ALXYAxisAngleGet();
		printf("The roll angle is: %f   ", g_XYAxisAngle.fXAxisData);
		printf("The pitch angle is: %f \r\n", g_XYAxisAngle.fYAxisData);
		//DelayMS(500);
    }
}
Пример #6
0
// init servo signal and pin
// does not check arguments, make sure to pass valide arguments
void servo_init(void)
{
	xSysCtlPeripheralClockSourceSet(xSYSCTL_PWMB_MAIN, 1);

	// Enable PWM peripheral
	xSysCtlPeripheralEnable(SYSCTL_PERIPH_PWMB);

	// Enable gpio pin peripheral
	xSysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

	// Enable PWM and set GPIO Pin as PWM
	xSPinTypePWM(TIM1CH0, PB0);
//	xSPinTypePWM(TIM0CH3, PE30);

	// Set invert, dead zone and mode
	xPWMInitConfigure(xPWMB_BASE, xPWM_CHANNEL0, xPWM_TOGGLE_MODE);

	// Set CNR, Prescale and Divider. FHz = 50Hz
	xPWMFrequencySet(xPWMB_BASE, xPWM_CHANNEL0, 50);

	// Set CMR, high pulse @ 1,5 ms middle position
	servo_angle(0);

	// Set output enable
	xPWMOutputEnable(xPWMB_BASE, xPWM_CHANNEL0);

	// start pwm
	xPWMStart(xPWMB_BASE, xPWM_CHANNEL0);

	// initialization ok

}
Пример #7
0
void UART_example(void)
{
    unsigned int i = 0;

    //
    // Configure System clock
    //
    xSysCtlClockSet(84000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ);
    SysCtlDelay(10000);

    //
    // Enable GPIO/UART Clock
    //
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOG);

    //
    // Remap UART pin to GPIO Port UART0_RX --> PG1 UART0_TX --> PG2
    xSPinTypeUART(UART0RX, PG1);
    xSPinTypeUART(UART0TX, PG2);

    //
    // Configure UART Baud 115200 8-N-1
    //
    xUARTConfigSet(xUART0_BASE, 115200, xUART_CONFIG_WLEN_8 | xUART_CONFIG_PAR_NONE | xUART_CONFIG_STOP_1);

    //
    // Enable UART Receive/Transmit
    //
    xUARTEnable(xUART0_BASE, xUART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX);

    //
    // print out welcome information
    //

    i = 0;
    while(Buf[i] != '\0')
    {
        xUARTCharPut(xUART0_BASE, Buf[i++]);
    }

    //
    // Echo user's input information
    //
    while((Rec = UxARTCharGet(xUART0_BASE)) != '\n')
    {
        xUARTCharPut(xUART0_BASE, Rec);
    }

    //
    // print out run over information
    //
    i = 0;
    while(Buf[i] != '\0')
    {
        xUARTCharPut(xUART0_BASE, End[i++]);
    }

    while(1);                  
}
Пример #8
0
//*****************************************************************************
//
//! \brief Init uart to print.
//!
//! \param None
//!
//! \details uart config as (115200, 8 data bit, 1 stop bit , no partiy)
//!
//! \return None.
//
//*****************************************************************************
static 
void UartInit(void)
{

    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);

    xSPinTypeUART(UART0RX, PC10);
    xSPinTypeUART(UART0TX, PC8);
    

    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART0);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0);
    //
    // Set UART0 clock source.
    //
    SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_UART_S_HCLK);

    //
    // Configure 8 bit word length, 1 stop bit,
    // and none parity bit, receive FIFO 1 byte.
    //
    xUARTConfigSet(UART0_BASE, 115200, (xUART_CONFIG_WLEN_8 |
                                        xUART_CONFIG_STOP_1 |
                                        xUART_CONFIG_PAR_NONE));

    xUARTEnable(UART0_BASE, (UART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX));
}
Пример #9
0
//*****************************************************************************
//
//! \brief Initialize I2C
//!
//! \param None
//!
//! This function initialize the mcu I2C as master and specified I2C port.
//!
//! \note internal function, used in this file only.
//! \note The max data rate is 100KHz.
//! \return None.
//
//*****************************************************************************
static Result _I2CComPortInit(void)
{
    //I2C Max clock: 100K
    uint32_t I2CInitClkRate = 100000;

    xSysCtlPeripheralEnable(PCF8574_I2C_GPIO);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);

    //
    // Enable the I2C which is connected with PCF8574
    //
    xSysCtlPeripheralEnable2(PCF8574_PIN_I2C_PORT);

    //
    // Set PCF8574_PIN_I2C_SCK as I2C SCK Pin
    //
    xSPinTypeI2C(PCF8574_I2C_SCK, PCF8574_PIN_I2C_SCK);

    //
    // Set PCF8574_PIN_I2C_SDA as I2C SDA Pin
    //
    xSPinTypeI2C(PCF8574_I2C_SDA, PCF8574_PIN_I2C_SDA);

    //
    // I2C enable
    //
    xI2CMasterEnable(PCF8574_PIN_I2C_PORT);

    //
    // Initializes the I2C Master block.
    //
    xI2CMasterInit(PCF8574_PIN_I2C_PORT, I2CInitClkRate);

    return(SUCCESS);
}
Пример #10
0
//*****************************************************************************
//
//! \brief Initialize TC77 
//!
//! \param ulClock specifies the SPI Clock Rate
//!
//! This function is to initialize the MCU as master and specified SPI port.Set
//! TC77_PIN_SPI_CS as CS, TC77_PIN_SPI_CLK as CLK, TC77_PIN_SPI_MISO ->MISO and 
//! TC77_PIN_SPI_MOSI->MOSI,most of all it check the first conversion is finished 
//! or not in order to execute the following operation.
//! 
//! \return None.
//
//*****************************************************************************
void
TC77Init(unsigned long ulSpiClock)
{
    short sReadValue = 0;
    
    //
    // The max clock rate of TC77 is 7M Hz acoording to Datasheet, Otherwise
    // it will generate  bigger error
    //
    xASSERT((ulSpiClock > 0) && (ulSpiClock < 7000000));
    
    //
    // Enable the GPIOx port which is connected with tc77 
    //
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(TC77_PIN_SPI_MISO));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(TC77_PIN_SPI_MOSI));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(TC77_PIN_SPI_CLK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(TC77_PIN_SPI_CS));
    
    //
    // Enable the SPIx which is connected with tc77
    //
    xSysCtlPeripheralEnable2(TC77_PIN_SPI_PORT);
    
    //
    // Set TC77_PIN_SPI_CS as a chip select pin and set it as OUT_MODE
    //
    xGPIOSPinDirModeSet(TC77_PIN_SPI_CS, xGPIO_DIR_MODE_OUT);
    
    //
    // Set TC77_PIN_SPI_CLK as SPIx.CLK
    //
    xSPinTypeSPI(TC77_SPI_CLK, TC77_PIN_SPI_CLK);
    
    //
    // Set TC77_PIN_SPI_MISO as SPIx.MISO
    //
    xSPinTypeSPI(TC77_SPI_MISO, TC77_PIN_SPI_MISO);
    
    //
    // Configure MCU as a master device , 16 bits data width ,MSB first,Mode_0
    //
    xSPIConfigSet(TC77_PIN_SPI_PORT, ulSpiClock, xSPI_MOTO_FORMAT_MODE_0 |
                                                       xSPI_DATA_WIDTH16 |
                                                        xSPI_MODE_MASTER |
                                                           xSPI_MSB_FIRST);
    //
    // Disable TC77 when Power up
    //
    xGPIOSPinWrite(TC77_PIN_SPI_CS, 1);

    //
    // Wait for the first conversion completed
    //
    while(!(0x0004 & sReadValue))
    {
        sReadValue = TC77TemperRead();
    }
}
Пример #11
0
//*****************************************************************************
//
//! \brief Something should do before the test execute of xgpio001 test.
//!
//! \return None.
//
//*****************************************************************************
static void xgpio001Setup(void)
{
    xSysCtlClockSet(8000000, xSYSCTL_XTAL_8MHZ | xSYSCTL_OSC_MAIN);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	xSysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
	xSysCtlPeripheralEnable(SYSCTL_PERIPH_EXTI);
}
Пример #12
0
//*****************************************************************************
//
//! Ininite the ADC 
//!
//! \param None
//!
//! This function ininite the ADC including clock source and enable ADC 
//!
//! \return none
//
//*****************************************************************************
void ADConvert(void)
{
  
    unsigned long ulAdcSeqNo[] = {0};

    xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);
    xSysCtlDelay(10000);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);
    //
    // configure GPIO pin as ADC function
    //
    xSPinTypeADC(ADC0, PA0);
    //
    // Reset ADC 
    //
    xSysCtlPeripheralReset(xSYSCTL_PERIPH_ADC1);

    //
    // Set ADC clock source
    //
    xSysCtlPeripheralClockSourceSet(xSYSCTL_ADC0_MAIN, 4);

    //
    // Enable ADC clock 
    //
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_ADC1);
 
    //
    // Set the length of converter
    //
    ADCConverLenSet(ADC1_BASE, 1, 1);

    //
    // Set the Index of converter Sequence
    //
    ADCSequenceIndexSet(ADC1_BASE, ulAdcSeqNo, ulAdcSeqNo);

    ADCSampLenSet(ADC1_BASE, 0, 128);

    //
    // A/D interrupt enable 
    //
    ADCIntEnable(ADC1_BASE, ADC_INT_END_CONVERSION);
    xIntEnable(xINT_ADC0);
    xADCIntCallbackInit(ADC1_BASE, ADC0IntFucntion);
    //
    // Software trigger enable
    //
    ADCProcessorTrigger(ADC1_BASE);
    //
    // A/D configure 
    //
    ADCRegularConfigure(ADC1_BASE, ADC_OP_SINGLE, ADC_TRIGGER_PROCESSOR);
    ADCDataRegularGet(ADC1_BASE, ADC_MODE_NORMAL);
}
Пример #13
0
void LCD_GPIO_Init(void)
{
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOB);
    xGPIODirModeSet( xGPIO_PORTA_BASE, xGPIO_PIN_8, xGPIO_DIR_MODE_OUT); 
    xGPIODirModeSet( xGPIO_PORTB_BASE, xGPIO_PIN_12, xGPIO_DIR_MODE_OUT);
    xGPIODirModeSet( xGPIO_PORTB_BASE, xGPIO_PIN_13, xGPIO_DIR_MODE_OUT);
    xGPIODirModeSet( xGPIO_PORTB_BASE, xGPIO_PIN_14, xGPIO_DIR_MODE_OUT);
    xGPIODirModeSet( xGPIO_PORTB_BASE, xGPIO_PIN_15, xGPIO_DIR_MODE_OUT);
}
Пример #14
0
//*****************************************************************************
//
//! \brief Initialize AT45DB161 and SPI
//!
//! \param ulSpiClock specifies the SPI Clock Rate
//!
//! This function initialize the mcu SPI as master and specified SPI port.
//! After SPI and port was configured, the mcu send a AT45DB161_CMD_SRRD command
//! to get the page size of AT45DB161 to get prepareed for the followed read and
//! write operations.
//!
//! \return None.
//
//*****************************************************************************
void AT45DB161_Init(unsigned long ulSpiClock)
{
    unsigned char tmp;
    xASSERT((ulSpiClock > 0) && (ulSpiClock < AT45DB161_MAX_CLK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_SCK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_CS_PIN));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_MISO));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_MOSI));
    xSysCtlPeripheralEnable2(AT45DB161_SPI_PORT);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    xGPIOSPinDirModeSet(AT45DB161_CS_PIN, xGPIO_DIR_MODE_OUT);
#if (AT45DB161_WRITE_PROTECT < 1)
    xGPIOSPinDirModeSet(FLASH_PIN_WRITE_PROTECT, xGPIO_DIR_MODE_OUT);
    xGPIOSPinWrite(FLASH_PIN_WRITE_PROTECT, 0);
#endif
    //
    // PD1 as SPI2.CLK
    //
    xSPinTypeSPI(SPI_CLK, AT45DB161_SCK);
    //
    // PD2 as SPI2.MISO
    // MISO20 => SPI0MISO
    //
    xSPinTypeSPI(SPI_MISO, AT45DB161_MISO);
    //
    // PD3 as SPI2.MOSI
    // MOSI20 => SPI0MISO
    //
    xSPinTypeSPI(SPI_MOSI, AT45DB161_MOSI);

    //xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    //
    //! Set SPI mode.
    //
    xSPIConfigSet(AT45DB161_SPI_PORT, ulSpiClock, SPI_MODE_MASTER |
                  SPI_MSB_FIRST |
                  SPI_2LINE_FULL |
                  SPI_DATA_WIDTH8 |
                  SPI_FORMAT_MODE_4);
    SPISSModeConfig(AT45DB161_SPI_PORT, SPI_CR1_SSM);
    SPISSIConfig(AT45DB161_SPI_PORT, SPI_CR1_SSI);
    SPIEnble(AT45DB161_SPI_PORT);
    AT45DB161_CS = 1;
    xSPISingleDataReadWrite(AT45DB161_SPI_PORT, 0xFF);
    xSysCtlDelay(100000);
    AT45DB161_CS = 0;
    //
    //! Read AT45DB161 state register to get the page size.
    //
    xSPISingleDataReadWrite(AT45DB161_SPI_PORT, AT45DB161_CMD_SRRD);
    tmp = xSPISingleDataReadWrite(AT45DB161_SPI_PORT, 0xFF);
    if(tmp & AT45DB161_PGSZ) AT45DB161_PageSize = 512;
    AT45DB161_CS = 1;
}
Пример #15
0
//
// Enable I2C, GPIO clock
// Set pins to I2C funciton
//
void pinSet()
{
    //
    // Enable GPIO Clock
    //
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(PA8));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(PA9));

    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(PB13));

    xSPinTypeI2C(I2C0SDA, PA8);
    xSPinTypeI2C(I2C0SCK, PA9);
}
Пример #16
0
//*****************************************************************************
//
//! !brief xrtc 001 test for clock config.
//!
//! \return None.
//
//*****************************************************************************
static void xrtc001Execute_clock_Config(void)
{
		xSysCtlPeripheralEnable(SYSCTL_PERIPH_PWR);
		SysCtlBackupAccessEnable();
	
		SysCtlLSEConfig(SYSCTL_LSE_OSC_EN);		
		TestAssert((xHWREG(RCC_BDCR)&0x03) == 0x03, "enable LSE error!");
	
		SysCtlPeripheralClockSourceSet(SYSCTL_RTC_LSE); 
		TestAssert(xHWREG(RCC_BDCR)&((SYSCTL_RTC_LSE&0x03)<<8) == ((SYSCTL_RTC_LSE&0x03)<<8), "select LSE as RTC clock error!");
		
		xSysCtlPeripheralEnable(SYSCTL_PERIPH_RTC);
		TestAssert((xHWREG(RCC_BDCR)&0x8000) == 0x8000, "enable RTC clock error!");
}
Пример #17
0
//*****************************************************************************
//
//! \brief initialize USART for debugging use
//!
//! \param None
//!
//! \details Initialize USART1 for debugging use. Debugging will use printf function,
//!   so we use USART1 as the debugging tool. Don't forget to add and transplant printf.c.
//! If you don't need debugging or you have your own debugging function, remove this
//! function.
//!
//! \return None
//
//*****************************************************************************
void    mInitSTDIO( void )
{
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);

    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART1);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART1);
    xUARTConfigSet(xUART1_BASE, 115200, (xUART_CONFIG_WLEN_8 |
    									 xUART_CONFIG_STOP_1 |
    									 xUART_CONFIG_PAR_NONE));

    xUARTEnable(xUART1_BASE, (xUART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX));
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    xSPinTypeUART(UART1TX, PA9);
}
Пример #18
0
//*****************************************************************************
//
//! \brief something should do before the test execute of xtimer001 test.
//!
//! \return None.
//
//*****************************************************************************
static void xTimer001Setup(void)
{
    int i;
    //
    //Set the external 12MHZ clock as system clock 
    //
    SysCtlKeyAddrUnlock();
    xSysCtlClockSet(12000000, xSYSCTL_XTAL_6MHZ | xSYSCTL_OSC_MAIN);
    
    //
    // Set the timer clock
    //
    SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_TMR0_S_EXT12M);
    SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_TMR1_S_EXT12M);
    SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_TMR2_S_EXT12M);
    SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_TMR3_S_EXT12M);
    
    //
    // Enable the tiemr0-3 peripheral
    //
    for(i = 0; i < 4; i++)
    {   
        
        xSysCtlPeripheralEnable(ulTimerID[i]);  
       
    }
    
}
Пример #19
0
//*****************************************************************************
//
//! \brief Init Spi communction port and wifi handshake pin.
//
//! WiFi shield IO refence volatge == 3.3V
//! Pin map is below:
//! HAND_PIN  --> PA3
//! SPI1_NSS  --> PA4
//! SPI1_SCK  --> PA5
//! SPI1_MISO --> PA6
//! SPI1_MOSI --> PA7
//!
//! \param none.
//!
//! \return None
//
//*****************************************************************************
void SpiDrv_Init(void)
{
    
    xSysCtlClockSet(72000000,  xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SPI1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);

    xGPIOSPinTypeGPIOInput(PA3);
    xGPIOSPinTypeGPIOOutput(PA4);

    xSPinTypeSPI(SPI1CLK(3),  PA5);
    xSPinTypeSPI(SPI1MOSI(3), PA7);
    xSPinTypeSPI(SPI1MISO(1), PA6);

    //
    // Configure MCU as a master device , 8 bits data width ,MSB first,Mode_0
    //
    xSPIConfigSet(xSPI1_BASE, 4000000, xSPI_MOTO_FORMAT_MODE_0 |
                                                xSPI_MODE_MASTER |
                                                xSPI_MSB_FIRST |
                                                xSPI_DATA_WIDTH8);
    xSPISSSet(xSPI1_BASE, xSPI_SS_SOFTWARE, xSPI_SS0);

    xSPIEnable(xSPI1_BASE);
}
Пример #20
0
void uartprinntf()
{
    //
    // Initionalize system clock.
    //
    xSysCtlPeripheralClockSourceSet( 10000000,  xSYSCTL_XTAL_6MHZ );
 
    SysCtlDelay(10000);

    xSPinTypeUART(UART0RX,PB0);
    xSPinTypeUART(UART0TX,PB1);

    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART0);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0);
    SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_UART_S_EXT12M);

    //
    // Config 8 bit word length, 1 stop bit, 
    // and none parity bit, receive FIFO 1 byte.
    //
    UARTConfigSetExpClk(UART0_BASE, 115200, (UART_CONFIG_WLEN_8 | 
                                             UART_CONFIG_STOP_ONE | 
                                               UART_CONFIG_PAR_NONE));

    UARTEnable(UART0_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX));

    UARTBufferWrite(UART0_BASE, "NUC1xx.UART.BAUDRATE EXAMPLE \r\n", sizeof("NUC1xx.UART.BAUDRATE EXAMPLE \r\n")); 
}
Пример #21
0
//*****************************************************************************
//
//! \brief Initialize  24LC64 and I2C
//!
//! \param None
//!
//! This function initialize the mcu I2C as master and specified I2C port.the 
//! master block will be set up to transfer data at 400 kbps.
//! 
//! \return None.
//
//*****************************************************************************
void _24LC64_Init(void)
{
    //
    // Enable GPIO Periph clock and Alternate Fuction I/O clock.
    //  
    xSysCtlPeripheralEnable(_24LC64_I2C_GPIO);
    //
    // Enable the I2C which is connected with _24LC64_
    //
    xSysCtlPeripheralEnable2(_24LC64_I2C_PORT);
    //
    // Set _24LC64_PIN_I2C_SCK as IICx.SCK
    //
    xSPinTypeI2C(_24LC64_I2C_SCK, _24LC64_PIN_I2C_SCK);
    //
    // Set _24LC64_PIN_I2C_SDA as I2Cx.SDA
    //
    xSPinTypeI2C(_24LC64_I2C_SDA, _24LC64_PIN_I2C_SDA);

    //
    // Initializes the I2C Master block.
    //
    xI2CMasterInit(_24LC64_I2C_PORT, I2C_Speed);

}
Пример #22
0
void pwmInit(){
	xSysCtlPeripheralClockSourceSet(xSYSCTL_PWMA_HCLK, 1);
	xSysCtlPeripheralEnable(SYSCTL_PERIPH_PWMA);
	xSysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	xSPinTypePWM(TIM0CH0, PB11);
	xSPinTypePWM(TIM0CH1, PB10);

	xPWMInitConfigure(xPWMA_BASE, xPWM_CHANNEL0, xPWM_TOGGLE_MODE);
	xPWMInitConfigure(xPWMA_BASE, xPWM_CHANNEL1, xPWM_TOGGLE_MODE);
	xPWMFrequencySet(xPWMA_BASE, xPWM_CHANNEL0, 50);
	xPWMDutySetPrec(xPWMA_BASE, xPWM_CHANNEL0, 750);
	xPWMOutputEnable(xPWMA_BASE, xPWM_CHANNEL0);
	xPWMStart(xPWMA_BASE, xPWM_CHANNEL1);
	xPWMFrequencySet(xPWMA_BASE, xPWM_CHANNEL1, 50);
	xPWMDutySetPrec(xPWMA_BASE, xPWM_CHANNEL1, 750 + STEER_OFFSET);
	xPWMOutputEnable(xPWMA_BASE, xPWM_CHANNEL1);
	xPWMStart(xPWMA_BASE, xPWM_CHANNEL1);
}
Пример #23
0
//*****************************************************************************
//
//! The main function of the i2c slave receive with poll mode
//
//! return none
//
//*****************************************************************************
void SlaveReceivePoll(void)
{
    
    //
    // Congigure the i2c pin
    //
     xSPinTypeI2C(I2C0SCK, PA11);
     xSPinTypeI2C(I2C0DATA, PA10);
    
    //
    // Enable the i2c peripheral
    //
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_I2C0);
    
    //
    // Init the I2C as slave 
    //
    I2CSlaveInit(I2C0_BASE, SlaveAddress, I2C_GENERAL_CALL_DIS);
    
    //
    // Install the i2c0 interrupt service function
    //
   // I2CIntCallbackInit(I2C0_BASE, ( xtEventCallback)SlavaRecvFunc);
    
    WriteBuf[8] = '\0';
    //
    // I2C master transfer config
    //
    I2CSlaveRcCfg.pvWBuf = WriteBuf;
    I2CSlaveRcCfg.ulWLen = WriteLength;
    I2CSlaveRcCfg.ulWCount = 0;
    I2CSlaveRcCfg.pvRBuf = ReceiveBuf;
    I2CSlaveRcCfg.ulRLen = ReceiveLength;
    //I2CSlaveRcCfg.pvRBuf = 0;
    //I2CSlaveRcCfg.ulRLen = 0;
    I2CSlaveRcCfg.ulRCount = 0;
    
    //
    // UART initialize
    //
    UART0Configuration();    
    xI2CIntCallbackInit(I2C0_BASE, SlavaRecvFunc);
    
    //
    // I2C salve receive wiht pollint mode
    //
    I2CSlaveTransfer(I2C0_BASE, &I2CSlaveRcCfg, I2C_TRANSFER_POLLING);
    
    //
    // Print the receive data form the master
    //
    while(1)
    {

    }
    
}
Пример #24
0
//*****************************************************************************
//
//! \brief something should do before the test execute of xpwm002 test.
//!
//! \return None.
//
//*****************************************************************************
static void xpwm002Setup(void)
{
    SysCtlKeyAddrUnlock();  
    xSysCtlClockSet(12000000, xSYSCTL_XTAL_12MHZ | xSYSCTL_OSC_MAIN);
   
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_PWMA);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_PWMB);
    
    //
    // GPIO pin function set as pwm output
    //
    xSPinTypePWM(PWM0, PA12);    
    xSPinTypePWM(PWM1, PA13); 
    xSPinTypePWM(PWM2, PA14); 
    xSPinTypePWM(PWM3, PA15); 
    xSPinTypePWM(PWM4, PB11); 
    xSPinTypePWM(PWM5, PE5); 
    xSPinTypePWM(PWM6, PE0); 
    xSPinTypePWM(PWM7, PE1);     
}
Пример #25
0
//*****************************************************************************
//
//! \brief something should do before the test execute of xi2c001 test.
//!
//! \return None.
//
//*****************************************************************************
static void xI2C001Setup(void)
{      
    xSysCtlPeripheralEnable2(ulMaster);

    xSysCtlPeripheralEnable2(xGPIO_PORTD_BASE);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    
    xSPinTypeI2C(I2C0SCK, PD12);
    xSPinTypeI2C(I2C0SDA, PD13);
    
}
Пример #26
0
//*****************************************************************************
//
//! \brief Initialize STMPE811 and I2C  
//!
//! \param None
//!
//! This function initialize the mcu I2C as master and specified I2C port.the 
//! master block will be set up to transfer data at 400 kbps.
//! 
//! \return None.
//
//*****************************************************************************
void STMPE811Init(void)
{
    //
    // Enable GPIO Periph clock and Alternate Fuction I/O clock.
    //  
    xSysCtlPeripheralEnable(STMPE811_I2C_GPIO);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    //
    // Enable the I2C which is connected with STMPE811
    //
    xSysCtlPeripheralEnable2(STMPE811_PIN_I2C_PORT);   
    //
    // Set STMPE811_PIN_I2C_SCK as IICx.SCK
    //
    xSPinTypeI2C(STMPE811_I2C_SCK, STMPE811_PIN_I2C_SCK);   
    //
    // Set STMPE811_PIN_I2C_SDA as I2Cx.SDA
    //
    xSPinTypeI2C(STMPE811_I2C_SDA, STMPE811_PIN_I2C_SDA);  
    //
    // I2C enable
    //
    xI2CMasterEnable(STMPE811_PIN_I2C_PORT);
    //
    // Initializes the I2C Master block.
    //
    xI2CMasterInit(STMPE811_PIN_I2C_PORT, I2C_Speed);
    //
    // Set INT pin.
    //
    xGPIODirModeSet(STMPE811_INT_PORT, STMPE811_INT_GPIO, xGPIO_DIR_MODE_IN);
    //
    // Set GPIO pin interrupt callback.
    //
    xGPIOPinIntCallbackInit(STMPE811_INT_PORT, STMPE811_INT_GPIO, STMPE811IntCallback);
    //  Enable GPIO pin interrupt.
    xGPIOPinIntEnable(STMPE811_INT_PORT, STMPE811_INT_GPIO, xGPIO_FALLING_EDGE);
    xIntEnable(INT_GPIO);
    // STNPE811 initializtion.
    STMPE811InitConfig();     
}
Пример #27
0
//////////////////////////////////////////////////////////////////////////////
// Platform (STM32F103X) initialization for peripherals as GPIO, SPI, UARTs //
//////////////////////////////////////////////////////////////////////////////
void platform_init(void)
{
    xSysCtlClockSet(72000000,  xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);

    xSysCtlDelay((xSysCtlClockGet()/1000)*50); // wait 50ms


    /**************************/
    /* GPIO_A For SPI CS PIN  */// It must be first to enable GPIO peripheral than other peripheral. (Otherwise, UART do not run in STM32F103X)
    /**************************/
    xSysCtlPeripheralEnable( xSYSCTL_PERIPH_GPIOA );
    xGPIODirModeSet(xGPIO_PORTA_BASE, xGPIO_PIN_4, xGPIO_DIR_MODE_OUT);


    /************/
    /* For UART */
    /************/
    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART1);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART1);
    xSPinTypeUART(UART1TX,PA9);
    xSPinTypeUART(UART1RX,PA10);
    xUARTConfigSet(xUART1_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    xUARTEnable(xUART1_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX));


    /***********/
    /* For SPI */
    /***********/
    xSysCtlPeripheralReset(WIZCHIP_SPI_PERIPH);
    xSysCtlPeripheralEnable(WIZCHIP_SPI_PERIPH);
    xSPinTypeSPI(WIZCHIP_SPI_CLK, WIZCHIP_SPI_CLK_PIN);  // xGPIODirModeSet(xGPIO_PORTA, xGPIO_PIN_5, GPIO_TYPE_AFOUT_STD, GPIO_OUT_SPEED_50M);
    xSPinTypeSPI(WIZCHIP_SPI_MOSI,WIZCHIP_SPI_MOSI_PIN);  // xGPIODirModeSet(xGPIO_PORTA, xGPIO_PIN_7, GPIO_TYPE_AFOUT_STD, GPIO_OUT_SPEED_50M);
    xSPinTypeSPI(WIZCHIP_SPI_MISO,WIZCHIP_SPI_MISO_PIN);  // xGPIODirModeSet(xGPIO_PORTA, xGPIO_PIN_6, GPIO_TYPE_IN_FLOATING, GPIO_IN_SPEED_FIXED);
    xSPIConfigSet(WIZCHIP_SPI_BASE, xSysCtlClockGet()/2, xSPI_MOTO_FORMAT_MODE_0 | xSPI_MODE_MASTER | xSPI_MSB_FIRST | xSPI_DATA_WIDTH8);

    xSPISSSet(WIZCHIP_SPI_BASE, SPI_SS_SOFTWARE, xSPI_SS_NONE);
    xSPIEnable(WIZCHIP_SPI_BASE);

    printf("HCLK = %dMHz\r\n", (unsigned int)(xSysCtlClockGet()/1000000));
}
Пример #28
0
//*****************************************************************************
//
//! \brief PWM output function example.
//!
//! \return None.
//
//*****************************************************************************
void PWM_Output()
{
    //
    // Initionalize system clock and I/O port.
    //
    IOInit();

    PrintLine( "*** Cox PWM example ***" );

    //
    // Set GPIO Pin as PWM and enable PWM
    //
    xSPinTypePWM(PWM2, PA14);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_PWMA);

    //
    // Set invert, dead zone and mode
    //
    xPWMInitConfigure(xPWMA_BASE, xPWM_CHANNEL2, xPWM_TOGGLE_MODE |
                      xPWM_OUTPUT_INVERTER_DIS | xPWM_DEAD_ZONE_DIS );

    // Set CNR, Prescale and Divider
    xPWMFrequencyConfig(xPWMA_BASE, xPWM_CHANNEL2, 0x3FF1111);

    //
    // Set CMR
    //
    xPWMDutySet(xPWMA_BASE, xPWM_CHANNEL2, 40);

    //
    // Set output enable
    //
    xPWMOutputEnable(xPWMA_BASE, xPWM_CHANNEL2);

    // Set interrupt call back
    xPWMIntCallbackInit(xPWMA_BASE, user_Callback);

    //
    // PWM output interrupt enable
    //
    xPWMIntEnable(xPWMA_BASE, xPWM_CHANNEL2, xPWM_INT_PWM);

    //
    // NVIC interrupt enable
    //
    xIntEnable(xINT_PWMA);

    //
    // start pwm
    //
    xPWMStart(xPWMA_BASE, xPWM_CHANNEL2);
}
Пример #29
0
void 
TestIOInit(void)
{
    xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);

    SysCtlDelay(10000);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);
    //xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);

    //xSPinTypeUART(UART1RX,PA10);
    xSPinTypeUART(UART1TX,PA9);
    

    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART1);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART1);
    //SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_UART_S_EXT12M);

    xUARTConfigSet(USART1_BASE, 115200, (UART_CONFIG_WLEN_8 |
                                         UART_CONFIG_STOP_ONE | 
                                         UART_CONFIG_PAR_NONE));

    xUARTEnable(USART1_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX));
}
Пример #30
0
//*****************************************************************************
//
//! \brief Init uart to print.
//!
//! \param None
//!
//! \details uart config as (115200, 8 data bit, 1 stop bit , no partiy)
//!
//! \return None.
//
//*****************************************************************************
static 
void UartInit(void)
{
    xSPinTypeUART(UART0RX,PB0);
    xSPinTypeUART(UART0TX,PB1);

    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART0);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0);
    
    xSysCtlPeripheralClockSourceSet(xSYSCTL_UART0_MAIN, 1);

    xUARTConfigSet(UART0_BASE, 115200, (UART_CONFIG_WLEN_8 |
                                        UART_CONFIG_STOP_ONE | 
                                        UART_CONFIG_PAR_NONE));
}