This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

USB Communication in AT89C5131A

Hello,
I have been trying to perform USB communication between my AT89C5131A chip and pyUSB, to transmit some data to the microcontroller.
I haven't been able to find any library which will help me achieve this and as a result I've been trying to understand the USB configuration mentioned in http://www.keil.com/dd/docs/datashts/atmel/at89c5131_ds.pdf.

On running the command dev.set_configuration(), I receive an error and I suppose this indicates a mistake in my configuration till that point.

My hardware bootloader however successfully runs with the dfu-programmer.

I've set the clock frequency correctly and enabled USBEN and FEN as mentioned.

1. Where am I going wrong?
2. Are there any good libraries for doing USB communication with AT89C5131A?
3. Should I switch to an AVR uC instead and use the LUFA library?

Thank you!

Parents
  • For AT89C5131A, Atmel has released a couple of USB device projects on Keil C51 on their website. This CDC implementation gives good starting point for your purpose.

    USB Communication Device Class - Migration from RS-232 to USB
    www.atmel.com/.../doc4322.pdf
    www.atmel.com/.../c5131-usb-cdc-1_2_1.zip

    You'll modify this example step by step.
    1) run this example on your board
    - This example supposes a 16MHz crystal. Tune it for your crystal

    config.h
    #define FOSC                    16000
    

    Your board should appear as a CDC device on your PC.

    2) Implement a loop-back, to test it on PC terminal.

    if ( uart_usb_tx_ready() && uart_usb_test_hit() ) {
       char c = uart_usb_getchar();
       uart_usb_putchar( &c );
    }
    

    3) Replace the config descriptor into vendor-specific one, also VID/PID

    config.h
    #define DEVICE_CLASS          0x02  <-- 0xFF (vendor)
    ...
    #define VENDOR_ID             0xEB03        /* Atmel vendor ID = 03EBh */
    #define PRODUCT_ID            0x0920        /* Product ID: 2009h = CDC C5131 */
    ...
    #define CONF_LENGTH           0x4300  <-- 0x2000
    #define NB_INTERFACE          2       <-- 1
    ...
    #define INTERFACE1_NB          1      <-- 0
    ...
    #define INTERFACE1_CLASS       0x0A /* CDC ACM Data */  <-- 0xFF (vendor)
    
    usb_cdc_enum.c
    code struct
    { struct usb_st_configuration_descriptor  cfg;
      struct usb_st_interface_descriptor      ifc1;
      struct usb_st_endpoint_descriptor       ep1 ;
      struct usb_st_endpoint_descriptor       ep2 ;
     }
      usb_configuration =
      {
        { 9, CONFIGURATION, CONF_LENGTH, NB_INTERFACE, CONF_NB,
          CONF_INDEX, CONF_ATTRIBUTES, MAX_POWER},
        { 9, INTERFACE, INTERFACE1_NB, ALTERNATE1, NB_ENDPOINT1, INTERFACE1_CLASS,
          INTERFACE1_SUB_CLASS, INTERFACE1_PROTOCOL, INTERFACE1_INDEX },
        { 7, ENDPOINT, ENDPOINT_NB_1, EP_ATTRIBUTES_1, EP_SIZE_1, EP_INTERVAL_1 },
        { 7, ENDPOINT, ENDPOINT_NB_2, EP_ATTRIBUTES_2, EP_SIZE_2, EP_INTERVAL_2 },
    };
    

    Now that pyusb is able to see this device.

    4) Lastly, clean up the source code.

    Tsuneo

Reply
  • For AT89C5131A, Atmel has released a couple of USB device projects on Keil C51 on their website. This CDC implementation gives good starting point for your purpose.

    USB Communication Device Class - Migration from RS-232 to USB
    www.atmel.com/.../doc4322.pdf
    www.atmel.com/.../c5131-usb-cdc-1_2_1.zip

    You'll modify this example step by step.
    1) run this example on your board
    - This example supposes a 16MHz crystal. Tune it for your crystal

    config.h
    #define FOSC                    16000
    

    Your board should appear as a CDC device on your PC.

    2) Implement a loop-back, to test it on PC terminal.

    if ( uart_usb_tx_ready() && uart_usb_test_hit() ) {
       char c = uart_usb_getchar();
       uart_usb_putchar( &c );
    }
    

    3) Replace the config descriptor into vendor-specific one, also VID/PID

    config.h
    #define DEVICE_CLASS          0x02  <-- 0xFF (vendor)
    ...
    #define VENDOR_ID             0xEB03        /* Atmel vendor ID = 03EBh */
    #define PRODUCT_ID            0x0920        /* Product ID: 2009h = CDC C5131 */
    ...
    #define CONF_LENGTH           0x4300  <-- 0x2000
    #define NB_INTERFACE          2       <-- 1
    ...
    #define INTERFACE1_NB          1      <-- 0
    ...
    #define INTERFACE1_CLASS       0x0A /* CDC ACM Data */  <-- 0xFF (vendor)
    
    usb_cdc_enum.c
    code struct
    { struct usb_st_configuration_descriptor  cfg;
      struct usb_st_interface_descriptor      ifc1;
      struct usb_st_endpoint_descriptor       ep1 ;
      struct usb_st_endpoint_descriptor       ep2 ;
     }
      usb_configuration =
      {
        { 9, CONFIGURATION, CONF_LENGTH, NB_INTERFACE, CONF_NB,
          CONF_INDEX, CONF_ATTRIBUTES, MAX_POWER},
        { 9, INTERFACE, INTERFACE1_NB, ALTERNATE1, NB_ENDPOINT1, INTERFACE1_CLASS,
          INTERFACE1_SUB_CLASS, INTERFACE1_PROTOCOL, INTERFACE1_INDEX },
        { 7, ENDPOINT, ENDPOINT_NB_1, EP_ATTRIBUTES_1, EP_SIZE_1, EP_INTERVAL_1 },
        { 7, ENDPOINT, ENDPOINT_NB_2, EP_ATTRIBUTES_2, EP_SIZE_2, EP_INTERVAL_2 },
    };
    

    Now that pyusb is able to see this device.

    4) Lastly, clean up the source code.

    Tsuneo

Children