Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to send the USART data through USB to PC.

Status
Not open for further replies.

veerubiji

Full Member level 2
Full Member level 2
Joined
Feb 24, 2011
Messages
122
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Visit site
Activity points
2,301
Hi All,
I am new to programming AVR micro controllers. I have one board which was designed to get some sensor values, which contains ATmega32-A micro controller, AD9833 programmable waveform generator, external ADC and some other peripherals. I have designed the firmware for that board. I have used USART communication (RS232) to display data in hyper terminal. I am sending one command to display the data in hyper terminal. I am using CodeVision AVR compiler.
Now the problem is I have to connect this board to the other board, which having RS232 point. The second board is communicating to the PC using USB communication, which contains AT90USB1287 micro controller and some other peripherals.
I have to send the data what is getting using my board to the PC by connecting this RS232 cable to the second board, which sending data to the PC using USB communication. Please help me how can I transfer the data what I am getting by using USART communication in my board to the PC using second board which is communicating through USB.

thanks in advance.
 

is it that you want to send your data to the second board say the "slave"?, then from the slave you now send the data to the pc?
or is it that you find it difficult to do a board to board communication?

you have to make your problem a little bit defined.
 

If you want to send your PIC's UART data to PC via usb then you have to use a serial to usb converter between your max232 ic connected to PIC and PC.
 

i believe that from what i gathered from veerubiji he said "he has got an AT90USB1287 USB controller in his board".
so i think his problem is making one of the micros a master and the other a slave. but not how to get it down to the pc side.
@internetuser2k12 i will be glad if you go through his post once again except am not getting it right.
 

OK. I was wrong. He wants a UART communication betwwen the Atmega32 and AT90USB1287 boards and also wants to connect AT90USB1287 board using USB to PC.

So, He has to
1. connect RxD pin i.e., PD0 i.e., Pin 14 of ATMega32 to TxD pin i.e., PD3 i.e., Pin 28 of AT90USB1287
2. connect TxD pin i.e., PD1 i.e., Pin 15 of ATMega32 to RxD pin i.e., PD2 i.e., Pin 27 of AT90USB1287
3. USB pins of AT90USB1287 should be connected to PC USB
 
Last edited:

I agree with sequel, from your description it appears you have two development boards which you require to be connected in some way.

If this is correct, why not simply connect the USARTs of the boards together using either an asynchronous or synchronous protocol?

Using an asynchronous TTL or RS-232 would most likely be the simplest method, requiring firmware development for only the AT90USB1287 dev board.

Essentially you would be implementing your on USB to serial bridge/converter out of the AT90USB1287 dev board.

One possible option would be to implement a Communication Device Class (CDC) offering a virtual COM port and which utilizes standard drivers provided by the Windows OS.

Atmel AVR4907: ASF - USB Device CDC Application

**broken link removed**


BigDog



BigDog
 

Yes,
I have two boards, one having AT90USB1287 micro controller with some peripherals which is connected to the PC via USB and it is working and transferring data to PC. Now I have another board with ATmega32-A controller with some peripherals. I have designed the firmware for the ATmega32-A and i am able to read data using USART communication. Now i have to connect this board with the main board which is connected to the PC via USB. I have connected my board to the main board using RS232. Initially I have connected this RS232 cable to the PC directly now I have connected this RS232 to the main board.

I have to send the data from my board to the PC through main board. main board and my board are connected through RS232. What changes i have to make in the firmware of AT90USB1287 to get data from my board to the PC.

- - - Updated - - -

I agree with sequel, from your description it appears you have two development boards which you require to be connected in some way.

If this is correct, why not simply connect the USARTs of the boards together using either an asynchronous or synchronous protocol?

Using an asynchronous TTL or RS-232 would most likely be the simplest method, requiring firmware development for only the AT90USB1287 dev board.

Essentially you would be implementing your on USB to serial bridge/converter out of the AT90USB1287 dev board.

One possible option would be to implement a Communication Device Class (CDC) offering a virtual COM port and which utilizes standard drivers provided by the Windows OS.

Atmel AVR4907: ASF - USB Device CDC Application

**broken link removed**


BigDog



BigDog
I have understand your concept but not fully, if you don't mine can you give little bit explanation. I am new to micro controller programming so i am confusing with this task.
 

You have to redirect the serial data accepted by AT90USB1287 to usb port so that the data goes to PC via USB

Your ATMEGA32 sends serial data to AT90USB1287 using UART and that data received by AT90USB1287 has to be sent to PC via USB? Am I right?

If I am right, you have to send the data read through rs232 to usb write buffer of AT90USB1287.
 

You have to redirect the serial data accepted by AT90USB1287 to usb port so that the data goes to PC via USB

Your ATMEGA32 sends serial data to AT90USB1287 using UART and that data received by AT90USB1287 has to be sent to PC via USB? Am I right?

If I am right, you have to send the data read through rs232 to usb write buffer of AT90USB1287.

Yes absolutely right, but I have small doubt, I have designed the firmware for my board like, I have to send (type in hyperterminal) one command "scan" from PC then it will give data continuously. Now i have connected that rs232 cable to the main board. I am confusing what changes i have to make in the firmware of AT90USB1287. I have to implement USART communication in that firmware? or i have to use USB CDC device ?
 
Last edited:

all you need to do is simply copy whatever that you want to output to the pc from the ATmega32 board down to the AT90USB board via the serial port then of the micros then you can finish it of from here.

that is to say you have to master-slave the micros so that one can serve as the bridge while the other can serve as the master. so you have to first of all get this data down to the AT90USB first via any mode of communication that will be flexible for you say I2C, SPI or whatever protocol that will make you to be on the go....


......sequel
 

all you need to do is simply copy whatever that you want to output to the pc from the ATmega32 board down to the AT90USB board via the serial port then of the micros then you can finish it of from here.

that is to say you have to master-slave the micros so that one can serve as the bridge while the other can serve as the master. so you have to first of all get this data down to the AT90USB first via any mode of communication that will be flexible for you say I2C, SPI or whatever protocol that will make you to be on the go....
......sequel

I have searched all the way, i didn't found any such example code. Can any one help me with sample code.
 

I have searched all the way, i didn't found any such example code. Can any one help me with sample code.

Rubbish! I essentially handed you an example in reply #6.


There are several specific classes of USB devices, from your description a CDC device implementing a USB to Serial bridge is likely the most straight forward.

I have already posted an application note and a link describing a CDC implementation in my previous post.

However, for your convenience the following appnotes and attached code offers a compatible and compatible implementation for the AT90USB series of devices:

AVR271: USB CDC Demonstration UART to USB Bridge

AVR276: USB Software Library for AT90USBxxx Microcontrollers

The example code utilizes a simple scheduler to manage the various tasks, upon studying the API you will notice the various routines resemble those of UART routines for example:

Code:
uart_usb_getchar()

uart_usb_putchar()

However, the data is transmitted/received via the USB interface instead of the UART.

On the PC side the connection appears as a normal COMxx port and can be accessed by virtually any software which can utilize a standard COMxx port, like hyperterminal, MATLAB, etc.

I would first recommend implementing the example USB to UART bridge to link the ATMEGA32 board to the PC via USB interface and THEN later modify the code to include the routines to directly handle data from/to the AT90USB1287 board via USB interface.

Another possible option would be to use the Lightweight USB Framework for AVRs (LUFA) library, rather than the Atmel routines in the above examples.

Although any advantage to using LUFA over the Atmel USB library is unclear in this case, LUFA is Open Source, while the Atmel USB library is not.


BigDog
 

Attachments

  • AVR272_USB_CDC_Virtual_Com_Port.zip
    3.5 MB · Views: 112
  • AVR276_USB_Device-Host_Library.zip
    9.8 MB · Views: 112
Last edited:

Which Compiler are you using? I can do that using mikroC Compiler.
I am using CodeVisonAVR compiler.

- - - Updated - - -

Rubbish! I essentially handed you an example in reply #6.

BigDog
please pardon me for asking like that in the previous post.

I have the written code with me for AT90USB1287 using CDC device. That is working well and transferring data to PC. I am confusing to write little code that gets data from second board using UART.

I have the main board (AT90usb1287) firmware, it is for CDC device. The pins connected like this using RS232 cable
1. connect RxD pin i.e., PD0 i.e., Pin 14 of ATMega32 to TxD pin i.e., PD3 i.e., Pin 28 of AT90USB1287
2. connect TxD pin i.e., PD1 i.e., Pin 15 of ATMega32 to RxD pin i.e., PD2 i.e., Pin 27 of AT90USB1287

they have written some code for usart1(which is on AT90USB1287 pin 27 and 28)
Code:
// USART1 Receiver interrupt service routine
interrupt [USART1_RXC] void usart1_rx_isr(void){   
    
    if(UCSR1A & 0x1C){       
        SerIn[RxCnt] = UDR1; //Read the corrupted byte          
        return;              // Error
    }

    if(++BufCnt >= SIBUFSIZE){                 // Increment & check for buffer overflow
        BufCnt = SIBUFSIZE-1;                  // Set to max value
        return;                                // Skip char
    }else{                                     // Else: if buffer ok
        if(++RxCnt >= SIBUFSIZE) RxCnt = 0;    // Increment read counter, if 10 -> 0 (max 9)
        SerIn[RxCnt] = UDR1;                   // Write to SBUF (load the transmit register)
    }
}

// USB Receive
void catchString(void){
    
    while(UEBCLX){
    
        if(++BufCnt >= SIBUFSIZE){               // Increment & check for buffer overflow  
            BufCnt = SIBUFSIZE-1;                // Set to max value 
//            printf("!Overflow\r\n");
//            UENUM = 2;   
            return;                              // Skip char
        }else{                                   // Else: if buffer ok
            if(++RxCnt >= SIBUFSIZE) RxCnt = 0;  // Increment read counter, if 10 -> 0 (max 9)
            SerIn[RxCnt] = UEDATX;               // Write to SBUF (load the transmit register)
        }
     }  
}


// Read from ringbuffer
char getcharb(void){

    if(BufCnt){                                 // If anything
        BufCnt--;                               // Decrement buffer counter
        if(++RdCnt >= SIBUFSIZE) RdCnt = 0;     // Increment read counter, if 10 -> 0 (max 9)
        return SerIn[RdCnt];                    // Read from SBUF (access receive register)
    }
    return 0;
}
I am confusing is it ok or i have to write some more functions to get data from second board.

thank you very much.
 
Last edited:

Attached zip files are unknown format or damaged, I tried to unzip with all software's, But still i can't. even i have tried from this website also but still same problem **broken link removed**"
 

Attached zip files are unknown format or damaged, I tried to unzip with all software's, But still i can't. even i have tried from this website also but still same problem.[/URL]"

Apparently the files were corrupted at some point, I've updated the attachments of my previous posts from files directly from Atmel site.

By the way, you can access these appnotes and files as well as dozens more from the Atmel product page under the documents tab:

AT90USB1287 Product Page - Documents


BigDog
 

Hi,
I have looked into the example files but still I am not able to understand how to get data from ATmega32-A to the AT90usb1287 board using usart.
Code:
while (rx_counter)
{
  uart_putchar(uart_usb_getchar());   // loop back USB to USART
  }
while (rx_counter)
{
  //uart_putchar(uart_usb_getchar());   // loop back USB to USART
  uart_usb_putchar(uart_usb_getchar()); //loop back USB to USB
}
Still i am able to access data from atmega32-a board.

I am attaching the files regarding CDC device implementing a USB to Serial bridge on AT90USB1287 device hardware. Please help me with that, how can i get data from ATmega32-a using UART.

the code i have attached is working properly to get data and send commands from PC to AT90USB1287. I need help in getting data from other board using UART communication.
 

Attachments

  • codeAT90usb1287.rar
    8.4 KB · Views: 108
Last edited:

Hi,
I have implemented CDC module for USB, It working now. The problem I am facing is I am sending command from PC to atmega32 via AT90USB1287. At90USB1287 is receiving the command and it is giving result as "unknown command". How to send this command to ATmega32a via UART to get data from ATmega32A.
 

At90USB1287 is receiving the command and it is giving result as "unknown command"

Is your commands not being recognized? I told you that any data that comes from PC to AT90 through USB CDC will be in AT90's USB read buffer which is 64 bytes. Your command from PC will be in read buffer of AT90. You want to send that command to ATMega32A. right? So, put the command that is in usb read buffer to UDR register for UART transmission. Transmit the data to ATMega32A. The data i.e., command will now be in UDR register of ATMega32A. You want ATMega32A to do something or to send some data according to the command to AT90. So, according to the command send the data to UDR register of ATMega32A for transmission to AT90. When ATMega32A transmits data and AT90 reads it it will be in the AT90's UDR register. If you want to send that data to PC through USB CDC put that data in UDR to USB write buffer and call the send usb data function. The data will be transmitted to PC.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top