Hi guys I have set up my first breadboard prototype with an ATMEGA328P-PU but I am struggling to get it communicating by RX / TX to an ESP. Using the code below there is no information received by the ESP, I have also connected the ATMEGA up to an Intel Galileo via RX / TX and still the same there doesn’t seem to be anything being sent can anyone see anywhere I have gone wrong with the code. I have tried with and without the LED just to be sure but still same results.
/*
* IntelliLanAVRLED.c
*
* Created: 4/23/2016 7:30:43 PM
* Author : Adam Milton-Barker
*/
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#define BAUDRATE 9600
#define BAUD_PRESCALLER (((F_CPU / (BAUDRATE * 16UL))) - 1)
void USART_init(void);
unsigned char USART_receive(void);
void USART_send( unsigned char data);
void USART_putstring(char* StringPtr);
char String[]="Hello world!!";
int main(void)
{
USART_init();
DDRB |= (1<<DDB5);
while(1){
USART_putstring(String);
_delay_ms(5000);
PORTB |= (1<<PORTB5);
_delay_ms(1000);
PORTB &= ~(1<<PORTB5);
_delay_ms(1000);
}
}
void USART_init(void){
UBRR0H = (uint8_t)(BAUD_PRESCALLER>>8);
UBRR0L = (uint8_t)(BAUD_PRESCALLER);
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
UCSR0C = (3<<UCSZ00);
}
unsigned char USART_receive(void){
while(!(UCSR0A & (1<<RXC0)));
return UDR0;
}
void USART_send( unsigned char data){
while(!(UCSR0A & (1<<UDRE0)));
UDR0 = data;
}
void USART_putstring(char* StringPtr){
while(*StringPtr != 0x00){
USART_send(*StringPtr);
StringPtr++;
}
}