USB CDC Realterm

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

#include <asf.h>

/**
 * \brief main function
 */
int main (void)
{
#if SAMD21 || SAMR21
	/* Initialize basic board support features.
	 * - Initialize system clock sources according to device-specific
	 *   configuration parameters supplied in a conf_clocks.h file.
	 * - Set up GPIO and board-specific features using additional configuration
	 *   parameters, if any, specified in a conf_board.h file.
	 */
	system_init();
#else
	/* Initialize basic board support features.
	 * - Initialize system clock sources according to device-specific
	 *   configuration parameters supplied in a conf_clock.h file.
	 * - Set up GPIO and board-specific features using additional configuration
	 *   parameters, if any, specified in a conf_board.h file.
	 */
	sysclk_init();
	board_init();
#endif

	// Initialize interrupt vector table support.
	irq_initialize_vectors();

	// Enable interrupts
	cpu_irq_enable();

	/* Call a local utility routine to initialize C-Library Standard I/O over
	 * a USB CDC protocol. Tunable parameters in a conf_usb.h file must be
	 * supplied to configure the USB device correctly.
	 */
	stdio_usb_init();

	// Get and echo characters forever.

	uint8_t ch;

	while (true) {

		scanf("%c",&ch); // get one input character

		if (ch) {
			printf("%c",ch); // echo to output
		}
	}
}

I have run an example project of xmega a3bu on usb cdc protocol, but i am finding difficulty in using the Realterm to send and recieve the data. My virtual COMport is 9 in the device manager , I tried changing that in the realterm but it says 'port does not exist'.Can anyone help me with it?

This topic has a solution.

Nitin Shenoy

Last Edited: Mon. Jan 28, 2019 - 06:46 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Well does Windows show that the CDC has even enumerated? If it does has it assigned COM9 or something else?

 

Note also that usbdeview.exe

 

https://www.nirsoft.net/utils/us...

 

is an invaluable tool for diagnosing USB device operation in Windows.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you're having troubles with serial ports then start by shorting TxD and RxD together.

This will echo all send data back to whatever software you use.

 

Second step may be to cross connect the RxD and TxD of 2 serial ports and use 2 terminal emulators, to verify your port settings work.

 

As long as your PC's ports do not work properly there is no use of trying to use a microcontroller.

 

If you want to get started with CDC in a uC with USB, then start with the most simplest application.

For example, no scanf, or conditinal if stuff but something like:

 

 


void main ( void) {
    
    int cnt = 0;
    
    for( ;;) {
			printf("%3d Hello world.\n", cnt);
			delay_ms(400);
		}
	}
}

 

But even this is probably too complictated to begin with.

printf( ) is quite a beast of a function, and it is not guarateed to work with your serial port.

So if printf( ) does not work on the first try, use a simpler character based function.

 

Gotcha:

Data may be buffered somewhere untill pipes get flushed, or often untill you send a newline  "\n".

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com