Society of Robots - Robot Forum
Electronics => Electronics => Topic started by: superchiku on March 11, 2009, 03:15:11 AM
-
I using serial wireless communication for my new bot...i decided to test a sample program to switch a led on and off using serial communication...iam using an ask 433 mhz wireless transmitter for that and a bafo 810 usb to serial converter...
i connected pin 3 of db9 to the pin 13 of maxx 232
pin 12 of max 232 to the transmitter data pin
at the receiver side iam using the data pin to connect to the rxd pin of mcu....
at 1st before any serial command is issued i programmed the mcu to blnk the led...after i issue any commands then the blinking will stop and the led will be switched on or off according to my will...
if i transmit 'a' then the led will be switched on...if i transmit 'd' then the led will be switched off...iam using the atmega16 mcu at the receiver side and i have switched on global serial receive nterrupt on...but no matter wat i send from the pc the led kees on blinking as if the mcu is receiving no serial commands...the max 232 is fully operational and iam transmitting my data from a vb program
my serial port settings are
port no-com9
data bits-8
parity-none
stop bits-1
my vb programis tis...written in vb 2008 express edition
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox("hi how are u")
SerialPort1.Open()
End Sub
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
MsgBox("u clicked")
End Sub
Private Sub switchon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles switchon.Click
SerialPort1.Write(Chr(97))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.Write(Chr(100))
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SerialPort1.Close()
End Sub
End Class
and my mcu program is this
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define USART_BAUDRATE 38400
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
int f=0;
void portinitialize();
void uartinitialize();
void handleleft();
void handleright();
void bytedecision(char);
void portinitialize()
{
DDRD|=(1<<4);
TCCR1B|=(1<<CS12);
}
void uartinitialize()
{
UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry
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
UCSRB |= (1 << RXCIE); // Enable the USART Recieve Complete interrupt (USART_RXC)
sei(); // Enable the Global Interrupt Enable flag so that interrupts can be processed
}
void handleleft()
{
int m=0;
PORTD&=~(1<<4);
for(m=0;m<=100;m++)
_delay_ms(10);
}
void handleright()
{
int m=0;
PORTD|=(1<<4);
for(m=0;m<=100;m++)
_delay_ms(10);
}
void bytedecision(char a)
{
if(a=='a' || a=='A')
{
handleleft();
}
if(a=='d' || a=='D')
{
handleright();
}
}
int main (void)
{
portinitialize();
uartinitialize();
for(;;) // Loop forever
{
if(f==0)
{
if(TCNT1>=31250)
{
PORTD^=(1<<4); // run test program blinking- echoing is handled by the ISR instead of in the main loop
TCNT1=0;
}
}
}
}
ISR(USART_RXC_vect)
{
f=1;
char ReceivedByte;
ReceivedByte = UDR; // Fetch the recieved byte value into the variable "ByteReceived"
//UDR = ReceivedByte; // Echo back the received byte back to the computer
bytedecision(ReceivedByte);
}
plz this is long but do help me
-
come on guys....help me...is there sumthing wrong in the code...??
-
Hi,
Did you check the transmitter/receiver pair without the controllers?
-
even witout the transmitter and receiver y code isnt workin i am ot able to sendanything...plzz do help me...i think here is sumtin wrong inthe code coz the max232 is working well...
-
a bafo 810 usb to serial converter...
Hmmm I think you should get a new USB to TTL serial (not rs232) adapter.
Also, did you do a loop-back test? When you put a multimeter (set to frequency) up to the Tx/Rx lines, what do you see?