I recently bought a wireless [reciever and [transmitter. I’ve got one Atmega168 constantly sending ‘a’ over the transmitter, and another one with the receiver that should be receiving the bit and printing it to the terminal screen. The problem is that nothing happens when I turn the microcontrollers on. But when I turn the transmitter off and on a bunch of gibberish gets printed to the screen, which makes me think that there is some kind of connection between the transmitter/receiver. Can anyone think of what the problem might be? They’re running at 4800bps.
Thanks!
Here’s my code… Transmitter:
#include <stdio.h>
#include <avr/io.h>
#define FOSC 8000000
#define BAUD 4800
#define MYUBRR FOSC/16/BAUD-1
#define sbi(var, mask) ((var) |= (uint8_t)(1 << mask))
#define cbi(var, mask) ((var) &= (uint8_t)~(1 << mask))
void ioinit(void);
static int uart_putchar(char c, FILE *stream);
uint8_t uart_getchar(void);
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
void delay_ms(uint16_t x);
int main(void)
{
ioinit ();
int i = 0;
while (1) {
printf ("a");
}
return 0;
}
/**
* Initalizes basic input/output on ports and serial communications
*/
void ioinit (void)
{
//1 = output, 0 = input
DDRB = 0b11111111; //
DDRC = 0b11111111; //
DDRD = 0b11111110; //PORTD (RX on PD0)
//USART Baud rate: 9600
UBRR0H = MYUBRR >> 8;
UBRR0L = MYUBRR;
UCSR0C = (3 << UCSZ00);
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
stdout = &mystdout; //Required for printf init
}
/**
* Prints a character to the serial stream
*/
static int uart_putchar(char c, FILE *stream)
{
if (c == '\n') uart_putchar('\r', stream);
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = c;
return 0;
}
/**
* Reads a character from the serial stream
*/
uint8_t uart_getchar(void)
{
while( !(UCSR0A & (1<<RXC0)) );
return(UDR0);
}
/**
* General delay. Probably not actually delaying for x number of millisecs, but whatever.
*/
void delay_ms(uint16_t x)
{
uint8_t y, z;
for ( ; x > 0 ; x--){
for ( y = 0 ; y < 90 ; y++){
for ( z = 0 ; z < 6 ; z++){
asm volatile ("nop");
}
}
}
}
Receiver:
#include <stdio.h>
#include <avr/io.h>
#define FOSC 8000000
#define BAUD 4800
#define MYUBRR FOSC/16/BAUD-1
#define sbi(var, mask) ((var) |= (uint8_t)(1 << mask))
#define cbi(var, mask) ((var) &= (uint8_t)~(1 << mask))
void ioinit(void);
static int uart_putchar(char c, FILE *stream);
uint8_t uart_getchar(void);
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
void delay_ms(uint16_t x);
int main(void)
{
ioinit ();
int i = 0;
int handshake_count;
char in_char;
while (1) {
in_char = uart_getchar ();
printf ("%c", in_char);
}
return 0;
}
/**
* Initalizes basic input/output on ports and serial communications
*/
void ioinit (void)
{
//1 = output, 0 = input
DDRB = 0b11111111; //
DDRC = 0b11111111; //
DDRD = 0b11111110; //PORTD (RX on PD0)
//USART Baud rate: 9600
UBRR0H = MYUBRR >> 8;
UBRR0L = MYUBRR;
UCSR0C = (3 << UCSZ00);
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
stdout = &mystdout; //Required for printf init
}
/**
* Prints a character to the serial stream
*/
static int uart_putchar(char c, FILE *stream)
{
if (c == '\n') uart_putchar('\r', stream);
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = c;
return 0;
}
/**
* Reads a character from the serial stream
*/
uint8_t uart_getchar(void)
{
while( !(UCSR0A & (1<<RXC0)) );
return(UDR0);
}
/**
* General delay. Probably not actually delaying for x number of millisecs, but whatever.
*/
void delay_ms(uint16_t x)
{
uint8_t y, z;
for ( ; x > 0 ; x--){
for ( y = 0 ; y < 90 ; y++){
for ( z = 0 ; z < 6 ; z++){
asm volatile ("nop");
}
}
}
}
Yeah I’ve seen that link, thanks. That’s how I have everything wired up and nothing happens. When I connect the RX to the TX of each Atmega, and vice versa, they communicate successively with the same code as above.
I’ve also tried it at 2400 bps and that doesn’t do anything either.
Err, could you point me to a page that would show me how to do that?
e: And if the wireless receiver was working but just not getting the stuff the transmitter sent, shouldn’t I at least be getting static? I don’t even get static, I just get nothing.
Right, and when I hook the receiver directly to the the Max3232 IC it doesn’t output anything either so I don’t think the receiver is getting any data at all.
I found this posted on the product page:
If that can help some people…
I buy this to use with a pic18f from microchip with a mikroe board, after one week, i go to be crazy because i get nothing out of the data pin.
I found the right doc and I read that the high level is 0.7*Vdd so ~3.5V → 1 and 0V → 0, but the pic don’t get it at this level.
So I have to put one transistor command with the output data pin and powered with 5V.
And with that it’s working !! UART don’t work good with my case, so i use Manchester coding ( I think it is best ), and no problem now !
No. He was using a PIC with a low voltage supply, and needed to use a transistor to provide a higher voltage to the transmitter input. If you are powering your MCU from 5V you should be OK. Note that he was using Manchester code.
I’d listen to the transmitter on another receiver to make sure that it was working properly, I’ve got a couple of amateur radio transceivers with wide-band receive.
That won’t work unless you design and build a suitable down-converter. You could make a simple RF detector with a dipole antenna and Shottky diode, with a micro-ammeter. Alternatively, buying another transmitter and receiver could help. You might have damaged something.
The receiver is going directly into the Max3232, which is why I didn’t take a picture of the rest of that breadboard (there’s also a lot of other wires for my H bridge and the programmer so I figured it’d be easier to look at like this).
The schematic is the same as the one [here, except with Atmega168s instead of Atmega8s, no antennas, and no crystals.