コード例 #1
0
ファイル: rs485.c プロジェクト: Counterfeiter/DMXDisplay
void rs485_init(void)
{
	
	ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_OUTPUT	| IOPORT_INIT_HIGH);
	ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_INPUT);
	
	ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 7), IOPORT_DIR_OUTPUT	| IOPORT_INIT_HIGH);
	ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 6), IOPORT_DIR_INPUT);
		
	//rs485 enable
	usart_rs232_options_t usart_opt;
	
	usart_opt.baudrate = 250000;
	usart_opt.charlength = USART_CHSIZE_8BIT_gc;
	usart_opt.paritytype = USART_PMODE_DISABLED_gc;
	usart_opt.stopbits = true;
	
	usart_init_rs232(&RS485_1_UART,&usart_opt);
	
	usart_set_rx_interrupt_level(&RS485_1_UART,USART_INT_LVL_HI);
	
	
	
	usart_init_rs232(&RS485_2_UART,&usart_opt);
	
	usart_set_rx_interrupt_level(&RS485_2_UART,USART_INT_LVL_HI);
}
コード例 #2
0
ファイル: main.c プロジェクト: InSoonPark/asf
static void reconfigure_console(uint32_t ul_mck, uint32_t ul_baudrate)
{
	sam_usart_opt_t uart_serial_options;
	
	uart_serial_options.baudrate = ul_baudrate,
	uart_serial_options.char_length = CONF_UART_CHAR_LENGTH,
	uart_serial_options.parity_type = US_MR_PAR_NO;
	uart_serial_options.stop_bits = CONF_UART_STOP_BITS,
	uart_serial_options.channel_mode= US_MR_CHMODE_NORMAL,
	uart_serial_options.irda_filter = 0,

	/* Configure PMC */
	flexcom_enable(CONF_FLEXCOM);
	flexcom_set_opmode(CONF_FLEXCOM, FLEXCOM_USART);

	/* Configure PIO */
	pio_configure_pin_group(CONF_UART_PIO, CONF_PINS_UART,
			CONF_PINS_UART_FLAGS);

	/* Configure UART */
	usart_init_rs232(CONF_UART, &uart_serial_options, ul_mck);
	/* Enable the receiver and transmitter. */
	usart_enable_tx(CONF_UART);
	usart_enable_rx(CONF_UART);
}
int
DeviceCharacterBufferedUsart0::implPortInit(void)
{
  setPortAddress(&AVR32_USART0);

  gpio_enable_module_pin(OS_CFGPIN_DEVICECHARACTERBUFFEREDUSART0_RX_PIN,
      OS_CFGINT_DEVICECHARACTERBUFFEREDUSART0_GPIO_FUNCTION);
  gpio_enable_module_pin(OS_CFGPIN_DEVICECHARACTERBUFFEREDUSART0_TX_PIN,
      OS_CFGINT_DEVICECHARACTERBUFFEREDUSART0_GPIO_FUNCTION);

  usart_options_t usartConfig;
#if defined(OS_INCLUDE_OSDEVICECHARACTER_SETBAUDRATE)
  if(m_baudRate == 0)
    m_baudRate = OS_CFGINT_DEVICECHARACTERBUFFEREDUSART0_BAUD_RATE;
  usartConfig.baudrate =m_baudRate;
#else
  usartConfig.baudrate = OS_CFGINT_DEVICECHARACTERBUFFEREDUSART0_BAUD_RATE;
#endif  /* defined(OS_INCLUDE_OSDEVICECHARACTER_SETBAUDRATE) */
  usartConfig.channelmode = USART_NORMAL_CHMODE;
  usartConfig.charlength = 8;
  usartConfig.paritytype = USART_NO_PARITY;
  usartConfig.stopbits = USART_1_STOPBIT;

  usart_init_rs232(&AVR32_USART0, &usartConfig, OS_CFGLONG_PBA_FREQUENCY_HZ);

  INTC_register_interrupt(DeviceCharacterBufferedUsart0::contextHandler,
      AVR32_USART0_IRQ, OS_CFGINT_DEVICECHARACTERBUFFEREDUSART0_IRQ_PRIORITY);

  // Enable the RX interrupt
  AVR32_USART0.ier = AVR32_USART_IER_RXRDY_MASK;

  // Do not enable TX interrupts

  return 0;
}
コード例 #4
0
/**
 *  \brief USART RS485 mode configuration.
 *
 *  Configure USART in RS485 mode, asynchronous, 8 bits, 1 stop bit,
 *  no parity, 256000 bauds and enable its transmitter and receiver.
 */
void configure_usart(void)
{
	const sam_usart_opt_t usart_console_settings = {
		BOARD_USART_BAUDRATE,
		US_MR_CHRL_8_BIT,
		US_MR_PAR_NO,
		US_MR_NBSTOP_1_BIT,
		US_MR_CHMODE_NORMAL,
		/* This field is only used in IrDA mode. */
		0
	};

	/* Enable the peripheral clock in the PMC. */
	sysclk_enable_peripheral_clock(BOARD_ID_USART);

	/* Configure USART in RS485 mode. */
//jsi 7feb16 we want rs232 not rs485 for our application	usart_init_rs485(BOARD_USART, &usart_console_settings,
//jsi 7feb16 we want rs232 not rs485 for our application			sysclk_get_cpu_hz());
			
	usart_init_rs232(BOARD_USART, &usart_console_settings, sysclk_get_cpu_hz());

	/* enable transmitter timeguard, 4 bit period delay. */
	usart_set_tx_timeguard(BOARD_USART, 4);

	/* Disable all the interrupts. */
	usart_disable_interrupt(BOARD_USART, ALL_INTERRUPT_MASK);

	/* Enable TX & RX function. */
	usart_enable_tx(BOARD_USART);
	usart_enable_rx(BOARD_USART);

	/* Configure and enable interrupt of USART. */
	NVIC_EnableIRQ(USART_IRQn);
}
コード例 #5
0
//! this function initializes the USART module at "EXAMPLE_USART_BAUDRATE" bauds
void dsp_debug_init(int fosc)
{
  static const gpio_map_t USART_GPIO_MAP =
  {
    {EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION},
    {EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION}
  };

  // Configuration structure for the USART module
  static const usart_options_t USART_OPTIONS =
  {
    // Baudrate
    .baudrate     = EXAMPLE_USART_BAUDRATE,
    // Number of bits per character
    .charlength   = EXAMPLE_USART_BITSPERCHAR,
    // Parity
    .paritytype   = EXAMPLE_USART_PARITY,
    // Stop bit
    .stopbits     = EXAMPLE_USART_STOPBIT,
    // Mode normal
    .channelmode  = USART_NORMAL_CHMODE
  };

  // Assign GPIO to USART.
  gpio_enable_module(USART_GPIO_MAP,
                     sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));

  // Initialize USART in RS232 mode.
  usart_init_rs232(EXAMPLE_USART, &USART_OPTIONS, fosc);

  // New window
  dsp_debug_print_fct("\x0C\r\n");
}
コード例 #6
0
void init_Usart (void)
{
    ioport_set_pin_dir(PIO_PA21_IDX,IOPORT_DIR_INPUT);
    ioport_set_pin_dir(PIO_PB4_IDX,IOPORT_DIR_OUTPUT);


    const sam_usart_opt_t usart_console_settings = {
        USART_SERIAL_BAUDRATE,
        USART_SERIAL_CHAR_LENGTH,
        USART_SERIAL_PARITY,
        USART_SERIAL_STOP_BIT,
        US_MR_CHMODE_NORMAL
    };
#if SAM4L
    sysclk_enable_peripheral_clock(USART_SERIAL);
#else
    sysclk_enable_peripheral_clock(USART_SERIAL_ID);
#endif
    usart_init_rs232(USART_SERIAL, &usart_console_settings,
                     sysclk_get_main_hz()/2);
    usart_enable_tx(USART_SERIAL);
    usart_enable_rx(USART_SERIAL);
    // how to enable an interrupt( use three steps ):use these functions: -usart_enable_interrupt-    Then  -NVIC_EnableIRQ(USART_SERIAL_IRQ);-    & Then add this function  void USART_SERIAL_ISR_HANDLER(void)
    usart_enable_interrupt(USART_SERIAL, US_IER_RXRDY);
    NVIC_EnableIRQ(USART_SERIAL_IRQ);
}
コード例 #7
0
ファイル: print_funcs.c プロジェクト: bensteinberg/aleph
void init_dbg_rs232_ex(unsigned long baudrate, long pba_hz)
{
  static const gpio_map_t DBG_USART_GPIO_MAP =
  {
    {DBG_USART_RX_PIN, DBG_USART_RX_FUNCTION},
    {DBG_USART_TX_PIN, DBG_USART_TX_FUNCTION}
  };

  // Options for debug USART.
  usart_options_t dbg_usart_options =
  {
    .baudrate = baudrate,
    .charlength = 8,
    .paritytype = USART_NO_PARITY,
    .stopbits = USART_1_STOPBIT,
    .channelmode = USART_NORMAL_CHMODE
  };

  // Setup GPIO for debug USART.
  gpio_enable_module(DBG_USART_GPIO_MAP,
                     sizeof(DBG_USART_GPIO_MAP) / sizeof(DBG_USART_GPIO_MAP[0]));

  // Initialize it in RS232 mode.
  usart_init_rs232(DBG_USART, &dbg_usart_options, pba_hz);
}

#if RELEASEBUILD==1



void print_dbg(const char *str) { ;; }
コード例 #8
0
ファイル: uart_sam.c プロジェクト: Timvrakas/samd21_gcc
void uart_open(uint8_t port)
{
	Usart* usart = get_usart(port);

	if (0 == port) {
		// IO is initialized in board init
		// Enable interrupt with priority higher than USB
		NVIC_SetPriority((IRQn_Type) USART_ID_0, USART_INT_LEVEL_0);
		NVIC_EnableIRQ((IRQn_Type) USART_ID_0);
		NVIC_SetPriority((IRQn_Type) USART_ID_1, USART_INT_LEVEL_1);
		NVIC_EnableIRQ((IRQn_Type) USART_ID_1);
		// Initialize it in RS232 mode.
		pmc_enable_periph_clk(USART_ID_0);
		USART_ENABLE_0();
	} else if (1 == port) {
		// IO is initialized in board init
		// Enable interrupt with priority higher than USB
		NVIC_SetPriority((IRQn_Type) USART_ID_1, USART_INT_LEVEL_1);
		NVIC_EnableIRQ((IRQn_Type) USART_ID_1);
		// Initialize it in RS232 mode.
		pmc_enable_periph_clk(USART_ID_1);
		USART_ENABLE_1();
	} else {
		return;
	}
	if (usart_init_rs232(usart, &usart_options,
				sysclk_get_peripheral_hz())) {
		return;
	}
	// Enable both RX and TX
	usart_enable_tx(usart);
	usart_enable_rx(usart);
	// Enable interrupts
	usart_enable_interrupt(usart, US_IER_RXRDY | US_IER_TXRDY);
}
コード例 #9
0
ファイル: unit_tests.c プロジェクト: marekr/asf
/**
 * \brief Test checking different registers of the USART module
 *
 * This function calls the different check functions and make sure they set the
 * correct values.
 *
 * \param test Current test case.
 */
static void run_check_registers_test(const struct test_case *test)
{
	bool success;
	uint8_t data = 'b';

	
	const usart_rs232_options_t options = {
		.baudrate   = CONF_UNIT_BAUDRATE,
		.charlength = CONF_UNIT_CHARLENGTH,
		.paritytype = CONF_UNIT_PARITY,
		.stopbits   = CONF_UNIT_STOPBITS
	};

	usart_init_rs232(&CONF_UNIT_USART, &options);
      
	/* Test empty data register */
	success = usart_data_register_is_empty(&CONF_UNIT_USART);
	test_assert_true(test, success,
			"Checking if the data register is empty failed");
	
	/* Test finished data transfers */
	usart_put(&CONF_UNIT_USART, data);
	for(volatile uint16_t delay=0;delay<20000;delay++);
    
	success = usart_rx_is_complete(&CONF_UNIT_USART);
	usart_get(&CONF_UNIT_USART);
	test_assert_true(test, success,
   	                "Checking if the receive is finished failed");		       
					
	success = usart_tx_is_complete(&CONF_UNIT_USART);
	test_assert_true(test, success,
	                "Checking if the transmit is finished failed");

}
コード例 #10
0
int main (void)
{
	board_init();	//Board definition and selection
	sysclk_init();	//System clock init
	
	usart_init_rs232(USART_SERIAL_RFID, &usart_options_RFID);	//UART init
	usart_init_rs232(USART_SERIAL_Monitor, &usart_options_Monitor);
	
	gfx_mono_init();	//LCD init
	PORTE.OUTSET=PIN4_bm;	//LCD Back light on
	
	//RTC Init
	sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC);
	while (RTC32.SYNCCTRL & RTC32_SYNCBUSY_bm);
	if (rtc_vbat_system_check(false) != VBAT_STATUS_OK)
		rtc_init();
	PORTE.DIRCLR=PIN5_bm;
	
	while(1)
	{
		if(Receive())
		{
			card_no=Check();
			if(card_no)
			{
				PORTR.OUTCLR=PIN0_bm;
				gfx_mono_draw_string("Card Detected",0,0,&sysfont);
				gfx_mono_draw_string("Welcome",0,10,&sysfont);
				gfx_mono_draw_string(names[card_no-1],55,10,&sysfont);
				rtc_timestamp=rtc_get_time();
				calendar_timestamp_to_date_tz(rtc_timestamp,5,30,&get_date);
				gfx_mono_draw_string(display_time(get_date,arr),0,20,&sysfont);
				delay_s(1);
				gfx_mono_init();
				PORTR.OUTSET=PIN0_bm;
			}
			else
			{
				PORTR.OUTCLR=PIN1_bm;
				gfx_mono_draw_string("Invalid Card",0,0,&sysfont);
				delay_s(1);
				gfx_mono_init();
				PORTR.OUTSET=PIN1_bm;
			}
		}
	}
}
コード例 #11
0
ファイル: comms.c プロジェクト: ribbotson/rlabTelemetryTx
void ext_uart_init(void)
{
	static usart_rs232_options_t EXT_USART_SERIAL_OPTIONS = {
		.baudrate = EXT_USART_SERIAL_BAUDRATE,
		.charlength = EXT_USART_SERIAL_CHAR_LENGTH,
		.paritytype = EXT_USART_SERIAL_PARITY,
		.stopbits = EXT_USART_SERIAL_STOP_BIT
	};
	sysclk_enable_module(SYSCLK_PORT_E, PR_USART0_bm);
	usart_init_rs232(EXT_USART_SERIAL, &EXT_USART_SERIAL_OPTIONS);
}
コード例 #12
0
u16 BUFFERED_SIO_Init (void)
{
    // IO mapping
static const gpio_map_t USART_GPIO_MAP = {
    {BUFFERED_SIO_USART_RX_PIN, BUFFERED_SIO_USART_RX_FUNCTION},
    {BUFFERED_SIO_USART_TX_PIN, BUFFERED_SIO_USART_TX_FUNCTION}
};

    // USART options.
static const usart_options_t USART_OPTIONS = {
    .baudrate = 57600 * 2,
    .charlength = 8,
    .paritytype = USART_NO_PARITY,
    .stopbits = USART_1_STOPBIT,
    .channelmode = USART_NORMAL_CHMODE
};

    // Reset vars
    BUFFERED_SIO_TxBuffer_StartPointer = 0;
    BUFFERED_SIO_TxBuffer_EndPointer = 0;
    BUFFERED_SIO_TxActiv_Sendbytes = 0;

    BUFFERED_SIO_RxBuffer_StartPointer = 0;
    BUFFERED_SIO_RxBuffer_EndPointer = 0;

#ifdef STICK_20_SEND_DEBUGINFOS_VIA_HID
    BUFFERED_SIO_HID_TxBuffer_StartPointer = 0;
    BUFFERED_SIO_HID_TxBuffer_EndPointer = 0;
    BUFFERED_SIO_HID_TxActiv_Sendbytes = 0;
#endif

    // Assign GPIO to USART.
    gpio_enable_module (USART_GPIO_MAP, sizeof (USART_GPIO_MAP) / sizeof (USART_GPIO_MAP[0]));

    // Initialize USART in RS232 mode.
    usart_init_rs232 (BUFFERED_SIO_USART, &USART_OPTIONS, FPBA_HZ);

    // Disable all interrupts.
    Disable_global_interrupt ();

    // Set ISR
    INTC_register_interrupt (&BUFFERED_SIO_Usart_ISR, BUFFERED_SIO_USART_IRQ, AVR32_INTC_INT0);

    // Enable USART Rx interrupt.
    BUFFERED_SIO_USART->IER.rxrdy = 1;

    // Enable USART Tx interrupt.
    // BUFFERED_SIO_USART->IER.txempty = 1;

    // Enable all interrupts.
    Enable_global_interrupt ();

    return (TRUE);
}
コード例 #13
0
ファイル: serial.c プロジェクト: granthuu/fsm_software
/*
 * See the serial.h header file.
 */
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
{
uint32_t ulChar;
xComPortHandle xReturn;
const sam_usart_opt_t xUSARTSettings =
{
	ulWantedBaud,
	US_MR_CHRL_8_BIT,
	US_MR_PAR_NO,
	US_MR_NBSTOP_1_BIT,
	US_MR_CHMODE_NORMAL,
	0 /* Only used in IrDA mode. */
};

	/* Create the queues used to hold Rx/Tx characters. */
	xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
	xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );

	/* If the queues were created correctly then setup the serial port
	hardware. */
	if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) )
	{
		/* Enable the peripheral clock in the PMC. */
		pmc_enable_periph_clk( serPMC_USART_ID );

		/* Configure USART in serial mode. */
		usart_init_rs232( serUSART_PORT, &xUSARTSettings, sysclk_get_cpu_hz() );

		/* Disable all the interrupts. */
		usart_disable_interrupt( serUSART_PORT, serMASK_ALL_INTERRUPTS );

		/* Enable the receiver and transmitter. */
		usart_enable_tx( serUSART_PORT );
		usart_enable_rx( serUSART_PORT );

		/* Clear any characters before enabling interrupt. */
		usart_getchar( serUSART_PORT, &ulChar );

		/* Enable Rx end interrupt. */
		usart_enable_interrupt( serUSART_PORT, US_IER_RXRDY );

		/* Configure and enable interrupt of USART. */
		NVIC_SetPriority( serUSART_IRQ, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
		NVIC_EnableIRQ( serUSART_IRQ );
	}
	else
	{
		xReturn = ( xComPortHandle ) 0;
	}

	/* This demo file only supports a single port but we have to return
	something to comply with the standard demo header file. */
	return xReturn;
}
コード例 #14
0
int main (void)
{
	uint8_t menu_status;
	struct keyboard_event input;

	static usart_rs232_options_t SERIAL_OPTIONS = {
		.baudrate = 57600,
		.charlength = USART_CHSIZE_8BIT_gc,
		.paritytype = USART_PMODE_DISABLED_gc,
		.stopbits = false
	};

	sysclk_init();	
	board_init();
	solenoid_init();
	gfx_mono_init();
	usart_init_rs232(USART_SERIAL, &SERIAL_OPTIONS);

	gpio_toggle_pin(NHD_C12832A1Z_BACKLIGHT);

	while(true) 
	{
		gfx_mono_menu_init(&main_menu);

		do {
			do {
				keyboard_get_key_state(&input);
			} while (input.type != KEYBOARD_RELEASE);

			menu_status = gfx_mono_menu_process_key(&main_menu, input.keycode);
		} while (menu_status == GFX_MONO_MENU_EVENT_IDLE);

		//Determine what song to play based on 
		//the input from the user controlling the A3BU
		switch(menu_status) {
			case 0:
				song_menu(0);
				play_song_with_input(SAMPLE_SONG, SAMPLE_SONG_LENGTH);
				break;
			case 1:
				song_menu(1);
				play_song_with_input(STAIRWAY, 6);
				break;
			case 2:
				song_menu(2);
				play_song_with_input(MISERLOU, 1);
				break;
			case 3:
				song_menu(3);
				play_serial();
				break;
		}
	}
}
コード例 #15
0
ファイル: adpcm_example.c プロジェクト: avrxml/asf
//! this function initializes the USART module at 115200 bauds
void init_usart()
{
  static const gpio_map_t USART_GPIO_MAP =
  {
    {EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION},
    {EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION}
  };

  // Configuration structure for the USART module
  static const usart_options_t USART_OPTIONS =
  {
    // Baudrate at 115200 bauds
    .baudrate     = 115200,
    // 8 bits per characters
    .charlength   = 8,
    // No parity
    .paritytype   = USART_NO_PARITY,
    // One stop bit
    .stopbits     = USART_1_STOPBIT,
    // Mode normal
    .channelmode  = USART_NORMAL_CHMODE
  };

  // Assign GPIO to USART.
  gpio_enable_module(USART_GPIO_MAP,
                     sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));

  // Initialize USART in RS232 mode.
  usart_init_rs232(EXAMPLE_USART, &USART_OPTIONS, FOSC0*2);
}













//! Read the next block
void set_new_dac_buffer(char *_next_buffer)
{
  pbuffer_r = _next_buffer;

  predicted_value = *((short *) &pbuffer_r[4]);
  step_index = *((short *) &pbuffer_r[6]);

  cur_i_read_buffer = 8;
}
コード例 #16
0
ファイル: InitSoftware.c プロジェクト: jerpeter/NS8100
///----------------------------------------------------------------------------
///	Function Break
///----------------------------------------------------------------------------
void LoadUnitConfig(void)
{
	GetRecordData(&g_unitConfig, DEFAULT_RECORD, REC_UNIT_CONFIG_TYPE);

	// Check if the Unit Config is uninitialized
	if (g_unitConfig.validationKey != 0xA5A5)
	{
		// Set defaults in Unit Config
		debugWarn("Unit Config: Not found.\r\n");
#if EXTENDED_DEBUG
		debug("Loading Unit Config Defaults\r\n");
#endif

		LoadUnitConfigDefaults((UNIT_CONFIG_STRUCT*)&g_unitConfig);
		SaveRecordData(&g_unitConfig, DEFAULT_RECORD, REC_UNIT_CONFIG_TYPE);
	}
	else
	{
		// Unit Config is valid
#if EXTENDED_DEBUG
		debug("Unit Config record is valid\r\n");
#endif

		if ((g_unitConfig.pretrigBufferDivider != PRETRIGGER_BUFFER_QUARTER_SEC_DIV) && (g_unitConfig.pretrigBufferDivider != PRETRIGGER_BUFFER_HALF_SEC_DIV) &&
			(g_unitConfig.pretrigBufferDivider != PRETRIGGER_BUFFER_FULL_SEC_DIV))
		{
			g_unitConfig.pretrigBufferDivider = PRETRIGGER_BUFFER_QUARTER_SEC_DIV;
			SaveRecordData(&g_unitConfig, DEFAULT_RECORD, REC_UNIT_CONFIG_TYPE);
		}

#if 1 // Forcing flash wrapping to be disabled
		g_unitConfig.flashWrapping = NO;
#endif

#if 0 // Moved this init to the hardware section to allow for the saved Baud rate to be established from the start
		// Set the baud rate to the user stored baud rate setting (initialized to 115200)
		switch (g_unitConfig.baudRate)
		{
			case BAUD_RATE_57600: rs232Options.baudrate = 57600; break;
			case BAUD_RATE_38400: rs232Options.baudrate = 38400; break;
			case BAUD_RATE_19200: rs232Options.baudrate = 19200; break;
			case BAUD_RATE_9600: rs232Options.baudrate = 9600; break;
		}

		if (g_unitConfig.baudRate != BAUD_RATE_115200)
		{
			// Re-Initialize the RS232 with the stored baud rate
			usart_init_rs232(&AVR32_USART1, &rs232Options, FOSC0);
		}
#endif
	}
}
コード例 #17
0
ファイル: UartBuffer.c プロジェクト: Gallard88/PowerMonitor
/* ============================================= */
void UartBuffer_Init(void)
{
	sysclk_enable_peripheral_clock(ID_USART0);
	usart_init_rs232(USART0, &usart_console_settings, sysclk_get_cpu_hz());
	usart_disable_interrupt(USART0, ALL_INTERRUPT_MASK);
	usart_enable_tx(USART0);
	usart_enable_rx(USART0);
	usart_enable_interrupt(USART0, US_IER_RXRDY);
	NVIC_EnableIRQ(USART0_IRQn);

	TxIn = TxOut = 0;
	RxIn = RxOut = 0;
}
コード例 #18
0
int usart_init_rs485(volatile avr32_usart_t *usart, const usart_options_t *opt, long pba_hz)
{
  // First: Setup standard RS232.
  if (usart_init_rs232(usart, opt, pba_hz) == USART_INVALID_INPUT)
    return USART_INVALID_INPUT;

  // Clear previous mode.
  usart->mr &= ~AVR32_USART_MR_MODE_MASK;
  // Set RS485 mode.
  usart->mr |= USART_MODE_RS485 << AVR32_USART_MR_MODE_OFFSET;

  return USART_SUCCESS;
}
コード例 #19
0
ファイル: main.c プロジェクト: forkineye/FloodBrain_ASF
// setup the board instead of board_init() as recommended by ASF.. because christmas lights, that's why.
void init (void) {
	static usart_serial_options_t usart_options = {
		.baudrate = USART_SERIAL_BAUDRATE,
		.charlength = USART_SERIAL_CHAR_LENGTH,
		.paritytype = USART_SERIAL_PARITY,
		.stopbits = USART_SERIAL_STOP_BIT
	};
	
	// initialize ASF stuff
	board_init();
	sysclk_init();
	ioport_init();
	pmic_init();
	pmic_set_scheduling(PMIC_SCH_FIXED_PRIORITY);
	
	// remap, enable TX, and configure USART on PORT C
	PORTC.REMAP |= PR_USART0_bm;
	PORTC.DIR |= (1 << PIN7_bp);
		
	sysclk_enable_module(SYSCLK_PORT_C, PR_USART0_bm);
	usart_init_rs232(USART_SERIAL, &usart_options);
	
	// setup timer for PWM
	tc45_enable(&TCC4);
	tc45_set_overflow_interrupt_callback(&TCC4, pwm_callback);
	tc45_set_wgm(&TCC4, TC45_WG_NORMAL);
	tc45_write_period(&TCC4, 256);
	tc45_set_overflow_interrupt_level(&TCC4, TC45_INT_LVL_MED);
		
	// enable all channels and turn off (high)
	ioport_set_port_dir(IOPORT_PORTA, PORTA_MASK, IOPORT_DIR_OUTPUT);
	ioport_set_port_dir(IOPORT_PORTD, PORTD_MASK, IOPORT_DIR_OUTPUT);
	ioport_set_port_dir(IOPORT_PORTR, PORTR_MASK, IOPORT_DIR_OUTPUT);
	ioport_set_port_level(IOPORT_PORTA, PORTA_MASK, 0xFF);
	ioport_set_port_level(IOPORT_PORTD, PORTD_MASK, 0xFF);
	ioport_set_port_level(IOPORT_PORTR, PORTR_MASK, 0xFF);
	for (uint8_t i=0; i<NUM_CHANNELS; i++) {
		compare[i] = 0;
		compbuff[i] = 0;
	}
	
	// enable status LEDs and turn off
	ioport_set_pin_dir(LED_STATUS, IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(LED_DATA, IOPORT_DIR_OUTPUT);
	ioport_set_pin_level(LED_STATUS, 1);
	ioport_set_pin_level(LED_DATA, 1);
	
	// enable interrupts and start timer for PWM
	cpu_irq_enable();
	tc45_write_clock_source(&TCC4, TC45_CLKSEL_DIV2_gc);	
}
コード例 #20
0
ファイル: comms.c プロジェクト: ribbotson/rlabTelemetryTx
void ntx2b_uart_init(void)
{
	static usart_rs232_options_t NTX2B_USART_SERIAL_OPTIONS = {
		.baudrate = NTX2B_USART_SERIAL_BAUDRATE,
		.charlength = NTX2B_USART_SERIAL_CHAR_LENGTH,
		.paritytype = NTX2B_USART_SERIAL_PARITY,
		.stopbits = NTX2B_USART_SERIAL_STOP_BIT
	};
	sysclk_enable_module(SYSCLK_PORT_D, PR_USART0_bm);
	usart_init_rs232(NTX2B_USART_SERIAL, &NTX2B_USART_SERIAL_OPTIONS);
	usart_rx_disable(NTX2B_USART_SERIAL); // we don't use the receiver
	ioport_set_pin_mode(GPIO_NTX2B_EN, IOPORT_MODE_TOTEM | IOPORT_MODE_INVERT_PIN ); // set enable low
	
}
コード例 #21
0
int usart_init_IrDA(volatile avr32_usart_t *usart, const usart_options_t *opt,
                    long pba_hz, unsigned char irda_filter)
{
  // First: Setup standard RS232.
  if (usart_init_rs232(usart, opt, pba_hz) == USART_INVALID_INPUT)
    return USART_INVALID_INPUT;

  // Set IrDA counter.
  usart->ifr = irda_filter;

  // Activate "low-pass filtering" of input.
  usart->mr |= AVR32_USART_MR_FILTER_MASK;

  return USART_SUCCESS;
}
コード例 #22
0
ファイル: usb_specific_request.c プロジェクト: kerichsen/asf
void cdc_set_line_coding (void)
{
   Usb_ack_setup_received_free();

   while(!Is_usb_control_out_received());
   Usb_reset_endpoint_fifo_access(EP_CONTROL);

   LSB0(line_coding.dwDTERate) = Usb_read_endpoint_data(EP_CONTROL, 8);
   LSB1(line_coding.dwDTERate) = Usb_read_endpoint_data(EP_CONTROL, 8);
   LSB2(line_coding.dwDTERate) = Usb_read_endpoint_data(EP_CONTROL, 8);
   LSB3(line_coding.dwDTERate) = Usb_read_endpoint_data(EP_CONTROL, 8);
   line_coding.bCharFormat = Usb_read_endpoint_data(EP_CONTROL, 8);
   line_coding.bParityType = Usb_read_endpoint_data(EP_CONTROL, 8);
   line_coding.bDataBits = Usb_read_endpoint_data(EP_CONTROL, 8);
   Usb_ack_control_out_received_free();

   Usb_ack_control_in_ready_send();
   while (!Is_usb_control_in_ready());

   // Set the baudrate of the USART
   {
      static usart_options_t dbg_usart_options;
      uint32_t stopbits, parity;

      if     ( line_coding.bCharFormat==0 )   stopbits = USART_1_STOPBIT;
      else if( line_coding.bCharFormat==1 )   stopbits = USART_1_5_STOPBITS;
      else                                    stopbits = USART_2_STOPBITS;

      if     ( line_coding.bParityType==0 )   parity = USART_NO_PARITY;
      else if( line_coding.bParityType==1 )   parity = USART_ODD_PARITY;
      else if( line_coding.bParityType==2 )   parity = USART_EVEN_PARITY;
      else if( line_coding.bParityType==3 )   parity = USART_MARK_PARITY;
      else                                    parity = USART_SPACE_PARITY;

      // Options for debug USART.
      dbg_usart_options.baudrate    = line_coding.dwDTERate;
      dbg_usart_options.charlength  = line_coding.bDataBits;
      dbg_usart_options.paritytype  = parity;
      dbg_usart_options.stopbits    = stopbits;
      dbg_usart_options.channelmode = USART_NORMAL_CHMODE;

      // Initialize it in RS232 mode.
      usart_init_rs232(DBG_USART, &dbg_usart_options, pcl_freq_param.pba_f);

      // Enable Rx interrupts
      DBG_USART->ier = AVR32_USART_IER_RXRDY_MASK;
   }
}
コード例 #23
0
/**
 * \brief Application main loop.
 */
int main(void)
{
	board_init();
	/**
	 * \note the call to sysclk_init() will disable all non-vital
	 * peripheral clocks, except for the peripheral clocks explicitly
	 * enabled in conf_clock.h.
	 */
	sysclk_init();

	/**
	 * Enable the clock to the selected example USART peripheral module.
	 * The clocks to all non-essential peripherals are disabled in the
	 * conf_clock.h file, so we need to re-enable our USART clock here.
	 */
	sysclk_enable_peripheral_clock(EXAMPLE_USART);

	/**
	 * Write the example USART module configuration to the hardware
	 * registers. The example USART is selected in the conf_example_usart.h
	 * file.
	 */
	usart_init_rs232(EXAMPLE_USART, &usart_opt,
			sysclk_get_peripheral_bus_hz(EXAMPLE_USART));

	/**
	 * Write a welcome message on the USART and busy-wait for the listener
	 * to press the enter key.
	 */
	usart_write_line(EXAMPLE_USART, "Hello, this is the AVR UC3 MCU saying"
			" hello! (press enter)\r\n");

	/**
	 * Busy-wait for a carriage return sent from the listener. Any received
	 * characters are echoed back.
	 */
	do { } while (usart_get_echo_line(EXAMPLE_USART) == USART_FAILURE);

	/**
	 * Send a goodbye message before entering a forever non-return loop.
	 */
	usart_write_line(EXAMPLE_USART, "Goodbye.\r\n");

	for (;;) {
		/* Intentionally loop forever. */
	}
}
コード例 #24
0
ファイル: unit_tests.c プロジェクト: marekr/asf
/**
 * \brief Test physical loop-back with some characters.
 *
 * This function sends a character over USART on loop back to verify that init
 * and sending/receiving works. A jumper is connected on the USART.
 *
 * \param test Current test case.
 */
static void run_loopback_test(const struct test_case *test)
{
	uint8_t out_c = 'a';
	uint8_t in_c  = 0;
	
	const usart_rs232_options_t options = {
		.baudrate   = CONF_UNIT_BAUDRATE,
		.charlength = CONF_UNIT_CHARLENGTH,
		.paritytype = CONF_UNIT_PARITY,
		.stopbits   = CONF_UNIT_STOPBITS
	};

	usart_init_rs232(&CONF_UNIT_USART, &options);

	usart_putchar(&CONF_UNIT_USART, out_c);
	in_c = usart_getchar(&CONF_UNIT_USART);

	test_assert_true(test, in_c == out_c,
			"Read character is not correct: %d != %d", in_c, out_c);			
}
コード例 #25
0
ファイル: main.c プロジェクト: johaa1993/C-Examples
static void USART_Initialize ()
{
    static const gpio_map_t USART_GPIO_MAP =
    {
        {AVR32_USART0_RXD_0_0_PIN, AVR32_USART0_RXD_0_0_FUNCTION},
        {AVR32_USART0_TXD_0_0_PIN, AVR32_USART0_TXD_0_0_FUNCTION}
    };
    static const usart_options_t USART_OPTIONS =
    {
        .baudrate     = 57600,
        .charlength   = 8,
        .paritytype   = USART_NO_PARITY,
        .stopbits     = USART_1_STOPBIT,
        .channelmode  = USART_NORMAL_CHMODE
    };
    portENTER_CRITICAL ();
    {
        gpio_enable_module(USART_GPIO_MAP, sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));
        usart_init_rs232 (&AVR32_USART0, &USART_OPTIONS, FOSC0);
        (&AVR32_USART0)->cr |= AVR32_USART_CR_RXDIS_MASK | AVR32_USART_CR_TXDIS_MASK;
        //INTC_init_interrupts ();
        //INTC_register_interrupt (&USART_0_Interrupt, AVR32_USART0_IRQ, AVR32_INTC_INT0);
        //(&AVR32_USART0)->ier = AVR32_USART_IER_RXRDY_MASK;
        (&AVR32_USART0)->cr |= AVR32_USART_CR_TXEN_MASK | AVR32_USART_CR_RXEN_MASK;
    }
    portEXIT_CRITICAL();
}

void USART_printf (volatile avr32_usart_t * usart, const char * format, ...)
{
    //taskENTER_CRITICAL();
#define Buffer_Size 100
    char Buffer[Buffer_Size] = {'\0'};
    va_list args;
    va_start (args, format);
    vsprintf (Buffer, format, args);
    va_end (args);
    usart_write_line (usart, Buffer);
#undef Buffer_Size
    //taskEXIT_CRITICAL();
};
コード例 #26
0
ファイル: usart_example.c プロジェクト: InSoonPark/asf
/*! \brief Main function.
 */
int main(void)
{
	uint8_t tx_buf[] = "\n\rHello AVR world ! : ";
	uint8_t tx_length = sizeof(tx_buf);
	uint8_t received_byte;
	uint8_t i;

	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();
	sysclk_init();

	/* USART options. */
	static usart_rs232_options_t USART_SERIAL_OPTIONS = {
		.baudrate = USART_SERIAL_EXAMPLE_BAUDRATE,
		.charlength = USART_SERIAL_CHAR_LENGTH,
		.paritytype = USART_SERIAL_PARITY,
		.stopbits = USART_SERIAL_STOP_BIT
	};

	/* Initialize usart driver in RS232 mode */
	usart_init_rs232(USART_SERIAL_EXAMPLE, &USART_SERIAL_OPTIONS);

	/* Send "message header" */
	for (i = 0; i < tx_length; i++) {
		usart_putchar(USART_SERIAL_EXAMPLE, tx_buf[i]);
	}
	/* Get and echo a character forever, specific '\r' processing. */
	while (true) {
		received_byte = usart_getchar(USART_SERIAL_EXAMPLE);
		if (received_byte == '\r') {
			for (i = 0; i < tx_length; i++) {
				usart_putchar(USART_SERIAL_EXAMPLE, tx_buf[i]);
			}
		} else {
			usart_putchar(USART_SERIAL_EXAMPLE, received_byte);
		}
	}
}
コード例 #27
0
ファイル: print_funcs.c プロジェクト: Someone101/aleph
void init_dbg_rs232_ex(unsigned long baudrate, long pba_hz)
{
  static const gpio_map_t DBG_USART_GPIO_MAP =
  {
    {DBG_USART_RX_PIN, DBG_USART_RX_FUNCTION},
    {DBG_USART_TX_PIN, DBG_USART_TX_FUNCTION}
  };

  // Options for debug USART.
  usart_options_t dbg_usart_options =
  {
    .baudrate = baudrate,
    .charlength = 8,
    .paritytype = USART_NO_PARITY,
    .stopbits = USART_1_STOPBIT,
    .channelmode = USART_NORMAL_CHMODE
  };

  // Setup GPIO for debug USART.
  gpio_enable_module(DBG_USART_GPIO_MAP,
                     sizeof(DBG_USART_GPIO_MAP) / sizeof(DBG_USART_GPIO_MAP[0]));

  // Initialize it in RS232 mode.
  usart_init_rs232(DBG_USART, &dbg_usart_options, pba_hz);
}

#if RELEASEBUILD==1

/// print_dbg funcs are #defined as noops in header

#else


void print_dbg(const char *str)
{
  // Redirection to the debug USART.
  USART_BEGIN_DBG_TX;
  print(DBG_USART, str);
  USART_END_DBG_TX;
}
コード例 #28
0
ファイル: ipc_example_core1.c プロジェクト: InSoonPark/asf
/**
 *  \brief Configure the Console.
 */
static void configure_console(void)
{
	const sam_usart_opt_t usart_console_settings = {
		CONF_UART_BAUDRATE,
		CONF_UART_CHAR_LENGTH,
		CONF_UART_PARITY,
		CONF_UART_STOP_BITS,
		US_MR_CHMODE_NORMAL,
		/* This field is only used in IrDA mode. */
		0
	};

	/* Enable the peripheral clock in the PMC. */
	sysclk_enable_peripheral_clock(CONF_UART_ID);

	/* Configure USART in serial mode. */
	usart_init_rs232(CONF_UART, &usart_console_settings,
			sysclk_get_cpu_hz());

	/* Enable the transmitter. */
	usart_enable_tx(CONF_UART);
}
コード例 #29
0
ファイル: board_monitor.c プロジェクト: AndreyMostovov/asf
/**
 *  \brief Configure the USART.
 */
void bm_init(void)
{
	static uint32_t ul_sysclk;
	const sam_usart_opt_t usart_console_settings = {
		115200,
		US_MR_CHRL_8_BIT,
		US_MR_PAR_NO,
		US_MR_NBSTOP_1_BIT,
		US_MR_CHMODE_NORMAL,
		/* This field is only used in IrDA mode. */
		0
	};

	/* Get system clock. */
	ul_sysclk = sysclk_get_peripheral_bus_hz(BM_USART_USART);

	/* Configure sysclk. */
	sysclk_enable_peripheral_clock(BM_USART_USART);

	/* Configure UART. */
	usart_init_rs232(BM_USART_USART, &usart_console_settings, ul_sysclk);
}
コード例 #30
0
/**
 * \brief Configure USART in normal (serial rs232) mode, asynchronous,
 * 8 bits, 1 stop bit, no parity, 115200 bauds and enable its transmitter
 * and receiver.
 */
static void configure_usart(void)
{
	const sam_usart_opt_t usart_console_settings = {
		BOARD_USART_BAUDRATE,
		US_MR_CHRL_8_BIT,
		US_MR_PAR_NO,
		US_MR_NBSTOP_1_BIT,
		US_MR_CHMODE_NORMAL,
		/* This field is only used in IrDA mode. */
		0
	};

	/* Enable the peripheral clock in the PMC. */
	sysclk_enable_peripheral_clock(BOARD_ID_USART);

	/* Configure USART in serial mode. */
	usart_init_rs232(BOARD_USART, &usart_console_settings,
			sysclk_get_cpu_hz());

	/* Enable the receiver and transmitter. */
	usart_enable_tx(BOARD_USART);
	usart_enable_rx(BOARD_USART);
}