Need some help in Programming

Sir, I have a 3pi Robot and have attached a CC2500 module on it. Now, I have initialized the transceiver module attached to my Desktop with the Hyper terminal
as
Self address= 2
Remote address= 1 (address of the remote device i.e. address of transceiver connected on 3pi)
Channel as= 3 (selecting channel frequency over which device wants to communicate).

Now i have to do the same on the 3pi and program the atmega328p as follows:-
Self address= 1
Remote address= 2 (address of the remote device i.e. address of transceiver connected on Desktop)
Channel as= 3 (selecting channel frequency over which device wants to communicate).
Now i see that 3pi has a inbuilt function to set the baud rate

	serial_set_baud_rate(115200);

.
My Question is is there any such functions to set up the above mentioned parameters?

	serial_set_mode(SERIAL_CHECK);
	serial_receive_ring(buffer, 100);

Moreover i want to know what these two functions signify can how can i change the modes.
I wrote a program in avr studio .The code is as follows

void TX (unsigned char data)
{
UDR=data;
while(!UCSRA&(1<<UDRE)));
}
int main(void)
{
serial_set_baud_rate(38400);
sei;
TX('1');
TX('2');
TX('3');
while(1)
{
}
return 0;
}

Thinking if there is some functions like the baud rate then can the code snippet be optimised

Hello,

If you are using the same module as the one in this thread, then it sounds like all you need to do is send those parameters as the first three bytes of your serial communication. So really, all you are asking is how to send bytes on the serial line.

We have very detailed information about all of the serial functions we provide here and examples here. Have you read over all of this information? For example, our serial_send() function is an advanced alternative to running your TX() function several times. To send bytes ‘1’, ‘2’, and ‘3’, you can just do

serial_send("123",3);

and the bytes will be sent in the background, using interrupts.

-Paul

By the way, you should make sure that you understand that the byte ‘1’ is different from the byte 1 (which could also be written 0x01). If that is not clear to you, google for something like “ascii decimal in c”.

If you want to use serial_send to send the bytes 1, 2, and 3, you can do this:

serial_send("\x01\x02\x03",3);

-Paul

msdn.microsoft.com/en-us/library/bb466258.aspx
may help

microsoft.com/robotics/#GetIt

free software open code
abotics.com/cdbot_robot_software.htm

Anyone trying to program a 3pi should disregard the links in the last three posts from ken58w.

According to this post you can’t use Microsoft Robotics Studio to program an AVR. The page about the NewCDBot programming software makes it clear that the software is for programming a specific kind of robot that is not AVR-based.

–David

Sir, I just need help in understanding this Part of the serial slave code

		case (char)0xC1:
			m1_forward();
			break;
		case (char)0xC2:
			m1_backward();
			break;
		case (char)0xC5:
			m2_forward();
			break;
		case (char)0xC6:
			m2_backward();
			break;

I just Want to ask that which character does 0xC1 denote…please tell me :smiley:, i googled in and found that 0xC1 in EBCDIC it denoted ‘A’ but i want to know what does it denote in ascii, rather after burning the code in our 3pi which letter in the keyboard do we need to press

Sir, using the serial1 program in the library i developed this program but i cant understand why it is yielding 5 errors

#include <pololu/orangutan.h>

char recieve_buffer[32];
char send_buffer[32];
int motorSpeed = 200;

void wait_for_sending_to_finish()
{
	while(!serial_send_buffer_empty());
}

void process_received_byte(char byte)
{
	switch(byte)
	{
		
		case 'w':
			set_motors(motorSpeed, motorSpeed);
			break;

		
		case 's':
			set_motors(-motorSpeed, -motorSpeed);
			break;


		case 'a':
			set_m1_speed(motorSpeed);
			break;


		case 'd':
			set_m2_speed(motorSpeed);
			break;

		default:
			wait_for_sending_to_finish();
			send_buffer[0] = byte ^ 0x20;
			serial_send(send_buffer, 1);
			break;
	}
}

void check_for_new_bytes_received()
{
	while(serial_get_received_bytes() != receive_buffer_position)
	{
	
		process_received_byte(receive_buffer[receive_buffer_position]);

		if (receive_buffer_position == sizeof(receive_buffer)-1)
		{
			receive_buffer_position = 0;
		}
		else
		{
			receive_buffer_position++;
		}
	}
}

int main()
{
	
	serial_set_baud_rate(38400);
	serial_receive_ring(receive_buffer, sizeof(receive_buffer));
	serial_send("\x01\x02\x03",3);
     
    while(1)
    {
		check_for_new_bytes_received();
		if (button_is_pressed(MIDDLE_BUTTON))
		{
			wait_for_sending_to_finish();
			memcpy_P(send_buffer, PSTR("Hi there!\r\n"), 11);
			serial_send(send_buffer, 11);
			wait_for_button_release(MIDDLE_BUTTON);
		}
    }
}

Sir, please tell me Where i am doing the mistake, i cant get it any how.please help me out Sir

sorry for the above code, i just found out the error, but still it is not compiling, i dont know why

#include <pololu/orangutan.h>

char recieve_buffer[32];
char send_buffer[32];
unsigned char receive_buffer_position = 0;
int motorSpeed = 200;

void wait_for_sending_to_finish()
{
	while(!serial_send_buffer_empty());
}

void process_received_byte(char byte)
{
	switch(byte)
	{
		
		case 'w':
			set_motors(motorSpeed, motorSpeed);
			break;

		
		case 's':
			set_motors(-motorSpeed, -motorSpeed);
			break;


		case 'a':
			set_m1_speed(motorSpeed);
			break;


		case 'd':
			set_m2_speed(motorSpeed);
			break;

		default:
			wait_for_sending_to_finish();
			send_buffer[0] = byte ^ 0x20;
			serial_send(send_buffer, 1);
			break;
	}
}

void check_for_new_bytes_received()
{
	while(serial_get_received_bytes() != receive_buffer_position)
	{
	
		process_received_byte(receive_buffer[receive_buffer_position]);

		if (receive_buffer_position == sizeof(receive_buffer)-1)
		{
			receive_buffer_position = 0;
		}
		else
		{
			receive_buffer_position++;
		}
	}
}

int main()
{
	
	serial_set_baud_rate(38400);
	serial_receive_ring(receive_buffer, sizeof(receive_buffer));
	serial_send("\x01\x02\x03",3);
     
    while(1)
    {
		check_for_new_bytes_received();
		if (button_is_pressed(MIDDLE_BUTTON))
		{
			wait_for_sending_to_finish();
			memcpy_P(send_buffer, PSTR("Hi there!\r\n"), 11);
			serial_send(send_buffer, 11);
			wait_for_button_release(MIDDLE_BUTTON);
		}
    }
}

In my earlier codes there are a few compilation errors which may result because i made a few changes in your example program, But when i just copy paste the same Serial1 program for serial communication(link to the example program is https://www.pololu.com/docs/0J20/6.j) just changing the Case statement to the control the motors it complies nicely but when i build the same it gives me 9 errors
the code is

#include <pololu/orangutan.h>  
  
char receive_buffer[32];
unsigned char receive_buffer_position = 0;
char send_buffer[32];


void wait_for_sending_to_finish()
{
	while(!serial_send_buffer_empty());
}


void process_received_byte(char byte)
{
	switch(byte)
	{

		case 'w':
			set_motors(200,200);
			break;


		case 's':
			set_motors(-200,-200);
			break;

	
		case 'a':
			set_motors(0,200);
			break;


		case 'd':
			set_motors(200,0);
			break;


		default:
			wait_for_sending_to_finish();
			send_buffer[0] = byte ^ 0x20;
			serial_send(send_buffer, 1);
			break;
	}
}

void check_for_new_bytes_received()
{
	while(serial_get_received_bytes() != receive_buffer_position)
	{
	
		process_received_byte(receive_buffer[receive_buffer_position]);


		if (receive_buffer_position == sizeof(receive_buffer)-1)
		{
			receive_buffer_position = 0;
		}
		else
		{
			receive_buffer_position++;
		}
	}
}

int main()
{

	serial_set_baud_rate(9600);


	serial_receive_ring(receive_buffer, sizeof(receive_buffer));

    while(1)
    {

		check_for_new_bytes_received();

	
		if (button_is_pressed(MIDDLE_BUTTON))
		{
			wait_for_sending_to_finish();
			memcpy_P(send_buffer, PSTR("Hi there!\r\n"), 11);
			serial_send(send_buffer, 11);

		
			wait_for_button_release(MIDDLE_BUTTON);
		}
    }
}

errors are

Build started 17.6.2010 at 21:52:01
avr-gcc -mmcu=atmega328p -Wl,-Map=cc2500test.map cc2500test.o     -o cc2500test.elf
cc2500test.o: In function `wait_for_sending_to_finish':
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:10: undefined reference to `serial_send_buffer_empty'
cc2500test.o: In function `process_received_byte':
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:35: undefined reference to `set_motors'
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:42: undefined reference to `serial_send'
cc2500test.o: In function `check_for_new_bytes_received':
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:49: undefined reference to `serial_get_received_bytes'
cc2500test.o: In function `main':
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:69: undefined reference to `serial_set_baud_rate'
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:72: undefined reference to `serial_receive_ring'
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:80: undefined reference to `button_is_pressed'
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:84: undefined reference to `serial_send'
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:87: undefined reference to `wait_for_button_release'
make: *** [cc2500test.elf] Error 1
Build failed with 9 errors and 0 warnings...

Sir please help me out, i dont understand what is happening

The linker can’t find any of the functions you are trying to call because you didn’t tell it to use our library. Please read the “Using the Pololu AVR Library for your own projects” section of the Pololu AVR C/C++ Library User’s Guide for information on how to configure AVR Studio (if that’s what you are using):

–David

Thank you very much sir, everything is running just fine