示例#1
0
文件: main.c 项目: oldjohnh/car
int main(void)
{
		UART_InitTypeDef UART_InitStruct1; 
		UART_InitStruct1.UARTxMAP= UART0_RX_PA14_TX_PA15; 
		UART_InitStruct1.UART_BaudRate=115200;
		UART_Init(&UART_InitStruct1);
		UART_ITConfig(UART0,UART_IT_RDRF, ENABLE);
	  NVIC_EnableIRQ(UART0_RX_TX_IRQn);	
		OLED_Init();
	while(1){
		//UART_SendData(UART0,1);
		//OLED_Write_Char(2,2,ch);
		//UART_SendData(UART0,'x');
		//UART_Send_String(UART0,"abcdefg");
	}
}
int main(void)
{
	DDRA = 0x01;
	DDRD = 0x02;
	UART_Init();
	unsigned char data = 0x1E;
	
    while(1)
    {
		PORTA |= (1 << PA0);
		//_delay_ms(100);
		//UART_Transmit(data);
		PORTA &= ~(1 << PA0);
		//_delay_ms(100);
	}
}
示例#3
0
void main()
{
	lcd_init();
	lcd_pos(0, 0);
	lcd_write_string("Ξ�½ΠΑυξΘ£Ί1234‘ζ");
	UART_Init();
	while (1) 
	{
		LED_ON();
		delay_ms(100);
		LED_OFF();
		delay_ms(100);
		SendData('b');
		SendData('\n');
	}
}
int main()
{
	PORT_Init();
	UART_Init(19200);
	while (1)
	{
		PrintWelcome();

		while (1)
		{
			AcceptCommands();
			EvaluateStatus(UPDATE_ONLY_ON_CHANGE);
		}			
	}
	return 0;
}
示例#5
0
int main(void)
{
	UART_Init();
	microrl_terminalInit();
	LoggerHAL_Init();
	CommandLine_Init();
	logger_Test();

	Led_t greenLed;
	Led_Init(&greenLed, GPIOC, GPIO_Pin_9);
	Led_SetState(&greenLed, led_on);
    while(1)
    {
    	microrl_terminalProcess();
    }
}
示例#6
0
文件: main.cpp 项目: Kreyl/nute
// ============================ Implementation ================================
int main(void) {
    UART_Init();
    Delay.ms(100);
    klPrintf("Helm is up to sing\r");

    GeneralInit();
    uint32_t tmr;
    Delay.Reset(&tmr);
    // ==== Main cycle ====
    while(1) {
        ESnd.Task();
        Detector.Task();
        //if (Delay.Elapsed(&tmr, 2000)) EVENT_SomeoneDetected();
    } // while(1)
    return 0;
}
示例#7
0
int32_t main (void)
{
    uint8_t Tx_Data[6];
    uint8_t Rx_Data[6];

    /* Init System, IP clock and multi-function I/O */
    SYS_Init();

    /* Init UART for printf */
    UART_Init();

    printf("+-------------------------------------------------------+\n");
    printf("|    Software I2C sample code                           |\n");
    printf("|    SW Master                                          |\n");
    printf("|    HW Slave                                           |\n");
    printf("+-------------------------------------------------------+\n");

    printf("Initiate I2C for slave\n");
    InitI2C_HW();

    printf("Initiate software I2C for Master\n");
    I2C_SW_Open(100000);

    printf("Please connect:\n");
    printf("SW SDA - P1.4 (PIN47)  <->   HW SDA - P3.4 (PIN9) \n");
    printf("SW SCL - P1.5 (PIN2)   <->   HW SCL - P3.5 (PIN10) \n");

    Tx_Data[0]=0;
    Tx_Data[1]=0;
    Tx_Data[2]=0xA5;
    Tx_Data[3]=0xcc;
    Tx_Data[4]=0xbb;
    Tx_Data[5]=0xdd;

    printf("Access I2C slave:\n");

    I2C_SW_Send(0x15,Tx_Data,6);
    CLK_SysTickDelay(5000);
    I2C_SW_Get(0x15,Rx_Data,4);

    if((Rx_Data[0] != 0xaa) || (Rx_Data[1] != 0x22) || (Rx_Data[2] != 0x33) || (Rx_Data[3] != 0x44))
        printf("Data Error!!\n");
    else
        printf("Pass!!\n");

    return 0;
}
int main() 
{
    int adcValue;
    float volt;
    
    ADC_Init();       /* Initialize the ADC module */
    UART_Init(9600);  /* Initialize UART at 9600 baud rate */
    
    while(1)
    {
        adcValue = ADC_GetAdcValue(0); // Read the ADC value of channel zero
        volt = (adcValue*5.00)/1023;
        UART_Printf("ADC0 Value:%4d  Equivalent Voltage:%f\n\r",adcValue,volt);     // Send the value on UART
    }
    
    return (0);
}
示例#9
0
int main(void)
{
    uint32_t u32DataCount;

    /* Init System, IP clock and multi-function I/O */
    SYS_Init();

    /* Init UART for printf */
    UART_Init();

    /* Init SPI */
    SPI_Init();

    printf("\n\n");
    printf("+----------------------------------------------------------------------+\n");
    printf("|                       SPI Driver Sample Code                         |\n");
    printf("+----------------------------------------------------------------------+\n");
    printf("\n");

    printf("Configure SPI as a slave.\n");

    for(u32DataCount=0; u32DataCount<TEST_COUNT; u32DataCount++)
    {
        g_au32SourceData[u32DataCount] = 0x00550000 + u32DataCount;
        g_au32DestinationData[u32DataCount] = 0;
    }

    SPI->CNTRL |= SPI_CNTRL_FIFO_Msk;
    SPI->FIFO_CTL |= (SPI_FIFO_CTL_RX_INTEN_Msk | SPI_FIFO_CTL_TX_INTEN_Msk);
    SPI->FIFO_CTL = (SPI->FIFO_CTL & ~(SPI_FIFO_CTL_TX_THRESHOLD_Msk | SPI_FIFO_CTL_RX_THRESHOLD_Msk) |
                     (2 << SPI_FIFO_CTL_TX_THRESHOLD_Pos) |
                     (1 << SPI_FIFO_CTL_RX_THRESHOLD_Pos));
    NVIC_EnableIRQ(SPI_IRQn);

    while(!g_u8Done);

    printf("Received data:\n");
    for(u32DataCount=0; u32DataCount<TEST_COUNT; u32DataCount++)
    {
        printf("%d:\t0x%08X\n", u32DataCount, g_au32DestinationData[u32DataCount]);
    }

    printf("The data transfer was done.\n");

    while(1);
}
示例#10
0
/**
  @brief UART, SPI, I2C, GPIO initialization

  @return none

**/
void Test_Init(void)
{

   if(FUNCTION_TO_TEST == SPI) { /* Check if SPI is tested */
      SPI_Init();         /* SPI initialization */

   } else if(FUNCTION_TO_TEST == UART) { /* Check if UART is tested */
      UART_Init(B9600, COMLCR_WLS_8BITS);    /* UART initialization: 9600 baud rate and 8 bits data */

   } else if(FUNCTION_TO_TEST == I2C) { /* Check if I2C is tested */
      I2C_Init();         /* I2C initialization */

   } else if(FUNCTION_TO_TEST == GPIO) { /* Check if GPIO is tested */
      Port_Init();
   }

}
示例#11
0
文件: uart_print.c 项目: coocox/Mplib
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");
}
示例#12
0
void XBeeInit(){
	char * commands [] = {"ATDL66", "ATDH0", "ATMY6D", "ATAP1", "ATCN", ""};
	int i = 0;
	int j;
	UART_Init();
	while (RxFifo_Size()>0){ //flush FIFO
		UART_InChar();
	}

		ID = 1;
  UART_OutString("x");
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
	 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);	 //SysTick_Wait10ms(110);		//wait waitTime number of ms;
	sendATCommand("+++", 110, 0);
	//UART_InString(response, 5);
	//RIT128x96x4StringDraw(response, 10, 10 , 15);
	
	for (i=0;i<5;i++){
		sendATCommand(commands[i], 20, 1);
	}
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
	 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10); }
示例#13
0
文件: main.c 项目: liulvcong/EE445L
int main(void){ 
  PLL_Init(Bus80MHz); 	// 80 MHz
  UART_Init();      		// initialize UART device
	//initialize ADC, hardware timer trigger, 100Hz sampling
	ADC0_InitTimer0ATriggerSeq3PD3(f100HZ);  
	TxFifo_Init();	// initialize FIFO
	ST7735_InitR(INITR_REDTAB); // initialize LCD
	ST7735_InitTemperatureGraph();	// initialize graph area
	
	EnableInterrupts();

	while(1){
		TxFifo_Get(&adcValue);	// get most recent ADC value from FIFO
		ST7735_UpdateTemperatureGraph(numSamples, adcValue); // plot new point and display ADC and temperature values
    numSamples++;                       // counts the number of samples
	}
}
示例#14
0
文件: comm.c 项目: chalot/360
int main(int argc, char **argv)
{
	int serial_fd = 0;

    UART_Init();

    char buf[]="hello world";
    char buf1[10];
    UART_Send(serial_fd, buf, 10);
    printf("\n");

    UART_Recv(serial_fd, buf1, 10);

    printf("uart receive %s\n", buf1);
    close(serial_fd);
    return 0;
}
示例#15
0
文件: ublox.c 项目: ctraabe/NaviCtrl
// -----------------------------------------------------------------------------
static void UART1Init(uint32_t baud_rate)
{
  UART_InitTypeDef uart_init;

  uart_init.UART_WordLength = UART_WordLength_8D;
  uart_init.UART_StopBits = UART_StopBits_1;
  uart_init.UART_Parity = UART_Parity_No ;
  uart_init.UART_BaudRate = baud_rate;
  uart_init.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
  uart_init.UART_Mode = UART_Mode_Tx_Rx;
  uart_init.UART_FIFO = UART_FIFO_Enable;
  uart_init.UART_TxFIFOLevel = UART_FIFOLevel_1_4;
  uart_init.UART_RxFIFOLevel = UART_FIFOLevel_3_4;
  UART_DeInit(UART0);
  UART_Init(UART0, &uart_init);
  UART_Cmd(UART0, ENABLE);
}
示例#16
0
/*
 * Configure the pins according to their intended default function
 */
int _roboveroConfig(uint8_t * args)
{
    int i;
    UART_CFG_Type UARTConfigStruct;
    PWM_TIMERCFG_Type PWMCfgDat;

    configAllPins();

    /*
     * Enable 7 analog inputs
     */
    ADC_Init(LPC_ADC, 200000);
    for (i = 0; i < 4; i++)
    		ADC_ChannelCmd(LPC_ADC, i, ENABLE); 
    for (i = 5; i < 8; i++)
        ADC_ChannelCmd(LPC_ADC, i, ENABLE);
    /*
     * Configure I2C0 for IMU communications
     */
    I2C_Init(LPC_I2C0, 100000);
    I2C_Cmd(LPC_I2C0, ENABLE);

    /*
     * Initialize CAN bus
     */
    CAN_Init(LPC_CAN1, 100000);

    /*
     * Initialize UART1 
     */
    UART_ConfigStructInit(&UARTConfigStruct);
    UARTConfigStruct.Baud_rate = 115200;
    UART_Init((LPC_UART_TypeDef*)LPC_UART1, &UARTConfigStruct);
    UART_TxCmd((LPC_UART_TypeDef*)LPC_UART1, ENABLE);

    /*
     * Initialize PWM
     *
     * Peripheral clock is 30MHz. Prescale by 30 cycles for 1us resolution.
     */    
    PWMCfgDat.PrescaleOption = PWM_TIMER_PRESCALE_TICKVAL;
    PWMCfgDat.PrescaleValue = 30;
    PWM_Init(LPC_PWM1, PWM_MODE_TIMER, &PWMCfgDat);

    return 0;
}
示例#17
0
文件: main.c 项目: kasparwu/Mini51
int32_t main (void)
{
    uint8_t Tx_Data[6];
    
    /* Init System, IP clock and multi-function I/O */
    SYS_Init();

    /* Init UART for printf */
    UART_Init();
    
    printf("+-------------------------------------------------------+\n");
    printf("|    Software I2C sample code                           |\n");
    printf("|    SW Master -> I2C EEPROM                            |\n");
    printf("+-------------------------------------------------------+\n");

    I2C_SW_I_Open(50000);
    Tx_Data[0]=0;
    Tx_Data[1]=0;
    Tx_Data[2]=0xAA;
    Tx_Data[3]=0xBB;
    Tx_Data[4]=0x55;
    Tx_Data[5]=0xCC;

    printf("Write data into EEPROM\n");
    printf("Data:0x%x,0x%x,0x%x,0x%x\n",Tx_Data[2],Tx_Data[3],Tx_Data[4],Tx_Data[5] );
    I2C_SW_I_Send(0x50,Tx_Data,6);
    while(I2C_SW_I_IsBZ());
    if(I2C_SW_I_Count()!=6)
        while(1);
    CLK_SysTickDelay(5000);

    printf("Write address into EEPROM\n");
    I2C_SW_I_Send(0x50,Tx_Data,2);
    while(I2C_SW_I_IsBZ());
    if(I2C_SW_I_Count()!=2)
        while(1);
        
    printf("Read data form EEPROM\n");        
    I2C_SW_I_Get(0x50,Tx_Data,4);
    while(I2C_SW_I_IsBZ());
    printf("Data:0x%x,0x%x,0x%x,0x%x\n",Tx_Data[0],Tx_Data[1],Tx_Data[2],Tx_Data[3] );
    if(I2C_SW_I_Count()!=4)
        while(1);
    while(1);
}
uint8_t UART_QuickInit(uint32_t MAP, uint32_t baudrate)
{
    uint8_t i;
    uint32_t clock;
    UART_InitTypeDef UART_InitStruct1;
    QuickInit_Type * pq = (QuickInit_Type*)&(MAP);
    UART_InitStruct1.baudrate = baudrate;
    UART_InitStruct1.instance = pq->ip_instance;
    
    /* clock source */
    if(pq->ip_instance == HW_UART0)
    {
        CLOCK_GetClockFrequency(kMCGOutClock, &clock);
        
        /* use PLL/2 or FLL */
        SIM->SOPT2 &= ~SIM_SOPT2_UART0SRC_MASK;
        SIM->SOPT2 |= SIM_SOPT2_UART0SRC(1);  
	
        if(MCG->C6 & MCG_C6_PLLS_MASK) /* PLL */
        {
            SIM->SOPT2 |= SIM_SOPT2_PLLFLLSEL_MASK;
            clock /= 2;
        }
        else /* FLL */
        {
            SIM->SOPT2 &= ~SIM_SOPT2_PLLFLLSEL_MASK;
        }
    }
    else
    {
        CLOCK_GetClockFrequency(kBusClock, &clock);
    }
    UART_InitStruct1.srcClock = clock;
    
    /* init pinmux */
    for(i = 0; i < pq->io_offset; i++)
    {
        PORT_PinMuxConfig(pq->io_instance, pq->io_base + i, (PORT_PinMux_Type) pq->mux); 
    }
    
    /* init UART */
    UART_Init(&UART_InitStruct1);
    
    return pq->ip_instance;
}
示例#19
0
static void uart3_init(rt_uint32_t baudrate)
{
	PINSEL_CFG_Type PinSelCfgType;

	UART_CFG_Type UartCfgType;

	UART_FIFO_CFG_Type UartFIFOCfgType;

	//pin config
	//TXD
	PinSelCfgType.Portnum = PINSEL_PORT_0;
	PinSelCfgType.Pinnum  = PINSEL_PIN_0;
	PinSelCfgType.Funcnum = PINSEL_FUNC_2;
	PinSelCfgType.Pinmode = PINSEL_PINMODE_PULLUP;
	PinSelCfgType.OpenDrain = PINSEL_PINMODE_NORMAL;
	PINSEL_ConfigPin(&PinSelCfgType);

	//RXD
	PinSelCfgType.Portnum = PINSEL_PORT_0;
	PinSelCfgType.Pinnum  = PINSEL_PIN_1;
	PinSelCfgType.Funcnum = PINSEL_FUNC_2;
	PinSelCfgType.Pinmode = PINSEL_PINMODE_TRISTATE;
	PinSelCfgType.OpenDrain = PINSEL_PINMODE_NORMAL;
	PINSEL_ConfigPin(&PinSelCfgType);

	//init
	UartCfgType.Baud_rate = baudrate;
	UartCfgType.Parity    = UART_PARITY_NONE;
	UartCfgType.Databits  = UART_DATABIT_8;
	UartCfgType.Stopbits  = UART_STOPBIT_1;
	UART_Init(LPC_DEV_UART, &UartCfgType);

	//FIFO
	UartFIFOCfgType.FIFO_ResetRxBuf = ENABLE;
	UartFIFOCfgType.FIFO_ResetTxBuf = ENABLE;
	UartFIFOCfgType.FIFO_DMAMode    = DISABLE;
	UartFIFOCfgType.FIFO_Level      = UART_FIFO_TRGLEV2;
	UART_FIFOConfig(LPC_DEV_UART, &UartFIFOCfgType);

	//int
	UART_IntConfig(LPC_DEV_UART, UART_INTCFG_RBR, ENABLE);

	//enable
	UART_TxCmd(LPC_DEV_UART, ENABLE);
}
示例#20
0
/******************************************************************************
 *
 * Description:
 *   Initialize the console (UART connected to USB-to-UART bridge)
 *
 *****************************************************************************/
void console_init(void)
{
  // UART Configuration structure variable
	UART_CFG_Type UARTConfigStruct;

  // pinsel for UART
	PINSEL_ConfigPin(0,2,1);
	PINSEL_ConfigPin(0,3,1);

	UART_ConfigStructInit(&UARTConfigStruct);
  UARTConfigStruct.Baud_rate = 115200;

	// Initialize UART0 peripheral with given to corresponding parameter
	UART_Init(CONSOLE_DEV, &UARTConfigStruct);

	// Enable UART Transmit
	UART_TxCmd(CONSOLE_DEV, ENABLE);
}
示例#21
0
void main(void)
{
	// init UART and send initial 'AT' to the BlueCore
	UART_Init();
	UART_SendByte('A');
	UART_SendByte('T');
	UART_SendByte('\n');

	while (TRUE) {
		uint8_t byte  = ReadADC();
		uint8_t digit = byte/100;
		while (UART_SendByte(digit + '0'));
		digit = (byte%100)/10;
		while (UART_SendByte(digit + '0'));
		while (UART_SendByte(byte%10 + '0'));
		while (UART_SendByte(' '));								   
	}
}
示例#22
0
文件: gps.c 项目: Feyre/345Final
void GPS_init(struct GPS_info_struct *GPS_data)
{
	UART_Init();
	// Initialise the UART protocol to the teensy

	DDRB = 0x0C;	// Same as 0b00001100 - declare Register B for use with LEDs
	PORTB = 0x00;	// Turn off all LEDs on Register B

	GPS_data->current_datetime.time_hour = 0, GPS_data->current_datetime.time_minute = 0, GPS_data->current_datetime.time_sec = 0;
	GPS_data->pos.lat_deg = 0, GPS_data->pos.lat_min = 0;
	GPS_data->pos.long_deg = 0, GPS_data->pos.long_min = 0;
	GPS_data->knot_spd = 0;
	GPS_data->current_datetime.date_day = 0, GPS_data->current_datetime.date_month = 0, GPS_data->current_datetime.date_year = 0;
	GPS_data->knot_spd = 0; // only reset speed
	GPS_data->kmh_spd = 0;
	GPS_data->cog_T = 0;
	GPS_data->cog_M = 0;
}
示例#23
0
int main(void)
{
	InitLEDs();
	SetGreenLED();

	wdt_enable(WDTO_250MS);

	UART_Init();
	Cmd_InitInterface();
	RegisterAppCommands();
	sei();                    // enable interrupts

	while(true)
	{
		wdt_reset();
		Cmd_ProcessInterface();
	}
}
示例#24
0
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void setupHardware(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);
	UART_Init(115200);

	LEDs_Init();
    blink_Leds(10,80);

    // UART_Print("AsTeRICS HID actuator ready!\r\n");
    blink_Leds(20,40);

	USB_Init();
}
int main()
{		
	PLL_Init();                       // 80 MHz system clock
	SysTick_Init(80);                 // 1 us SysTick periodic interrupts 
	PWM_Init();                       // Initialize PF1,PF2 and PF3 for PWM operation
	MotorInput_Init();                // Initialize motor inputs for 3 motors
	UART_Init();                      // Initialize UART4	with 115200 baud rate
	EdgeInterrupts_Init();            // Initialize all available edge interrupts 
  PID_Init(5, 0, 100, 200000);  // Initialize PID s by setting all the PID constants
	OmniControl_Init();               // Timer initializations for PID loops
	Ultrasonic1_Init();               // Intitialize HC-SR04 ultrasonic sensor1
	Ultrasonic2_Init();               // Intitialize HC-SR04 ultrasonic sensor2

	while(1)
	{
	
	}	 
}
示例#26
0
/**
  * @brief
  * @param	None
  * @retval	None
  */
void DebugUARTInit()
{
	UART_InitTypeDef UART_InitStructure;
	uint32_t BaudRateStatus;
#if defined (USE_MDR1986VE3)
	RST_CLK_PCLKcmd((RST_CLK_PCLK_PORTD | RST_CLK_PCLK_UART2), ENABLE);
#elif defined (USE_MDR1986VE9x)
	RST_CLK_PCLKcmd((RST_CLK_PCLK_PORTF | RST_CLK_PCLK_UART2), ENABLE);
#elif defined (USE_MDR1986VE1T)
	RST_CLK_PCLKcmd((RST_CLK_PCLK_PORTC | RST_CLK_PCLK_UART1), ENABLE);
#endif

	/* Port Init Struture */
	PORT_InitStructure.PORT_Pin = DEBUG_UART_PINS;
	PORT_InitStructure.PORT_FUNC = DEBUG_UART_PINS_FUNCTION;
	PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL;
	PORT_InitStructure.PORT_SPEED = PORT_SPEED_MAXFAST;
	PORT_InitStructure.PORT_PD = PORT_PD_DRIVER;

	PORT_Init(DEBUG_UART_PORT, &PORT_InitStructure);

	UART_DeInit(DEBUG_UART);

  	/* UART	Init Structure */
	UART_InitStructure.UART_BaudRate            = DEBUG_BAUD_RATE;
	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 );

	/* ----- Инициализация UART ----- */
	UART_BRGInit(DEBUG_UART, UART_HCLKdiv1);
        BaudRateStatus = UART_Init(DEBUG_UART, &UART_InitStructure);
	if(BaudRateStatus == BaudRateValid){
		UART_Cmd(DEBUG_UART,ENABLE);
	}
	else{
		while(1);
	}
	DEBUG_PRINTF("==============System startup==============\n\r");
	DEBUG_PRINTF("Init Debug UART ... Ok\r\n");
}
示例#27
0
int main(int argc, char **argv)
{
    int fd = FALSE;
    int ret;
    char rcv_buf[512];
	char send_buf[512];
    int i;
    if(argc != 2){
	    printf("Usage: %s /dev/ttySn \n",argv[0]);
	    return FALSE;
    }
    fd = UART_Open(fd,argv[1]);
    if(FALSE == fd){
	    printf("open error\n");
	    exit(1);
    }
    ret  = UART_Init(fd,9600,0,8,1,'N');
    if (FALSE == fd){
	    printf("Set Port Error\n");
	    exit(1);
    }
    strcpy(send_buf,"ff0161\n");
    ret  = UART_Send(fd,send_buf,strlen(send_buf));
    if(FALSE == ret){
	    printf("write error!\n");
	    exit(1);
    }
    printf("command: %s\n",send_buf);
    memset(rcv_buf,0,sizeof(rcv_buf));
    for(i=0;;i++)
    {
	    ret = UART_Recv(fd, rcv_buf,512);
    	if( ret > 0){
	    	rcv_buf[ret]='\0';
	    	printf("%s",rcv_buf);
	    } else {
	    	printf("cannot receive data1\n");
            //break;
	    }
	  	if('\n' == rcv_buf[ret-1]) break;
    }
    UART_Close(fd);
    return 0;
}
示例#28
0
static void uart_regs_init(uint8_t id)
{
    uart_tab[id]->bit_len = SystemCoreClock / uart_tab[id]->config.Baud_rate;
    UART_DeInit(uart_tab[id]->uart);
    UART_Init(uart_tab[id]->uart, &(uart_tab[id]->config));
    ///////////////////////////////////////
    // init hardware fifo

	// Initialize FIFO for UART0 peripheral
	UART_FIFO_CFG_Type UARTFIFOConfigStruct;
    UARTFIFOConfigStruct.FIFO_DMAMode = DISABLE;
    UARTFIFOConfigStruct.FIFO_Level = UART_FIFO_TRGLEV2;
    UARTFIFOConfigStruct.FIFO_ResetRxBuf = ENABLE;
    UARTFIFOConfigStruct.FIFO_ResetTxBuf = ENABLE;
    UART_FIFOConfig(uart_tab[id]->uart, &UARTFIFOConfigStruct);

    UART_TxCmd(uart_tab[id]->uart, ENABLE);          // enable transmit
    uart_tab[id]->uart->IER |= UART_IER_RBRINT_EN;   // enable rbr interrupt
    uart_tab[id]->uart->IER |= UART_IER_THREINT_EN;  // enable thre interrupt

	// Do not enable transmit interrupt here, since it is handled by
	// UART_Send() function, just to reset Tx Interrupt state for the
	// first time
	
    switch(id) {
        case 0:
            NVIC_SetPriority(UART0_IRQn, ((0x01<<3)|0x01)); // preemption = 1, sub-priority = 1
            NVIC_EnableIRQ(UART0_IRQn);                     // Enable Interrupt for UART0 channel
            break;
        case 1:
            NVIC_SetPriority(UART1_IRQn, ((0x01<<3)|0x01)); // preemption = 1, sub-priority = 1
            NVIC_EnableIRQ(UART1_IRQn);                     // Enable Interrupt for UART0 channel
            break;
        case 2:
            NVIC_SetPriority(UART2_IRQn, ((0x01<<3)|0x01)); // preemption = 1, sub-priority = 1
            NVIC_EnableIRQ(UART2_IRQn);                     // Enable Interrupt for UART0 channel
            break;
        case 3:
            NVIC_SetPriority(UART3_IRQn, ((0x01<<3)|0x01)); // preemption = 1, sub-priority = 1
            NVIC_EnableIRQ(UART3_IRQn);                     // Enable Interrupt for UART0 channel
        default:
            break;
    }
}
示例#29
0
u32 platform_uart_setup( unsigned id, u32 baud, int databits, int parity, int stopbits )
{
  UART_InitTypeDef UART_InitStructure;
  UART_TypeDef* p_uart = ( UART_TypeDef* )uarts[ id ];
    
  // Then configure UART parameters
  switch( databits )
  {
    case 5:
      UART_InitStructure.UART_WordLength = UART_WordLength_5D;
      break;      
    case 6:
      UART_InitStructure.UART_WordLength = UART_WordLength_6D;
      break;      
    case 7:
      UART_InitStructure.UART_WordLength = UART_WordLength_7D;
      break;      
    case 8:
      UART_InitStructure.UART_WordLength = UART_WordLength_8D;
      break;
  }
  if( stopbits == PLATFORM_UART_STOPBITS_1 )
    UART_InitStructure.UART_StopBits = UART_StopBits_1;    
  else
    UART_InitStructure.UART_StopBits = UART_StopBits_2;
  if( parity == PLATFORM_UART_PARITY_EVEN )
    UART_InitStructure.UART_Parity = UART_Parity_Even;
  else if( parity == PLATFORM_UART_PARITY_ODD )
    UART_InitStructure.UART_Parity = UART_Parity_Odd;
  else
    UART_InitStructure.UART_Parity = UART_Parity_No;
  UART_InitStructure.UART_BaudRate = baud;
  UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
  UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;
  UART_InitStructure.UART_FIFO = UART_FIFO_Enable;
  UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */
  UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */

  UART_DeInit( p_uart );
  UART_Init( p_uart , &UART_InitStructure );
  UART_Cmd( p_uart, ENABLE );
  
  return baud;
}
示例#30
0
文件: main.c 项目: 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);      
}