USB CDC Echo Using SAMD21-Send different data from another function.

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

I'm working on USB CDC on ATSAMD21. The code which i'm using is ATMEL START example for USB CD Echo on D21. I'm working on atmel studio.

 

Requirement:

     

    In my application the host send data to the device and i need to read that data and send back different data to the host from different function.

 

    Here in echo example the data reception and transfer is using the call back. I'm not aware how to use a write call   inside another function. Here i'm attaching the code below

Read the data:

static bool usb_device_cb_state_c(usb_cdc_control_signal_t state)
{
	if (state.rs232.DTR ) {
		/* Callbacks must be registered after endpoint allocation */
		cdcdf_acm_register_callback(CDCDF_ACM_CB_READ, (FUNC_PTR)usb_device_cb_bulk_out);
		
		cdcdf_acm_register_callback(CDCDF_ACM_CB_WRITE, (FUNC_PTR)usb_device_cb_bulk_in);
		/* Start Rx */
		cdcdf_acm_read((uint8_t *)usbd_cdc_buffer, sizeof(usbd_cdc_buffer));
	}

	/* No error. */
	return false;
}

Read from call back:

 

 

*/
static bool usb_device_cb_bulk_out(const uint8_t ep, const enum usb_xfer_code rc, const uint32_t count)
{
	cdcdf_acm_write((uint8_t *)usbd_cdc_buffer, count);
	
return false;	
}

Write back the data:

 

static bool usb_device_cb_bulk_in(const uint8_t ep, const enum usb_xfer_code rc, const uint32_t count)
{
	/* Echo data. */
	cdcdf_acm_read((uint8_t *)usbd_cdc_buffer, sizeof(usbd_cdc_buffer));

	/* No error. */
	return false;
}

Here i need to use this call inside another function to write a different data.  How can i use this read call in another function. Any help will be appreciated.

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

Any updates ?

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

You have to

 

int main(void)

{

 

  atmel_start_init();

  //cdcd_acm_example();

 

  char str[12];
  sprintf(str, "HELLO WORLD\n");
  cdcdf_acm_write(str, 12);

 

  while(1)

  {

 

 

  }

 

}