Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
mfilmer
PostPosted: Feb 04, 2012 - 04:56 AM
Newbie


Joined: Feb 04, 2012
Posts: 4


I'm trying to use an RN-42 [1] with my atmega8a and I'm having a little trouble getting the UART communication to work. (at least I think that's what the problem is)

My goal is to send text over the bluetooth serial connection via python with the pyserial module, and have it displayed on an LCD character display.

I am able to connect to the RN-42 on my computer and have been able to connect to the COM4 port (which is the one that the bluetooth connection creates). I have been able to display text on the LCD display. But the avr never receives the text that I send to the RN-42.

I'm using Peter Fleury's LCD library and his UART library [2]. Here is my code:


Code:

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "lcd.h"
#include "uart.h"

#ifndef F_CPU
#define F_CPU 1000000UL
#endif

#define UART_BAUD_RATE 115000

int main(void)
{
    lcd_init(LCD_DISP_ON_CURSOR_BLINK);
   lcd_puts("test");
   
   //initialize UART
   uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );
   sei();
   
   unsigned int data;
   while(1){
      //data = uart_getc();
      lcd_clrscr();
      data = uart_getc();
      if (data & UART_NO_DATA) {
         lcd_puts("No Data");
      }
      else {
         lcd_puts("Data\nPresent");
         break;
      }
      uart_puts("Test String");
      _delay_ms(1000);
   }
}


I'm running the avr and the RN-42 at 3V, but the power to the LCD module is 5V.
I have all the ground connections on the RN-42 tied to ground, the RTS and CTS pins are shorted (as per manufacturer recommendation), VCC = 3V, PIO4 is grounded, and TX -> RX and RX -> TX. The remaining pins are all floating.

Just to make sure things were working as I expected, I shorted the RX and TX pins on the avr and when I did that the LCD displayed "Data Present". Normally, when the RN-42 is connected to the AVR, the LCD display always shows "No Data".

Any ideas about what I'm doing wrong?

[1] http://www.sparkfun.com/products/10253
[2] http://homepage.hispeed.ch/peterfleury/ ... tware.html
 
 View user's profile Send private message  
Reply with quote Back to top
mfilmer
PostPosted: Feb 04, 2012 - 04:44 PM
Newbie


Joined: Feb 04, 2012
Posts: 4


Update:

If I connect the RX and TX of the RN-42 together I am able to send data from my computer, and then read it back. Because of this, I assume that the problem has to do with the UART communication between the AVR and the RN-42. I'm guessing I have the baud rate wrong, or I haven't properly initialized something, but I can't find seem to figure out what.
 
 View user's profile Send private message  
Reply with quote Back to top
mfilmer
PostPosted: Feb 04, 2012 - 05:36 PM
Newbie


Joined: Feb 04, 2012
Posts: 4


I changed the baud rate to 9600 and that appears to be a step in the right direction. I thought I had tried that before, but I guess not. Now the avr does register that data was received, but I can't figure out how to interpret that data.
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Feb 14, 2012 - 01:58 AM
10k+ Postman


Joined: Sep 04, 2002
Posts: 24109
Location: Orlando Florida

You mention 1MHz. This makes me think it might be the internal oscillator. This clk source is not accurate enough for serial comms (10%). Serial need 2% or less.

_________________
I ain't nobody's uncle, so don't call me that.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
mfilmer
PostPosted: Feb 14, 2012 - 02:08 AM
Newbie


Joined: Feb 04, 2012
Posts: 4


Yes, I am using the internal oscillator, it sounds like that's probably the problem then.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits