radio modules

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi freaks. i have 2 questions

question 1: I have been messing around with a radio tx and rx i bought from futurlec. any how i have managed to transmitt data from tx to rx but what i wanted to know was how i could read the rx of the recieving IC and create an interrupt when it receives some data. this is using C with mega 128 to mega 32.

question2: i was wondering also if some one could briefly explain this small peice of code i obtained here on avrfreaks used for setting up the UART for 9600 baud and 8n1 on mega 32. just stuff like why these registers have values of 0xXX and so forth.

// USART initialization: 9600,8N1 @ 8MHz 
#include 
#include 

void USART_Transmit(unsigned char data);

int main (void)
{
UCSRA = 0x00; 
UCSRB = 0x18; 
UCSRC = 0x86; 
UBRRH = 0x00; 
UBRRL = 0x33;
}

Thanks Tons :wink:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Both answers are in the uart section of the datasheet of course. The uart init might have generated by a wizard robot code generator that didnt bother to create comments for the carbon based life forms.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok cool thanks. well would u be able to help me with this small prob.. that code compiles for the m32 but not the m28 when i change the makefile. they are the same registers in the m128 im pretty sure. well thats what the dbook says?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mega128 has 2 uarts, so the usart regs have a 0 or 1 in the next to last char position (Ex: UCSR0B)

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes your right. haha :oops: . sorry

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

im going to be honest here. im having a bit of trouble understanding the data book. do u think u could give a small example at all?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've just written the following for Dan, over MSN. I'm not sure if it's correct or not -- didn't even compile it -- but it may be of some use to someone else in the near future. At the very least it uses the symbolic bit names!

/*
		Simple Polled USART Driver
		    By Dean Camera
		
		   For the ATMEGA8515
*/


void SetupUSART(void);
void SendByte(char);
char RecieveByte(void);

void SetupUSART (void)
{
	// Setup USART for 9600, 8, n, 1:
	UCSRB = ((1 << RXEN) | (1 << TXEN)); 
	UCSRC = ((1 << URSEL) | (1 << UMSEL) | (1 << UC8Z1) | (1 << UC8Z0));

	// Baud rate Voodoo:
	UBRR = 0x33;
}

void SendByte(char ByteToSend)
{
	while (!(UCSRA & (1 << TXC)));
	UDR = ByteToSend;
}

char RecieveByte(void)
{
	while (!(UCSRA & (1 << RXC)));
	return UDR;
}

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!