Interface with pl2303

Status
Not open for further replies.

magvitron

Active Member
hi, i got a pl 2303 USB 1.1 to RS 232 converter with me. is a level converter like max 232 needed if I want to interface this with a micro controller such as at mega 16, or else directly interface? I searched for some application notes or such but of no avail. If any one offer help I will be much obliged.
 
Same as using the FDTI232 chip.... You don't need a level converter.. You just connect rx and tx to your micro and install the driver on the PC.. ( watch out for voltage drive... Some USB chipssets run on 3v )
 
thanks Ian. Iam now trying to interface but the serial monitor shows nothing. its just blank. checked baud rate, relaced the crystal with a baud rate friendly number (11.0592 Mhz) but of no use. hmm. might be some bug.
 
If you just connect the PL2303 to the PC... The PC see's it OK? What serial monitor are you using... Hyperterminal?
 
hm.. finally got it working its a code for servo control over USB.
Code:
/*****************************
		Servo 
******************************
Program by   : Magvitron
version      : 1.0.0.0 (beta)
Assembled in : winavr
core         : mega 8 (8k)
fuse         : 8Mhz internal rc
			   rst disabled
AVR Studio	 :	4.15.623  
GUI Version	 :	4, 15, 0, 623
AVR Simulator:  1, 0, 2, 1
ATMEGA16		247
date 		 : 12 feb 2013 20.44
*******************************/
/*******************************
Preprovcessor Directive
*******************************/
#define F_CPU 8000000UL
#include<avr/io.h>
#include<util/delay.h>
/******************************/
#define motor PORTB
#define servo PB6
int k;
void servo_to(unsigned int k);
long map(long x, long in_min, long in_max, long out_min, long out_max);
/*******************************
uart definitions
*******************************/
void usart_init();
unsigned int usart_getch();
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

int main()
{
DDRB=0xff;
while(1)
{usart_init();
unsigned int degree_value,time;
//_delay_ms(1000);
usart_putch('H');
usart_putch('e');
usart_putch('l');
usart_putch('l');
usart_putch('o');
degree_value=usart_getch();
degree_value=(degree_value-48)*10;
usart_putch('D');
usart_putch(':');
convert(degree_value,2);
usart_putch(' ');

	for(time=0;time<30;time++)
		{
		  servo_to(degree_value);
		  
		}
/*
degree_value=180;
 	for(degree_value=0;degree_value<180;degree_value +=5)
		for(time=0;time<50;time++)
		{
		  servo_to(degree_value);
		  
		}
	//	_delay_ms(30);
	for(degree_value=180;degree_value>0;degree_value -=5)
		for(time=0;time<50;time++)
		{
		  servo_to(degree_value);
		}
	//	_delay_ms(30);

*/

}


}
void servo_to(unsigned int k)
{
    k=50+(k*10);
	motor= (1<< servo);
	_delay_us(k);
	motor = (0<<servo);
	_delay_ms(18);

}

long map(long x, long in_min, long in_max, long out_min, long out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

/*******************************
uart thingies
*******************************/
unsigned int usart_getch()
{
	while ((UCSRA & (1 << RXC)) == 0);
				// Do nothing until data have been received and is ready to be read from UDR
	return(UDR); // return the byte
//	serial =UDR;
}

void usart_init()
{
	UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN);   	// Turn on the transmission reception ..
								// circuitry and receiver interrupt
	UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes

	UBRRL = BAUD_PRESCALE; 	// Load lower 8-bits of the baud rate value..
				// into the low byte of the UBRR register
	UBRRH = (BAUD_PRESCALE >> 8); 	// Load upper 8-bits of the baud rate value..
					// into the high byte of the UBRR register
}


void usart_putch(unsigned char send)
{
	while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready..
							// for more data to be written to it
	UDR = send; // Send the byte 
}

/**********************************************
conversions lcd and the uart
**********************************************/
void convert(unsigned int value,unsigned int numb)
{
unsigned char text[numb];
unsigned char t,temp_char;
 for(t=1;t<=numb;t++)
 {
   temp_char = value%10;
   value=value/10;
   text[t]=temp_char+48;
 }
 
 for(t=numb;t>=1;t--)
 {
  usart_putch(text[t]);//=text[t];
 }

}


thanks Ian!!
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…