Using avr-gcc with an ATMega328p as the receiver, and an ATTiny2313a as the transmitter. Using RXB12 (http://eeant.com/datasheet/et-rxb-12.pdf) receiver module and H34A (http://www.icstation.com/h34a-31...) 433mhz transmitter module. The receiver breadboard circuit transmits anything it receives to a USART-to-USB module connected to my desktop, which I'm viewing with a serial console (TeraTerm). I have set up my serial console to the correct baud rate that both the transmitter and receiver are running on (250,000 bps).
I can't seem to properly send anything from the transmitter breadboard circuit (ATTiny2313a) to the receiver breadboard circuit (with the ATMega328p). Even without the transmitter powered on, the receiver circuit picks up and outputs lots of noise data (which I guess makes sense - probably lots of 433mhz signals bouncing around). Whenever I power the transmitter on, I know that it's actually transmitting things, because the output to my terminal greatly, greatly speeds up - but it's not the data that I expect to see, just faster garbled chars. I have the transmitter programmed to constantly output the char 't', but as you can see here there is no 't' to be found.
Here's the code. What am I doing wrong here?
Transmitter:
#define F_CPU 16000000UL #define BAUD_RATE 250000 #define CALCULATED_BAUD ((F_CPU / 16 / BAUD_RATE) - 1) #include <avr/io.h> void usart_transmit(unsigned char data); int main(void) { /* UBRR is a 16-bit register, but only the 4 least significant bits of UBBRH are valid. Let's put our calculated baud rate into these registers. */ UBRRH = (CALCULATED_BAUD >> 8); UBRRL = CALCULATED_BAUD; /* Set the TXEN bit in the USART control register B to enable transmission off the TX pin. */ UCSRB = (1 << TXEN); /* Set these bits to set 8-bits in the USART control register C to set a character size of 8. */ UCSRC = (1 << UCSZ0) | (1 << UCSZ1); while (1) { usart_transmit('t'); } } void usart_transmit(unsigned char data) { // Wait for transmit buffer to be empty while ( !(UCSRA & (1 << UDRE)) ); UDR = data; }
Receiver:
#define F_CPU 16000000UL #define BAUD_RATE 250000 #define CALCULATED_BAUD ((F_CPU / 16 / BAUD_RATE) - 1) #include <avr/io.h> void usart_transmit(unsigned char data); unsigned char usart_receive(); int main(void) { /* UBRR is a 16-bit register, but only the 4 least significant bits of UBBR0H are valid. Let's put our calculated baud rate into these registers. */ UBRR0H = (CALCULATED_BAUD >> 8); UBRR0L = CALCULATED_BAUD; /* Set the RXEN0 bit in the USART control register B to enable receiving data off the RX pin. */ UCSR0B = (1 << RXEN0) | (1 << TXEN0); /* Set these bits to set 8-bits in the USART control register C to set a character size of 8. */ UCSR0C = (1 << UCSZ00) | (1 << UCSZ01); while (1) { unsigned char data = usart_receive(); usart_transmit(data); } } void usart_transmit(unsigned char data) { // Wait for transmit buffer to be empty while ( !(UCSR0A & (1 << UDRE0)) ); UDR0 = data; } unsigned char usart_receive() { /* Wait for data to be received */ while ( !(UCSR0A & (1<<RXC0)) ) ; /* Get and return received data from buffer */ return UDR0; }